File size: 5,090 Bytes
c024705
 
 
 
 
 
 
 
 
 
eeacc46
c024705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
"""
Simple Admin Dashboard Test
Tests the professional management functionality
"""

import requests
import json

# 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("SUCCESS: Admin login successful")
                return True
            else:
                print(f"FAILED: Admin login failed: {data.get('error')}")
                return False
        else:
            print(f"FAILED: Admin login failed: {response.status_code}")
            return False
            
    except Exception as e:
        print(f"ERROR: Admin login error: {e}")
        return False

def test_add_professional():
    """Test adding a new professional"""
    print("Testing add professional...")
    
    professional_data = {
        "username": "test_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",
        "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("SUCCESS: Add professional successful")
                return data.get('professional', {}).get('id')
            else:
                print(f"FAILED: Add professional failed: {data.get('error')}")
                return None
        else:
            print(f"FAILED: Add professional failed: {response.status_code}")
            return None
            
    except Exception as e:
        print(f"ERROR: Add professional error: {e}")
        return None

def test_get_professionals():
    """Test getting all professionals"""
    print("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"SUCCESS: Get professionals successful - found {len(data['professionals'])} professionals")
                return True
            else:
                print("SUCCESS: Get professionals successful - no professionals found")
                return True
        else:
            print(f"FAILED: Get professionals failed: {response.status_code}")
            return False
            
    except Exception as e:
        print(f"ERROR: Get professionals error: {e}")
        return False

def cleanup_test_data():
    """Clean up test data"""
    print("Cleaning up test data...")
    
    try:
        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_professional':
                    delete_response = requests.delete(f"{API_BASE_URL}/admin/professionals/{prof['id']}")
                    if delete_response.status_code == 200:
                        print(f"SUCCESS: Cleaned up {prof['username']}")
                    else:
                        print(f"FAILED: Failed to clean up {prof['username']}")
                        
    except Exception as e:
        print(f"ERROR: Cleanup error: {e}")

def main():
    """Run simple admin dashboard test"""
    print("=" * 50)
    print("ADMIN DASHBOARD TEST")
    print("=" * 50)
    
    # Test admin login
    login_success = test_admin_login()
    
    # Test get professionals
    get_success = test_get_professionals()
    
    # Test add professional
    professional_id = test_add_professional()
    
    # Cleanup
    cleanup_test_data()
    
    print("\n" + "=" * 50)
    print("TEST RESULTS:")
    print(f"Login: {'PASS' if login_success else 'FAIL'}")
    print(f"Get Professionals: {'PASS' if get_success else 'FAIL'}")
    print(f"Add Professional: {'PASS' if professional_id else 'FAIL'}")
    
    if all([login_success, get_success, professional_id]):
        print("\nALL TESTS PASSED! Backend is working correctly.")
    else:
        print("\nSOME TESTS FAILED. Check the backend API.")

if __name__ == "__main__":
    main()