harshnarayan12's picture
Upload 19 files
f9ed489 verified
#!/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()