|
|
|
""" |
|
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 |
|
|
|
|
|
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") |
|
|
|
|
|
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) |
|
|
|
|
|
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") |
|
|
|
|
|
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() |
|
|