chatbot / tests /test_supabase.py
jawadsaghir12's picture
Add application file
a8a2cf5
#!/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())