File size: 4,035 Bytes
a384b03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Debug script for Week 4 debate case functionality
Run this script to test if student debate cases are being retrieved correctly
"""

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))

# Import Supabase directly for testing
from supabase import create_client, Client

def debug_week4_debate_case():
    """Debug the Week 4 debate case functionality"""
    print("πŸ” Debugging Week 4 Debate Case Functionality")
    print("=" * 60)
    
    # Test 1: Supabase Connection
    print("1. Testing Supabase Connection...")
    try:
        # Get credentials from environment variables
        url = os.getenv("SUPABASE_URL")
        key = os.getenv("SUPABASE_SERVICE_ROLE_KEY")  # Use service role key
        
        if not url or not key:
            print("   ❌ Missing Supabase credentials in environment variables")
            print(f"      SUPABASE_URL: {'Set' if url else 'Missing'}")
            print(f"      SUPABASE_SERVICE_ROLE_KEY: {'Set' if key else 'Missing'}")
            print("   πŸ’‘ Make sure to set SUPABASE_SERVICE_ROLE_KEY environment variable")
            return
        
        # Create Supabase client directly with service role
        supabase = create_client(url, key)
        print("   βœ… Supabase connection successful (using service role)")
        
    except Exception as e:
        print(f"   ❌ Supabase connection error: {str(e)}")
        return
    
    # Test 2: Check if table exists
    print("\n2. Testing student_debate_case table...")
    try:
        response = supabase.table('student_debate_case').select('*').limit(1).execute()
        print(f"   βœ… Table accessible, found {len(response.data)} records")
    except Exception as e:
        print(f"   ❌ Table access error: {str(e)}")
        return
    
    # Test 3: List all records
    print("\n3. Listing all debate cases in table...")
    try:
        response = supabase.table('student_debate_case').select('*').execute()
        if response.data:
            print(f"   βœ… Found {len(response.data)} debate cases:")
            for i, case in enumerate(response.data, 1):
                print(f"      {i}. Student ID: {case.get('student_id', 'N/A')}")
                print(f"         Google Doc: {case.get('google_doc_link', 'N/A')}")
                print(f"         Description: {case.get('description', 'N/A')}")
                print(f"         Created: {case.get('created_at', 'N/A')}")
                print()
        else:
            print("   ❌ No debate cases found in table")
    except Exception as e:
        print(f"   ❌ Error listing cases: {str(e)}")
    
    # Test 4: Test with specific usernames
    print("\n4. Testing with specific usernames...")
    test_usernames = ["test_student", "student1", "demo_user", "admin"]
    
    for username in test_usernames:
        try:
            # Test the query directly
            response = supabase.table('student_debate_case').select('*').eq('student_id', username).order('created_at', desc=True).limit(1).execute()
            if response.data:
                print(f"   βœ… Found case for '{username}': {response.data[0].get('google_doc_link', 'N/A')}")
            else:
                print(f"   ❌ No case found for '{username}'")
        except Exception as e:
            print(f"   ❌ Error testing '{username}': {str(e)}")
    
    # Test 5: Check environment variables
    print("\n5. Checking environment variables...")
    try:
        url = os.getenv("SUPABASE_URL")
        key = os.getenv("SUPABASE_KEY")
        
        if url:
            print(f"   βœ… SUPABASE_URL found: {url[:20]}...")
        else:
            print("   ❌ SUPABASE_URL not found")
            
        if key:
            print(f"   βœ… SUPABASE_KEY found: {key[:10]}...")
        else:
            print("   ❌ SUPABASE_KEY not found")
    except Exception as e:
        print(f"   ❌ Error checking environment: {str(e)}")

if __name__ == "__main__":
    debug_week4_debate_case()