cardserver / tests /test_app_startup.py
GitHub Actions
πŸš€ Auto-deploy from GitHub
63b8c2c
#!/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)