Files
audiobook/backend/test_api.py
Paul Bailey 31da896e56 Implement backend API foundation
- Created FastAPI application with CORS middleware
- Defined Pydantic models (RoleDetectionRequest, RolesResponse, TTSRequest, ErrorResponse)
- Implemented /api/health endpoint
- Set up error handling middleware for validation and general exceptions
- Configured logging with INFO level
- Added test script to verify API functionality
- Validates Requirements: 9.1, 9.2, 9.4
2025-12-09 00:57:46 +00:00

27 lines
929 B
Python

#!/usr/bin/env python3
"""Simple test script for API foundation."""
import urllib.request
import json
def test_health():
"""Test health endpoint."""
response = urllib.request.urlopen('http://localhost:8001/api/health')
data = json.loads(response.read().decode())
print(f"✓ Health check: {data}")
def test_cors():
"""Test CORS headers."""
req = urllib.request.Request('http://localhost:8001/api/health',
headers={'Origin': 'http://localhost:5173'})
response = urllib.request.urlopen(req)
cors_origin = response.headers.get('Access-Control-Allow-Origin')
cors_creds = response.headers.get('Access-Control-Allow-Credentials')
print(f"✓ CORS Origin: {cors_origin}")
print(f"✓ CORS Credentials: {cors_creds}")
if __name__ == '__main__':
print("Testing API Foundation...")
test_health()
test_cors()
print("\nAll tests passed!")