File size: 3,863 Bytes
f9ed489 |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#!/usr/bin/env python3
"""
Quick application test to verify basic functionality
"""
import os
import sys
import importlib
from pathlib import Path
def test_imports():
"""Test critical imports"""
print("π Testing critical imports...")
try:
import flask
print("β
Flask import successful")
except ImportError as e:
print(f"β Flask import failed: {e}")
return False
try:
import fastapi
print("β
FastAPI import successful")
except ImportError as e:
print(f"β FastAPI import failed: {e}")
return False
try:
from main import app as flask_app
print("β
Flask app import successful")
except ImportError as e:
print(f"β Flask app import failed: {e}")
return False
try:
from fastapi_app import app as fastapi_app
print("β
FastAPI app import successful")
except ImportError as e:
print(f"β FastAPI app import failed: {e}")
return False
return True
def test_database_connection():
"""Test database connection"""
print("\nπ Testing database connection...")
try:
from main import engine, init_db
# Test database initialization
if init_db():
print("β
Database initialization successful")
return True
else:
print("β Database initialization failed")
return False
except Exception as e:
print(f"β Database test failed: {e}")
return False
def test_configuration():
"""Test configuration loading"""
print("\nπ Testing configuration...")
try:
from config_manager import get_config
config = get_config()
print("β
Configuration loading successful")
# Test critical config values
if config.SECRET_KEY and config.SECRET_KEY != 'your_secret_key_here':
print("β
SECRET_KEY is configured")
else:
print("β οΈ SECRET_KEY needs configuration")
if config.GOOGLE_API_KEY and config.GOOGLE_API_KEY != 'your_google_api_key_here':
print("β
GOOGLE_API_KEY is configured")
else:
print("β οΈ GOOGLE_API_KEY needs configuration")
return True
except Exception as e:
print(f"β Configuration test failed: {e}")
return False
def main():
"""Main test function"""
print("π Mental Health App - Quick Test")
print("=" * 50)
# Load environment
if Path('.env').exists():
try:
from dotenv import load_dotenv
load_dotenv()
print("π Environment loaded from .env")
except ImportError:
print("β οΈ python-dotenv not available, using system environment")
# Run tests
tests = [
test_imports,
test_database_connection,
test_configuration,
]
all_passed = True
for test in tests:
try:
if not test():
all_passed = False
except Exception as e:
print(f"β Test {test.__name__} failed with exception: {e}")
all_passed = False
print("\n" + "=" * 50)
if all_passed:
print("β
All tests passed! Application is ready for Hugging Face Spaces deployment.")
print("\nπ To start the application:")
print(" # For Docker deployment on Hugging Face Spaces:")
print(" docker build -t mental-health-app .")
print(" docker run -p 7860:7860 mental-health-app")
print(" # Or for local development:")
print(" python app.py")
else:
print("β Some tests failed. Please fix the issues above.")
sys.exit(1)
if __name__ == "__main__":
main()
|