#!/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)