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