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