#!/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()