test_app_user_applications.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env python3
  2. import requests
  3. import json
  4. # Test app user applications access
  5. login_data = {
  6. 'username': 'app',
  7. 'password': '123456'
  8. }
  9. try:
  10. # Login as app user
  11. login_response = requests.post('http://localhost:8000/api/v1/auth/login', json=login_data)
  12. if login_response.status_code == 200:
  13. login_result = login_response.json()
  14. if login_result.get('code') == 0:
  15. token = login_result['data']['access_token']
  16. print('✅ App user login successful')
  17. # Get applications list
  18. headers = {'Authorization': f'Bearer {token}'}
  19. apps_response = requests.get('http://localhost:8000/api/v1/apps', headers=headers)
  20. if apps_response.status_code == 200:
  21. apps_result = apps_response.json()
  22. if apps_result.get('code') == 0:
  23. apps_data = apps_result['data']
  24. apps = apps_data.get('items', [])
  25. total = apps_data.get('total', 0)
  26. print(f'✅ App user can access applications API')
  27. print(f'📱 Found {len(apps)} applications (total: {total})')
  28. if apps:
  29. for app in apps:
  30. print(f' App: {app["name"]} (Key: {app["app_key"]})')
  31. print(f' Description: {app.get("description", "N/A")}')
  32. print(f' Active: {app["is_active"]}')
  33. print(f' Created: {app["created_at"]}')
  34. print()
  35. print('🎉 App user can now see all applications!')
  36. else:
  37. print('❌ No applications returned - still empty!')
  38. else:
  39. print(f'❌ Applications API error: {apps_result.get("message")}')
  40. else:
  41. print(f'❌ Applications API HTTP error: {apps_response.status_code}')
  42. print(f'Response: {apps_response.text}')
  43. else:
  44. print(f'❌ Login error: {login_result.get("message")}')
  45. else:
  46. print(f'❌ Login HTTP error: {login_response.status_code}')
  47. except Exception as e:
  48. print(f'❌ Request error: {e}')
  49. # Also test with admin user for comparison
  50. print('\n' + '='*50)
  51. print('Testing admin user for comparison...')
  52. admin_login_data = {
  53. 'username': 'admin',
  54. 'password': 'Admin123456'
  55. }
  56. try:
  57. # Login as admin user
  58. login_response = requests.post('http://localhost:8000/api/v1/auth/login', json=admin_login_data)
  59. if login_response.status_code == 200:
  60. login_result = login_response.json()
  61. if login_result.get('code') == 0:
  62. token = login_result['data']['access_token']
  63. print('✅ Admin user login successful')
  64. # Get applications list
  65. headers = {'Authorization': f'Bearer {token}'}
  66. apps_response = requests.get('http://localhost:8000/api/v1/apps', headers=headers)
  67. if apps_response.status_code == 200:
  68. apps_result = apps_response.json()
  69. if apps_result.get('code') == 0:
  70. apps_data = apps_result['data']
  71. apps = apps_data.get('items', [])
  72. total = apps_data.get('total', 0)
  73. print(f'✅ Admin user can access applications API')
  74. print(f'📱 Admin sees {len(apps)} applications (total: {total})')
  75. else:
  76. print(f'❌ Applications API error: {apps_result.get("message")}')
  77. else:
  78. print(f'❌ Applications API HTTP error: {apps_response.status_code}')
  79. else:
  80. print(f'❌ Admin login error: {login_result.get("message")}')
  81. else:
  82. print(f'❌ Admin login HTTP error: {login_response.status_code}')
  83. except Exception as e:
  84. print(f'❌ Admin request error: {e}')