Hirely-Backend / backend /test_api.py
NaikPranav11's picture
Initial clean deployment
1207440
Raw
History Blame Contribute Delete
3.22 kB
#!/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()