#!/usr/bin/env python3 """ Complete Admin Dashboard Flow Test Tests the entire professional management workflow """ import requests import json import time # Configuration API_BASE_URL = "https://prodevroger-ishingiro.hf.space" ADMIN_EMAIL = "eliasfeza@gmail.com" ADMIN_PASSWORD = "EliasFeza@12301" def test_admin_login(): """Test admin login""" print("๐Ÿ” Testing admin login...") try: response = requests.post(f"{API_BASE_URL}/admin/login", json={ "email": ADMIN_EMAIL, "password": ADMIN_PASSWORD }) if response.status_code == 200: data = response.json() if data.get('success'): print("โœ… Admin login successful") return data.get('token') else: print(f"โŒ Admin login failed: {data.get('error')}") return None else: print(f"โŒ Admin login failed: {response.status_code}") return None except Exception as e: print(f"โŒ Admin login error: {e}") return None def test_add_professional(): """Test adding a new professional""" print("\nโž• Testing add professional...") professional_data = { "username": "test_add_professional", "password": "password123", "first_name": "Test", "last_name": "Professional", "email": "test.professional@example.com", "phone": "+250788123456", "specialization": "counselor", "expertise_areas": ["depression", "anxiety"], "experience_years": 5, "district": "Gasabo", "consultation_fee": 50000, "bio": "Test professional for add functionality", "languages": ["english"], "qualifications": [], "availability_schedule": {} } try: response = requests.post(f"{API_BASE_URL}/admin/professionals", json=professional_data) if response.status_code == 200: data = response.json() if data.get('success'): print("โœ… Add professional successful") return data.get('professional', {}).get('id') else: print(f"โŒ Add professional failed: {data.get('error')}") return None else: print(f"โŒ Add professional failed: {response.status_code}") print(f"Response: {response.text}") return None except Exception as e: print(f"โŒ Add professional error: {e}") return None def test_edit_professional(professional_id): """Test editing a professional""" print(f"\nโœ๏ธ Testing edit professional {professional_id}...") update_data = { "first_name": "Updated", "last_name": "Professional", "email": "updated.professional@example.com", "phone": "+250788654321", "specialization": "psychologist", "expertise_areas": ["ptsd", "trauma"], "experience_years": 7, "district": "Kicukiro", "consultation_fee": 75000, "bio": "Updated professional for testing" } try: response = requests.put(f"{API_BASE_URL}/admin/professionals/{professional_id}", json=update_data) if response.status_code == 200: data = response.json() if data.get('success'): print("โœ… Edit professional successful") return True else: print(f"โŒ Edit professional failed: {data.get('error')}") return False else: print(f"โŒ Edit professional failed: {response.status_code}") return False except Exception as e: print(f"โŒ Edit professional error: {e}") return False def test_get_professionals(): """Test getting all professionals""" print("\n๐Ÿ“‹ Testing get professionals...") try: response = requests.get(f"{API_BASE_URL}/admin/professionals") if response.status_code == 200: data = response.json() if data.get('professionals'): print(f"โœ… Get professionals successful - found {len(data['professionals'])} professionals") return data.get('professionals') else: print("โŒ Get professionals failed - no professionals found") return [] else: print(f"โŒ Get professionals failed: {response.status_code}") return [] except Exception as e: print(f"โŒ Get professionals error: {e}") return [] def test_toggle_professional_status(professional_id): """Test toggling professional status""" print(f"\n๐Ÿ”„ Testing toggle professional status {professional_id}...") try: response = requests.post(f"{API_BASE_URL}/admin/professionals/{professional_id}/status", json={ "is_active": False }) if response.status_code == 200: data = response.json() if data.get('success'): print("โœ… Toggle professional status successful") return True else: print(f"โŒ Toggle professional status failed: {data.get('error')}") return False else: print(f"โŒ Toggle professional status failed: {response.status_code}") return False except Exception as e: print(f"โŒ Toggle professional status error: {e}") return False def test_delete_professional(professional_id): """Test deleting a professional""" print(f"\n๐Ÿ—‘๏ธ Testing delete professional {professional_id}...") try: response = requests.delete(f"{API_BASE_URL}/admin/professionals/{professional_id}") if response.status_code == 200: data = response.json() if data.get('success'): print("โœ… Delete professional successful") return True else: print(f"โŒ Delete professional failed: {data.get('error')}") return False else: print(f"โŒ Delete professional failed: {response.status_code}") return False except Exception as e: print(f"โŒ Delete professional error: {e}") return False def cleanup_test_data(): """Clean up test data""" print("\n๐Ÿงน Cleaning up test data...") try: # Get all professionals response = requests.get(f"{API_BASE_URL}/admin/professionals") if response.status_code == 200: data = response.json() professionals = data.get('professionals', []) for prof in professionals: if prof.get('username') == 'test_add_professional': delete_response = requests.delete(f"{API_BASE_URL}/admin/professionals/{prof['id']}") if delete_response.status_code == 200: print(f"โœ… Cleaned up {prof['username']}") else: print(f"โŒ Failed to clean up {prof['username']}") except Exception as e: print(f"โŒ Cleanup error: {e}") def main(): """Run complete admin dashboard flow test""" print("๐Ÿงช Testing Complete Admin Dashboard Flow") print("=" * 60) # Test admin login token = test_admin_login() if not token: print("โŒ Cannot proceed without admin authentication") return # Test get professionals (should work even if empty) professionals = test_get_professionals() # Test add professional professional_id = test_add_professional() if not professional_id: print("โŒ Cannot proceed without successful professional creation") return # Test edit professional edit_success = test_edit_professional(professional_id) # Test toggle status toggle_success = test_toggle_professional_status(professional_id) # Test delete professional delete_success = test_delete_professional(professional_id) # Cleanup cleanup_test_data() print("\n" + "=" * 60) print("๐ŸŽ‰ Admin Dashboard Flow Test Complete!") print("\n๐Ÿ“‹ Results:") print(f"โœ… Login: {'PASS' if token else 'FAIL'}") print(f"โœ… Get Professionals: {'PASS' if professionals is not None else 'FAIL'}") print(f"โœ… Add Professional: {'PASS' if professional_id else 'FAIL'}") print(f"โœ… Edit Professional: {'PASS' if edit_success else 'FAIL'}") print(f"โœ… Toggle Status: {'PASS' if toggle_success else 'FAIL'}") print(f"โœ… Delete Professional: {'PASS' if delete_success else 'FAIL'}") if all([token, professional_id, edit_success, toggle_success, delete_success]): print("\n๐Ÿš€ All tests passed! The admin dashboard backend is working perfectly!") else: print("\nโš ๏ธ Some tests failed. Check the backend API endpoints.") if __name__ == "__main__": main()