debate_LMS / tests /debug_page.py
raymondEDS's picture
Push to week 4
a384b03
import streamlit as st
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
from utils import init_supabase, get_student_debate_case
def main():
st.title("πŸ” Week 4 Debate Case Debug")
st.markdown("---")
# Test 1: Supabase Connection
st.subheader("1. Testing Supabase Connection")
try:
supabase = init_supabase()
if supabase:
st.success("βœ… Supabase connection successful")
else:
st.error("❌ Supabase connection failed")
return
except Exception as e:
st.error(f"❌ Supabase connection error: {str(e)}")
return
# Test 2: Check if table exists
st.subheader("2. Testing student_debate_case table")
try:
response = supabase.table('student_debate_case').select('*').limit(1).execute()
st.success(f"βœ… Table accessible, found {len(response.data)} records")
except Exception as e:
st.error(f"❌ Table access error: {str(e)}")
return
# Test 3: List all records
st.subheader("3. Listing all debate cases in table")
try:
response = supabase.table('student_debate_case').select('*').execute()
if response.data:
st.success(f"βœ… Found {len(response.data)} debate cases:")
for i, case in enumerate(response.data, 1):
st.write(f" **{i}.** Student ID: `{case.get('student_id', 'N/A')}`")
st.write(f" Link: {case.get('google_doc_link', 'N/A')}")
st.write(f" Created: {case.get('created_at', 'N/A')}")
st.write("---")
else:
st.warning("❌ No debate cases found in table")
except Exception as e:
st.error(f"❌ Error listing cases: {str(e)}")
# Test 4: Test with specific usernames
st.subheader("4. Testing with specific usernames")
test_usernames = ["lily", "reed", "instructor", "admin"]
for username in test_usernames:
try:
result = get_student_debate_case(username)
if result:
st.success(f"βœ… Found case for '{username}': {result.get('google_doc_link', 'N/A')}")
else:
st.info(f"❌ No case found for '{username}'")
except Exception as e:
st.error(f"❌ Error testing '{username}': {str(e)}")
# Test 5: Test with current user
st.subheader("5. Testing with current user")
if st.session_state.get('authenticated', False):
username = st.session_state.get('username')
st.write(f"**Current user:** {username}")
try:
result = get_student_debate_case(username)
if result:
st.success(f"βœ… Found case for current user '{username}': {result.get('google_doc_link', 'N/A')}")
else:
st.warning(f"❌ No case found for current user '{username}'")
except Exception as e:
st.error(f"❌ Error testing current user: {str(e)}")
else:
st.warning("⚠️ No user currently authenticated")
# Test 6: Check RLS policies
st.subheader("6. RLS Policy Check")
st.info("""
**RLS Policies Applied:**
- Users can read their own debate cases
- Users can insert their own debate cases
- Users can update their own debate cases
- Users can delete their own debate cases
**Note:** If you're testing with a service role or admin user, you might need additional policies.
""")
if __name__ == "__main__":
main()