Download backend/test_api.py from pranit144/Finance: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/pranit144/Finance/resolve/main/backend/test_api.py
- Command line
-
hf download hf://spaces/pranit144/Finance/backend/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/pranit144/Finance/resolve/main/backend/test_api.py
1.81 kB
| """ | |
| Test script to verify the signup endpoint works. | |
| """ | |
| import requests | |
| import json | |
| API_BASE_URL = "http://localhost:8000" | |
| def test_signup(): | |
| """Test user signup.""" | |
| print("Testing signup endpoint...") | |
| payload = { | |
| "email": "testuser@example.com", | |
| "name": "Test User", | |
| "password": "SecurePass123!", | |
| "role": "STAFF" | |
| } | |
| try: | |
| response = requests.post( | |
| f"{API_BASE_URL}/auth/signup", | |
| json=payload | |
| ) | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {json.dumps(response.json(), indent=2)}") | |
| if response.status_code == 201: | |
| print("β Signup successful!") | |
| return True | |
| else: | |
| print("β Signup failed!") | |
| return False | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| return False | |
| def test_health(): | |
| """Test health endpoint.""" | |
| print("\nTesting health endpoint...") | |
| try: | |
| response = requests.get(f"{API_BASE_URL}/health") | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {json.dumps(response.json(), indent=2)}") | |
| if response.status_code == 200: | |
| print("β Backend is healthy!") | |
| return True | |
| else: | |
| print("β Backend health check failed!") | |
| return False | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("=" * 50) | |
| print("API Test Script") | |
| print("=" * 50) | |
| # Test health first | |
| if test_health(): | |
| # Then test signup | |
| test_signup() | |
| else: | |
| print("\nβ Backend is not responding. Make sure it's running on port 8000.") | |