| """ |
| Quick test script to verify Supabase connection and migration |
| """ |
| import os |
| from dotenv import load_dotenv |
|
|
| load_dotenv() |
|
|
| def test_supabase_connection(): |
| """Test Supabase connection""" |
| print("π Testing Supabase Connection...\n") |
| |
| |
| supabase_url = os.getenv('SUPABASE_URL') |
| supabase_key = os.getenv('SUPABASE_KEY') |
| |
| if not supabase_url: |
| print("β SUPABASE_URL not found in environment variables") |
| print(" Add it to your .env file: SUPABASE_URL=https://xxxxx.supabase.co") |
| return False |
| |
| if not supabase_key: |
| print("β SUPABASE_KEY not found in environment variables") |
| print(" Add it to your .env file: SUPABASE_KEY=eyJhbGc...") |
| return False |
| |
| print(f"β
SUPABASE_URL: {supabase_url}") |
| print(f"β
SUPABASE_KEY: {supabase_key[:20]}...\n") |
| |
| |
| try: |
| from supabase import create_client |
| |
| supabase = create_client(supabase_url, supabase_key) |
| print("β
Supabase client created successfully\n") |
| |
| |
| print("π Testing table access...") |
| response = supabase.table('certificates').select('count', count='exact').execute() |
| |
| count = response.count if hasattr(response, 'count') else len(response.data) |
| print(f"β
Found {count} records in certificates table\n") |
| |
| |
| print("π Fetching sample records...") |
| sample = supabase.table('certificates').select('*').limit(3).execute() |
| |
| if sample.data: |
| print(f"β
Sample records:") |
| for record in sample.data: |
| print(f" - {record.get('reg_no')}: {record.get('name')}") |
| else: |
| print("β οΈ No records found. Import your data using SUPABASE_SETUP.md guide") |
| |
| print("\nβ
Supabase connection test PASSED!") |
| return True |
| |
| except ImportError: |
| print("β Supabase package not installed") |
| print(" Run: pip install supabase") |
| return False |
| except Exception as e: |
| print(f"β Connection failed: {e}") |
| print("\nTroubleshooting:") |
| print("1. Check your SUPABASE_URL is correct") |
| print("2. Check your SUPABASE_KEY is the 'anon/public' key") |
| print("3. Ensure the 'certificates' table exists") |
| print("4. Check RLS policies allow public access") |
| return False |
|
|
| def test_verifier(): |
| """Test the Supabase verifier""" |
| print("\n" + "="*50) |
| print("π Testing SupabaseCertificateVerifier...\n") |
| |
| try: |
| from verifier_supabase import SupabaseCertificateVerifier |
| |
| verifier = SupabaseCertificateVerifier() |
| print("β
Verifier initialized successfully") |
| |
| |
| print("\nπ Testing registration lookup...") |
| test_reg_nos = ['ABC2023001', '1BG19CS100', 'TEST123'] |
| |
| for reg_no in test_reg_nos: |
| result = verifier._lookup_registration(reg_no) |
| if result: |
| print(f"β
Found: {reg_no} β {result.get('name')}") |
| else: |
| print(f"β οΈ Not found: {reg_no}") |
| |
| print("\nβ
Verifier test PASSED!") |
| return True |
| |
| except Exception as e: |
| print(f"β Verifier test failed: {e}") |
| return False |
|
|
| if __name__ == "__main__": |
| print("="*50) |
| print("π SUPABASE MIGRATION TEST") |
| print("="*50 + "\n") |
| |
| connection_ok = test_supabase_connection() |
| |
| if connection_ok: |
| test_verifier() |
| |
| print("\n" + "="*50) |
| print("β
ALL TESTS PASSED!") |
| print("="*50) |
| print("\nNext steps:") |
| print("1. Update api.py to use verifier_supabase") |
| print("2. Test locally: python api.py") |
| print("3. Deploy to Railway") |
| else: |
| print("\n" + "="*50) |
| print("β TESTS FAILED") |
| print("="*50) |
| print("\nFollow SUPABASE_SETUP.md for complete setup instructions") |
|
|