Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python | |
| """Test script to verify Supabase connection and configuration.""" | |
| import asyncio | |
| from src.db.supabase_client import get_supabase_client | |
| from src.db.database import engine, init_db, get_session | |
| from src.core.config.config import get_settings | |
| async def test_config(): | |
| """Test configuration loading.""" | |
| print("\n=== TESTING CONFIGURATION ===") | |
| settings = get_settings() | |
| print(f"β APP_NAME: {settings.APP_NAME}") | |
| print(f"β ENVIRONMENT: {settings.ENVIRONMENT}") | |
| print(f"β DEBUG: {settings.DEBUG}") | |
| print(f"β SUPABASE_URL: {settings.SUPABASE_URL[:50]}...") | |
| print(f"β DATABASE_URL: {'*' * 40}") | |
| print(f"β REDIS_URL: {settings.REDIS_URL}") | |
| return settings | |
| def test_supabase_client(): | |
| """Test Supabase client initialization.""" | |
| print("\n=== TESTING SUPABASE CLIENT ===") | |
| try: | |
| client = get_supabase_client() | |
| print(f"β Supabase client created: {type(client).__name__}") | |
| has_auth = hasattr(client, 'auth') | |
| has_table = hasattr(client, 'table') | |
| has_storage = hasattr(client, 'storage') | |
| print(f"β Has auth module: {has_auth}") | |
| print(f"β Has table module: {has_table}") | |
| print(f"β Has storage module: {has_storage}") | |
| return True | |
| except Exception as e: | |
| print(f"β Error initializing Supabase client: {e}") | |
| return False | |
| async def test_database_connection(): | |
| """Test database connection.""" | |
| print("\n=== TESTING DATABASE CONNECTION ===") | |
| try: | |
| # Try to get a session | |
| async for session in get_session(): | |
| print(f"β Database session created successfully") | |
| print(f"β Session type: {type(session).__name__}") | |
| break | |
| return True | |
| except Exception as e: | |
| print(f"β Error connecting to database: {e}") | |
| return False | |
| async def test_database_initialization(): | |
| """Test database schema initialization.""" | |
| print("\n=== TESTING DATABASE SCHEMA INITIALIZATION ===") | |
| try: | |
| await init_db() | |
| print("β Database schema initialized successfully") | |
| return True | |
| except Exception as e: | |
| print(f"β Error initializing schema: {e}") | |
| return False | |
| async def main(): | |
| """Run all tests.""" | |
| print("\n" + "="*60) | |
| print("SUPABASE & DATABASE SETUP VERIFICATION") | |
| print("="*60) | |
| # Test configuration | |
| await test_config() | |
| # Test Supabase client | |
| test_supabase_client() | |
| # Test database connection | |
| await test_database_connection() | |
| # Test database initialization | |
| await test_database_initialization() | |
| print("\n" + "="*60) | |
| print("β ALL TESTS COMPLETED") | |
| print("="*60 + "\n") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |