Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Quick test runner for development | |
| """ | |
| import subprocess | |
| import sys | |
| import time | |
| import requests | |
| def start_server(): | |
| """Start the FastAPI server""" | |
| print("π Starting FastAPI server...") | |
| try: | |
| process = subprocess.Popen([ | |
| sys.executable, "-m", "uvicorn", | |
| "app.main:app", "--reload", "--port", "8000" | |
| ], cwd=".") | |
| time.sleep(3) # Wait for server to start | |
| return process | |
| except Exception as e: | |
| print(f"β Failed to start server: {e}") | |
| return None | |
| def test_basic_endpoints(): | |
| """Test basic API endpoints""" | |
| base_url = "http://localhost:8000" | |
| tests = [ | |
| ("GET", "/", "Root endpoint"), | |
| ("GET", "/health", "Health check"), | |
| ("GET", "/metrics", "Metrics endpoint"), | |
| ("GET", "/docs", "API documentation"), | |
| ] | |
| print("\nπ§ͺ Testing basic endpoints...") | |
| for method, endpoint, description in tests: | |
| try: | |
| if method == "GET": | |
| response = requests.get(f"{base_url}{endpoint}", timeout=5) | |
| if response.status_code == 200: | |
| print(f"β {description}: OK") | |
| else: | |
| print(f"β οΈ {description}: Status {response.status_code}") | |
| except Exception as e: | |
| print(f"β {description}: {e}") | |
| def main(): | |
| print("π§ Development Test Runner") | |
| print("=" * 40) | |
| # Start server | |
| server_process = start_server() | |
| if not server_process: | |
| return | |
| try: | |
| # Run basic tests | |
| test_basic_endpoints() | |
| print("\nβ Basic tests completed!") | |
| print("π Server running at: http://localhost:8000") | |
| print("π API docs at: http://localhost:8000/docs") | |
| print("\nPress Ctrl+C to stop the server...") | |
| # Keep server running | |
| server_process.wait() | |
| except KeyboardInterrupt: | |
| print("\nπ Stopping server...") | |
| server_process.terminate() | |
| server_process.wait() | |
| if __name__ == "__main__": | |
| main() |