Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Simple API test script for Hirely API | |
| """ | |
| import requests | |
| import json | |
| BASE_URL = "http://localhost:8000/api/v1" | |
| def test_health(): | |
| """Test health endpoint""" | |
| response = requests.get("http://localhost:8000/health") | |
| print("π₯ Health Check:", response.json()) | |
| def test_login(): | |
| """Test login endpoint""" | |
| login_data = { | |
| "email": "admin@hirely.com", | |
| "password": "admin123" | |
| } | |
| response = requests.post(f"{BASE_URL}/auth/login", json=login_data) | |
| if response.status_code == 200: | |
| data = response.json() | |
| print("π Login Success:", data["user"]["full_name"]) | |
| return data["access_token"] | |
| else: | |
| print("β Login Failed:", response.json()) | |
| return None | |
| def test_dashboard_stats(token): | |
| """Test dashboard stats endpoint""" | |
| headers = {"Authorization": f"Bearer {token}"} | |
| response = requests.get(f"{BASE_URL}/dashboard/stats", headers=headers) | |
| if response.status_code == 200: | |
| print("π Dashboard Stats:", response.json()) | |
| else: | |
| print("β Dashboard Stats Failed:", response.json()) | |
| def test_jobs(token): | |
| """Test jobs endpoint""" | |
| headers = {"Authorization": f"Bearer {token}"} | |
| response = requests.get(f"{BASE_URL}/jobs/", headers=headers) | |
| if response.status_code == 200: | |
| jobs = response.json() | |
| print(f"πΌ Jobs Found: {len(jobs)}") | |
| for job in jobs[:2]: # Show first 2 jobs | |
| print(f" β’ {job['title']} - {job['department']} ({job['status']})") | |
| else: | |
| print("β Jobs Failed:", response.json()) | |
| def test_candidates(token): | |
| """Test candidates endpoint""" | |
| headers = {"Authorization": f"Bearer {token}"} | |
| response = requests.get(f"{BASE_URL}/candidates/", headers=headers) | |
| if response.status_code == 200: | |
| candidates = response.json() | |
| print(f"π§βπΌ Candidates Found: {len(candidates)}") | |
| for candidate in candidates[:2]: # Show first 2 candidates | |
| print(f" β’ {candidate['full_name']} - {candidate['status']} ({candidate['score_percentage']})") | |
| else: | |
| print("β Candidates Failed:", response.json()) | |
| def test_enums(): | |
| """Test enums endpoint""" | |
| response = requests.get(f"{BASE_URL}/enums") | |
| if response.status_code == 200: | |
| enums = response.json() | |
| print("π Available Enums:") | |
| print(f" β’ User Roles: {enums['user_roles']}") | |
| print(f" β’ Job Statuses: {enums['job_statuses']}") | |
| print(f" β’ Candidate Statuses: {enums['candidate_statuses'][:5]}...") # Show first 5 | |
| else: | |
| print("β Enums Failed:", response.json()) | |
| def main(): | |
| """Main test function""" | |
| print("π Testing Hirely API...") | |
| print("=" * 50) | |
| # Test health | |
| test_health() | |
| # Test enums (no auth required) | |
| test_enums() | |
| # Test login and get token | |
| token = test_login() | |
| if not token: | |
| print("β Cannot continue without authentication") | |
| return | |
| # Test authenticated endpoints | |
| test_dashboard_stats(token) | |
| test_jobs(token) | |
| test_candidates(token) | |
| print("\nβ API tests completed!") | |
| if __name__ == "__main__": | |
| main() |