Spaces:
Sleeping
Sleeping
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())
|