Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Quick test to verify the FastAPI app can start locally before deployment. | |
| This helps catch configuration issues early. | |
| """ | |
| import sys | |
| import asyncio | |
| from pathlib import Path | |
| # Add the cardserver directory to the path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| async def test_app_startup(): | |
| try: | |
| print("π§ Testing FastAPI app startup...") | |
| # Import and create the app | |
| from app.main import app | |
| from app.core.config import settings | |
| print("β App imported successfully") | |
| print(f"π Static directory: {settings.resolved_static_files_mount_dir}") | |
| print(f"π Static directory exists: {settings.resolved_static_files_mount_dir.exists()}") | |
| # Check if we can access the root endpoint | |
| print("π Testing root endpoint...") | |
| from fastapi.testclient import TestClient | |
| client = TestClient(app) | |
| response = client.get("/") | |
| if response.status_code == 200: | |
| print("β Root endpoint works!") | |
| print(f"Response: {response.json()}") | |
| else: | |
| print(f"β Root endpoint failed: {response.status_code}") | |
| # Test health endpoint | |
| print("π Testing health endpoint...") | |
| response = client.get("/api/v1/health") | |
| if response.status_code == 200: | |
| print("β Health endpoint works!") | |
| print(f"Response: {response.json()}") | |
| else: | |
| print(f"β Health endpoint failed: {response.status_code}") | |
| return True | |
| except ImportError as e: | |
| print(f"β Import error: {e}") | |
| print("π‘ Make sure all dependencies are installed: pip install -r requirements.txt") | |
| return False | |
| except Exception as e: | |
| print(f"β Unexpected error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| if __name__ == "__main__": | |
| print("=== FASTAPI APP STARTUP TEST ===") | |
| success = asyncio.run(test_app_startup()) | |
| if success: | |
| print("\nπ App startup test passed! Ready for deployment.") | |
| sys.exit(0) | |
| else: | |
| print("\nπ₯ App startup test failed. Fix issues before deploying.") | |
| sys.exit(1) | |