File size: 4,977 Bytes
b439a3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
"""Quick test script to verify service setup"""
import sys
import os

# Add app to path
sys.path.insert(0, os.path.dirname(__file__))

def test_imports():
    """Test all imports work correctly"""
    print("πŸ” Testing imports...")
    
    try:
        from app.main import app
        print("βœ… Main app imported")
        
        from app.routers import chats, messages
        print("βœ… Routers imported")
        
        from app.services.chat_service import ChatService
        from app.services.ai_service import AIService
        print("βœ… Services imported")
        
        from app.models.chat import Chat
        from app.models.message import Message
        print("βœ… Models imported")
        
        from app.schemas import ChatSchema, MessageSchema
        print("βœ… Schemas imported")
        
        from app.dependencies import get_db, get_user_id
        print("βœ… Dependencies imported")
        
        from app.core.config import get_settings
        settings = get_settings()
        print("βœ… Config imported")
        
        print(f"\nπŸ“Š Configuration:")
        print(f"  - Database: {settings.database_url}")
        print(f"  - AI Model: {settings.gemini_model}")
        print(f"  - Port: {settings.port}")
        print(f"  - File Service: {settings.file_service_url}")
        
        return True
        
    except Exception as e:
        print(f"❌ Import failed: {e}")
        import traceback
        traceback.print_exc()
        return False


def test_database():
    """Test database initialization"""
    print("\nπŸ—„οΈ  Testing database...")
    
    try:
        from app.db.database import init_db, engine
        from app.models.chat import Chat
        from app.models.message import Message
        
        # Initialize database
        init_db()
        print("βœ… Database initialized successfully")
        
        # Check tables
        from sqlalchemy import inspect
        inspector = inspect(engine)
        tables = inspector.get_table_names()
        print(f"βœ… Tables created: {tables}")
        
        if "chats" in tables and "messages" in tables:
            print("βœ… All required tables exist")
            return True
        else:
            print("❌ Missing required tables")
            return False
            
    except Exception as e:
        print(f"❌ Database test failed: {e}")
        import traceback
        traceback.print_exc()
        return False


def test_api_structure():
    """Test API structure"""
    print("\nπŸ”§ Testing API structure...")
    
    try:
        from app.main import app
        
        # Get all routes
        routes = []
        for route in app.routes:
            if hasattr(route, 'methods') and hasattr(route, 'path'):
                for method in route.methods:
                    if method != 'HEAD':
                        routes.append(f"{method} {route.path}")
        
        print(f"βœ… Found {len(routes)} API endpoints:")
        for route in sorted(routes):
            print(f"  - {route}")
        
        # Check required endpoints
        required = [
            "POST /assistant/chats",
            "GET /assistant/chats",
            "GET /assistant/chats/{chat_id}/messages",
            "POST /assistant/chats/{chat_id}/messages",
            "PUT /assistant/chats/{chat_id}",
            "DELETE /assistant/chats/{chat_id}",
        ]
        
        all_found = True
        for endpoint in required:
            found = any(endpoint in route for route in routes)
            if not found:
                print(f"❌ Missing endpoint: {endpoint}")
                all_found = False
        
        if all_found:
            print("βœ… All required endpoints exist")
            
        return all_found
        
    except Exception as e:
        print(f"❌ API structure test failed: {e}")
        import traceback
        traceback.print_exc()
        return False


def main():
    """Run all tests"""
    print("=" * 60)
    print("πŸ§ͺ ASSISTANT SERVICE VERIFICATION")
    print("=" * 60)
    
    results = {
        "Imports": test_imports(),
        "Database": test_database(),
        "API Structure": test_api_structure(),
    }
    
    print("\n" + "=" * 60)
    print("πŸ“Š TEST RESULTS")
    print("=" * 60)
    
    for test_name, result in results.items():
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{test_name}: {status}")
    
    all_passed = all(results.values())
    
    print("\n" + "=" * 60)
    if all_passed:
        print("πŸŽ‰ ALL TESTS PASSED!")
        print("\nπŸš€ Ready to run:")
        print("   python -m app.main")
        print("   or")
        print("   uvicorn app.main:app --reload --port 8003")
    else:
        print("❌ SOME TESTS FAILED")
        print("Please fix the issues above before running the service")
    print("=" * 60)
    
    return 0 if all_passed else 1


if __name__ == "__main__":
    sys.exit(main())