File size: 2,306 Bytes
63b8c2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/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)