Spaces:
Sleeping
Sleeping
Commit
Β·
a384b03
1
Parent(s):
e74c738
Push to week 4
Browse files- src/views/week4.py +3 -25
- tests/add_debate_case.py +81 -0
- tests/debug_page.py +95 -0
- tests/debug_week4.py +101 -0
- tests/test_week4_debate_case.py +182 -0
src/views/week4.py
CHANGED
|
@@ -103,13 +103,6 @@ def show_week4_content():
|
|
| 103 |
- Make sure you can present everything within your time limit
|
| 104 |
""")
|
| 105 |
|
| 106 |
-
presentation_notes = st.text_area(
|
| 107 |
-
"Any notes about your full case presentation (optional):",
|
| 108 |
-
placeholder="e.g., 'I need to work on my pacing' or 'The transition between my first and second argument needs work'",
|
| 109 |
-
height=100,
|
| 110 |
-
key="full_case_notes"
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
elif presentation_option == "2. Present 1 argument you think is the best and explain why":
|
| 114 |
st.markdown("""
|
| 115 |
**Option 2: Best Argument Focus**
|
|
@@ -122,13 +115,6 @@ def show_week4_content():
|
|
| 122 |
- Connect it to your overall case strategy
|
| 123 |
""")
|
| 124 |
|
| 125 |
-
best_argument = st.text_area(
|
| 126 |
-
"Which argument from your case do you think is the best? Explain why:",
|
| 127 |
-
placeholder="e.g., 'My economic impact argument is strongest because...' or 'The moral obligation argument works best because...'",
|
| 128 |
-
height=150,
|
| 129 |
-
key="best_argument_explanation"
|
| 130 |
-
)
|
| 131 |
-
|
| 132 |
elif presentation_option == "3. Talk about what you think is a good strategy":
|
| 133 |
st.markdown("""
|
| 134 |
**Option 3: Strategy Discussion**
|
|
@@ -140,13 +126,6 @@ def show_week4_content():
|
|
| 140 |
- Discuss how your arguments complement each other
|
| 141 |
- Share insights about effective debate strategy
|
| 142 |
""")
|
| 143 |
-
|
| 144 |
-
strategy_discussion = st.text_area(
|
| 145 |
-
"Discuss your debate strategy and approach:",
|
| 146 |
-
placeholder="e.g., 'My strategy focuses on...' or 'I think the most effective approach is...' or 'My arguments work together by...'",
|
| 147 |
-
height=150,
|
| 148 |
-
key="strategy_discussion"
|
| 149 |
-
)
|
| 150 |
|
| 151 |
st.markdown("---")
|
| 152 |
st.markdown("### **π― Ready to Practice!**")
|
|
@@ -362,9 +341,9 @@ def show_week4_content():
|
|
| 362 |
|
| 363 |
st.markdown("### **π Your Debate Case Document**")
|
| 364 |
|
| 365 |
-
# Convert Google Doc URL to embed URL
|
| 366 |
google_doc_url = student_case['google_doc_link']
|
| 367 |
-
embed_url = google_doc_url
|
| 368 |
|
| 369 |
# Display the Google Doc in an iframe
|
| 370 |
st.markdown(f"""
|
|
@@ -378,8 +357,7 @@ def show_week4_content():
|
|
| 378 |
""", unsafe_allow_html=True)
|
| 379 |
|
| 380 |
# Add download button
|
| 381 |
-
|
| 382 |
-
st.markdown(f"[π₯ Download as Word Document]({download_url})")
|
| 383 |
|
| 384 |
if student_case.get('description'):
|
| 385 |
st.markdown(f"**Description:** {student_case['description']}")
|
|
|
|
| 103 |
- Make sure you can present everything within your time limit
|
| 104 |
""")
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
elif presentation_option == "2. Present 1 argument you think is the best and explain why":
|
| 107 |
st.markdown("""
|
| 108 |
**Option 2: Best Argument Focus**
|
|
|
|
| 115 |
- Connect it to your overall case strategy
|
| 116 |
""")
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
elif presentation_option == "3. Talk about what you think is a good strategy":
|
| 119 |
st.markdown("""
|
| 120 |
**Option 3: Strategy Discussion**
|
|
|
|
| 126 |
- Discuss how your arguments complement each other
|
| 127 |
- Share insights about effective debate strategy
|
| 128 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
st.markdown("---")
|
| 131 |
st.markdown("### **π― Ready to Practice!**")
|
|
|
|
| 341 |
|
| 342 |
st.markdown("### **π Your Debate Case Document**")
|
| 343 |
|
| 344 |
+
# Convert Google Doc URL to embed URL (allow editing)
|
| 345 |
google_doc_url = student_case['google_doc_link']
|
| 346 |
+
embed_url = google_doc_url # Keep as edit mode to allow editing
|
| 347 |
|
| 348 |
# Display the Google Doc in an iframe
|
| 349 |
st.markdown(f"""
|
|
|
|
| 357 |
""", unsafe_allow_html=True)
|
| 358 |
|
| 359 |
# Add download button
|
| 360 |
+
st.markdown(f"[π₯ Download as Word Document]({embed_url})")
|
|
|
|
| 361 |
|
| 362 |
if student_case.get('description'):
|
| 363 |
st.markdown(f"**Description:** {student_case['description']}")
|
tests/add_debate_case.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 5 |
+
|
| 6 |
+
from utils import init_supabase
|
| 7 |
+
|
| 8 |
+
def add_debate_case():
|
| 9 |
+
st.title("π Add Debate Case")
|
| 10 |
+
|
| 11 |
+
# Initialize Supabase
|
| 12 |
+
supabase = init_supabase()
|
| 13 |
+
if not supabase:
|
| 14 |
+
st.error("β Cannot connect to database")
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
st.markdown("---")
|
| 18 |
+
|
| 19 |
+
# Form to add debate case
|
| 20 |
+
with st.form("add_debate_case_form"):
|
| 21 |
+
st.subheader("Add New Debate Case")
|
| 22 |
+
|
| 23 |
+
# Student ID input
|
| 24 |
+
student_id = st.text_input("Student ID (username):", placeholder="e.g., lily, reed")
|
| 25 |
+
|
| 26 |
+
# Google Doc URL input
|
| 27 |
+
google_doc_url = st.text_input("Google Doc URL:",
|
| 28 |
+
value="https://docs.google.com/document/d/1J8Unkklwhk778jcARshISK0AdBZ34XikQpeBDAWAxY0/edit",
|
| 29 |
+
placeholder="https://docs.google.com/document/d/...")
|
| 30 |
+
|
| 31 |
+
# Description input
|
| 32 |
+
description = st.text_area("Description:", placeholder="Brief description of the debate case")
|
| 33 |
+
|
| 34 |
+
# Submit button
|
| 35 |
+
submitted = st.form_submit_button("Add Debate Case")
|
| 36 |
+
|
| 37 |
+
if submitted:
|
| 38 |
+
if student_id and google_doc_url:
|
| 39 |
+
try:
|
| 40 |
+
# Insert the debate case
|
| 41 |
+
data = {
|
| 42 |
+
'student_id': student_id,
|
| 43 |
+
'google_doc_link': google_doc_url,
|
| 44 |
+
'description': description
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
response = supabase.table('student_debate_case').insert(data).execute()
|
| 48 |
+
|
| 49 |
+
if response.data:
|
| 50 |
+
st.success(f"β
Successfully added debate case for {student_id}")
|
| 51 |
+
st.write("**Added data:**")
|
| 52 |
+
st.json(response.data[0])
|
| 53 |
+
else:
|
| 54 |
+
st.error("β Failed to add debate case")
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
st.error(f"β Error adding debate case: {str(e)}")
|
| 58 |
+
else:
|
| 59 |
+
st.warning("β οΈ Please fill in Student ID and Google Doc URL")
|
| 60 |
+
|
| 61 |
+
st.markdown("---")
|
| 62 |
+
|
| 63 |
+
# Show existing debate cases
|
| 64 |
+
st.subheader("Current Debate Cases")
|
| 65 |
+
try:
|
| 66 |
+
response = supabase.table('student_debate_case').select('*').execute()
|
| 67 |
+
if response.data:
|
| 68 |
+
st.success(f"β
Found {len(response.data)} debate cases:")
|
| 69 |
+
for i, case in enumerate(response.data, 1):
|
| 70 |
+
st.write(f"**{i}.** Student: `{case.get('student_id', 'N/A')}`")
|
| 71 |
+
st.write(f" Link: {case.get('google_doc_link', 'N/A')}")
|
| 72 |
+
st.write(f" Description: {case.get('description', 'N/A')}")
|
| 73 |
+
st.write(f" Created: {case.get('created_at', 'N/A')}")
|
| 74 |
+
st.write("---")
|
| 75 |
+
else:
|
| 76 |
+
st.info("π No debate cases found in table")
|
| 77 |
+
except Exception as e:
|
| 78 |
+
st.error(f"β Error retrieving debate cases: {str(e)}")
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
add_debate_case()
|
tests/debug_page.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 5 |
+
|
| 6 |
+
from utils import init_supabase, get_student_debate_case
|
| 7 |
+
|
| 8 |
+
def main():
|
| 9 |
+
st.title("π Week 4 Debate Case Debug")
|
| 10 |
+
|
| 11 |
+
st.markdown("---")
|
| 12 |
+
|
| 13 |
+
# Test 1: Supabase Connection
|
| 14 |
+
st.subheader("1. Testing Supabase Connection")
|
| 15 |
+
try:
|
| 16 |
+
supabase = init_supabase()
|
| 17 |
+
if supabase:
|
| 18 |
+
st.success("β
Supabase connection successful")
|
| 19 |
+
else:
|
| 20 |
+
st.error("β Supabase connection failed")
|
| 21 |
+
return
|
| 22 |
+
except Exception as e:
|
| 23 |
+
st.error(f"β Supabase connection error: {str(e)}")
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
# Test 2: Check if table exists
|
| 27 |
+
st.subheader("2. Testing student_debate_case table")
|
| 28 |
+
try:
|
| 29 |
+
response = supabase.table('student_debate_case').select('*').limit(1).execute()
|
| 30 |
+
st.success(f"β
Table accessible, found {len(response.data)} records")
|
| 31 |
+
except Exception as e:
|
| 32 |
+
st.error(f"β Table access error: {str(e)}")
|
| 33 |
+
return
|
| 34 |
+
|
| 35 |
+
# Test 3: List all records
|
| 36 |
+
st.subheader("3. Listing all debate cases in table")
|
| 37 |
+
try:
|
| 38 |
+
response = supabase.table('student_debate_case').select('*').execute()
|
| 39 |
+
if response.data:
|
| 40 |
+
st.success(f"β
Found {len(response.data)} debate cases:")
|
| 41 |
+
for i, case in enumerate(response.data, 1):
|
| 42 |
+
st.write(f" **{i}.** Student ID: `{case.get('student_id', 'N/A')}`")
|
| 43 |
+
st.write(f" Link: {case.get('google_doc_link', 'N/A')}")
|
| 44 |
+
st.write(f" Created: {case.get('created_at', 'N/A')}")
|
| 45 |
+
st.write("---")
|
| 46 |
+
else:
|
| 47 |
+
st.warning("β No debate cases found in table")
|
| 48 |
+
except Exception as e:
|
| 49 |
+
st.error(f"β Error listing cases: {str(e)}")
|
| 50 |
+
|
| 51 |
+
# Test 4: Test with specific usernames
|
| 52 |
+
st.subheader("4. Testing with specific usernames")
|
| 53 |
+
test_usernames = ["lily", "reed", "instructor", "admin"]
|
| 54 |
+
|
| 55 |
+
for username in test_usernames:
|
| 56 |
+
try:
|
| 57 |
+
result = get_student_debate_case(username)
|
| 58 |
+
if result:
|
| 59 |
+
st.success(f"β
Found case for '{username}': {result.get('google_doc_link', 'N/A')}")
|
| 60 |
+
else:
|
| 61 |
+
st.info(f"β No case found for '{username}'")
|
| 62 |
+
except Exception as e:
|
| 63 |
+
st.error(f"β Error testing '{username}': {str(e)}")
|
| 64 |
+
|
| 65 |
+
# Test 5: Test with current user
|
| 66 |
+
st.subheader("5. Testing with current user")
|
| 67 |
+
if st.session_state.get('authenticated', False):
|
| 68 |
+
username = st.session_state.get('username')
|
| 69 |
+
st.write(f"**Current user:** {username}")
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
result = get_student_debate_case(username)
|
| 73 |
+
if result:
|
| 74 |
+
st.success(f"β
Found case for current user '{username}': {result.get('google_doc_link', 'N/A')}")
|
| 75 |
+
else:
|
| 76 |
+
st.warning(f"β No case found for current user '{username}'")
|
| 77 |
+
except Exception as e:
|
| 78 |
+
st.error(f"β Error testing current user: {str(e)}")
|
| 79 |
+
else:
|
| 80 |
+
st.warning("β οΈ No user currently authenticated")
|
| 81 |
+
|
| 82 |
+
# Test 6: Check RLS policies
|
| 83 |
+
st.subheader("6. RLS Policy Check")
|
| 84 |
+
st.info("""
|
| 85 |
+
**RLS Policies Applied:**
|
| 86 |
+
- Users can read their own debate cases
|
| 87 |
+
- Users can insert their own debate cases
|
| 88 |
+
- Users can update their own debate cases
|
| 89 |
+
- Users can delete their own debate cases
|
| 90 |
+
|
| 91 |
+
**Note:** If you're testing with a service role or admin user, you might need additional policies.
|
| 92 |
+
""")
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
main()
|
tests/debug_week4.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Debug script for Week 4 debate case functionality
|
| 4 |
+
Run this script to test if student debate cases are being retrieved correctly
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
|
| 10 |
+
|
| 11 |
+
# Import Supabase directly for testing
|
| 12 |
+
from supabase import create_client, Client
|
| 13 |
+
|
| 14 |
+
def debug_week4_debate_case():
|
| 15 |
+
"""Debug the Week 4 debate case functionality"""
|
| 16 |
+
print("π Debugging Week 4 Debate Case Functionality")
|
| 17 |
+
print("=" * 60)
|
| 18 |
+
|
| 19 |
+
# Test 1: Supabase Connection
|
| 20 |
+
print("1. Testing Supabase Connection...")
|
| 21 |
+
try:
|
| 22 |
+
# Get credentials from environment variables
|
| 23 |
+
url = os.getenv("SUPABASE_URL")
|
| 24 |
+
key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") # Use service role key
|
| 25 |
+
|
| 26 |
+
if not url or not key:
|
| 27 |
+
print(" β Missing Supabase credentials in environment variables")
|
| 28 |
+
print(f" SUPABASE_URL: {'Set' if url else 'Missing'}")
|
| 29 |
+
print(f" SUPABASE_SERVICE_ROLE_KEY: {'Set' if key else 'Missing'}")
|
| 30 |
+
print(" π‘ Make sure to set SUPABASE_SERVICE_ROLE_KEY environment variable")
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
# Create Supabase client directly with service role
|
| 34 |
+
supabase = create_client(url, key)
|
| 35 |
+
print(" β
Supabase connection successful (using service role)")
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f" β Supabase connection error: {str(e)}")
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
+
# Test 2: Check if table exists
|
| 42 |
+
print("\n2. Testing student_debate_case table...")
|
| 43 |
+
try:
|
| 44 |
+
response = supabase.table('student_debate_case').select('*').limit(1).execute()
|
| 45 |
+
print(f" β
Table accessible, found {len(response.data)} records")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f" β Table access error: {str(e)}")
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
# Test 3: List all records
|
| 51 |
+
print("\n3. Listing all debate cases in table...")
|
| 52 |
+
try:
|
| 53 |
+
response = supabase.table('student_debate_case').select('*').execute()
|
| 54 |
+
if response.data:
|
| 55 |
+
print(f" β
Found {len(response.data)} debate cases:")
|
| 56 |
+
for i, case in enumerate(response.data, 1):
|
| 57 |
+
print(f" {i}. Student ID: {case.get('student_id', 'N/A')}")
|
| 58 |
+
print(f" Google Doc: {case.get('google_doc_link', 'N/A')}")
|
| 59 |
+
print(f" Description: {case.get('description', 'N/A')}")
|
| 60 |
+
print(f" Created: {case.get('created_at', 'N/A')}")
|
| 61 |
+
print()
|
| 62 |
+
else:
|
| 63 |
+
print(" β No debate cases found in table")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f" β Error listing cases: {str(e)}")
|
| 66 |
+
|
| 67 |
+
# Test 4: Test with specific usernames
|
| 68 |
+
print("\n4. Testing with specific usernames...")
|
| 69 |
+
test_usernames = ["test_student", "student1", "demo_user", "admin"]
|
| 70 |
+
|
| 71 |
+
for username in test_usernames:
|
| 72 |
+
try:
|
| 73 |
+
# Test the query directly
|
| 74 |
+
response = supabase.table('student_debate_case').select('*').eq('student_id', username).order('created_at', desc=True).limit(1).execute()
|
| 75 |
+
if response.data:
|
| 76 |
+
print(f" β
Found case for '{username}': {response.data[0].get('google_doc_link', 'N/A')}")
|
| 77 |
+
else:
|
| 78 |
+
print(f" β No case found for '{username}'")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
print(f" β Error testing '{username}': {str(e)}")
|
| 81 |
+
|
| 82 |
+
# Test 5: Check environment variables
|
| 83 |
+
print("\n5. Checking environment variables...")
|
| 84 |
+
try:
|
| 85 |
+
url = os.getenv("SUPABASE_URL")
|
| 86 |
+
key = os.getenv("SUPABASE_KEY")
|
| 87 |
+
|
| 88 |
+
if url:
|
| 89 |
+
print(f" β
SUPABASE_URL found: {url[:20]}...")
|
| 90 |
+
else:
|
| 91 |
+
print(" β SUPABASE_URL not found")
|
| 92 |
+
|
| 93 |
+
if key:
|
| 94 |
+
print(f" β
SUPABASE_KEY found: {key[:10]}...")
|
| 95 |
+
else:
|
| 96 |
+
print(" β SUPABASE_KEY not found")
|
| 97 |
+
except Exception as e:
|
| 98 |
+
print(f" β Error checking environment: {str(e)}")
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
debug_week4_debate_case()
|
tests/test_week4_debate_case.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
|
| 5 |
+
|
| 6 |
+
from utils import init_supabase, get_student_debate_case
|
| 7 |
+
from supabase import create_client, Client
|
| 8 |
+
|
| 9 |
+
def test_supabase_connection():
|
| 10 |
+
"""Test if Supabase connection is working"""
|
| 11 |
+
print("=== Testing Supabase Connection ===")
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
supabase = init_supabase()
|
| 15 |
+
if supabase:
|
| 16 |
+
print("β
Supabase connection successful")
|
| 17 |
+
return True
|
| 18 |
+
else:
|
| 19 |
+
print("β Supabase connection failed")
|
| 20 |
+
return False
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"β Supabase connection error: {str(e)}")
|
| 23 |
+
return False
|
| 24 |
+
|
| 25 |
+
def test_student_debate_case_table():
|
| 26 |
+
"""Test if student_debate_case table exists and is accessible"""
|
| 27 |
+
print("\n=== Testing student_debate_case Table ===")
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
supabase = init_supabase()
|
| 31 |
+
if not supabase:
|
| 32 |
+
print("β Cannot test table - no Supabase connection")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
# Try to select from the table
|
| 36 |
+
response = supabase.table('student_debate_case').select('*').limit(1).execute()
|
| 37 |
+
print("β
student_debate_case table is accessible")
|
| 38 |
+
print(f" Found {len(response.data)} records in table")
|
| 39 |
+
return True
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"β Error accessing student_debate_case table: {str(e)}")
|
| 43 |
+
return False
|
| 44 |
+
|
| 45 |
+
def test_get_student_debate_case_function():
|
| 46 |
+
"""Test the get_student_debate_case function with a test username"""
|
| 47 |
+
print("\n=== Testing get_student_debate_case Function ===")
|
| 48 |
+
|
| 49 |
+
# Test with a sample username
|
| 50 |
+
test_username = "test_student"
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
result = get_student_debate_case(test_username)
|
| 54 |
+
if result:
|
| 55 |
+
print(f"β
Found debate case for {test_username}")
|
| 56 |
+
print(f" Google Doc Link: {result.get('google_doc_link', 'N/A')}")
|
| 57 |
+
print(f" Description: {result.get('description', 'N/A')}")
|
| 58 |
+
print(f" Created: {result.get('created_at', 'N/A')}")
|
| 59 |
+
else:
|
| 60 |
+
print(f"β No debate case found for {test_username}")
|
| 61 |
+
|
| 62 |
+
return result is not None
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f"β Error in get_student_debate_case: {str(e)}")
|
| 66 |
+
return False
|
| 67 |
+
|
| 68 |
+
def test_all_students_in_table():
|
| 69 |
+
"""List all students who have debate cases"""
|
| 70 |
+
print("\n=== Testing All Students in Table ===")
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
supabase = init_supabase()
|
| 74 |
+
if not supabase:
|
| 75 |
+
print("β Cannot test - no Supabase connection")
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
# Get all records from the table
|
| 79 |
+
response = supabase.table('student_debate_case').select('*').execute()
|
| 80 |
+
|
| 81 |
+
if response.data:
|
| 82 |
+
print(f"β
Found {len(response.data)} debate cases in table:")
|
| 83 |
+
for i, case in enumerate(response.data, 1):
|
| 84 |
+
print(f" {i}. Student: {case.get('student_id', 'N/A')}")
|
| 85 |
+
print(f" Link: {case.get('google_doc_link', 'N/A')}")
|
| 86 |
+
print(f" Created: {case.get('created_at', 'N/A')}")
|
| 87 |
+
print()
|
| 88 |
+
else:
|
| 89 |
+
print("β No debate cases found in table")
|
| 90 |
+
|
| 91 |
+
return len(response.data) > 0
|
| 92 |
+
|
| 93 |
+
except Exception as e:
|
| 94 |
+
print(f"β Error listing students: {str(e)}")
|
| 95 |
+
return False
|
| 96 |
+
|
| 97 |
+
def test_username_matching():
|
| 98 |
+
"""Test if the username from session state matches any student_id in the table"""
|
| 99 |
+
print("\n=== Testing Username Matching ===")
|
| 100 |
+
|
| 101 |
+
try:
|
| 102 |
+
supabase = init_supabase()
|
| 103 |
+
if not supabase:
|
| 104 |
+
print("β Cannot test - no Supabase connection")
|
| 105 |
+
return False
|
| 106 |
+
|
| 107 |
+
# Get all student_ids from the table
|
| 108 |
+
response = supabase.table('student_debate_case').select('student_id').execute()
|
| 109 |
+
|
| 110 |
+
if response.data:
|
| 111 |
+
student_ids = [case['student_id'] for case in response.data]
|
| 112 |
+
print(f"β
Found {len(student_ids)} student IDs in table:")
|
| 113 |
+
for student_id in student_ids:
|
| 114 |
+
print(f" - {student_id}")
|
| 115 |
+
else:
|
| 116 |
+
print("β No student IDs found in table")
|
| 117 |
+
|
| 118 |
+
return len(response.data) > 0
|
| 119 |
+
|
| 120 |
+
except Exception as e:
|
| 121 |
+
print(f"β Error testing username matching: {str(e)}")
|
| 122 |
+
return False
|
| 123 |
+
|
| 124 |
+
def test_google_doc_url_conversion():
|
| 125 |
+
"""Test the Google Doc URL conversion logic"""
|
| 126 |
+
print("\n=== Testing Google Doc URL Conversion ===")
|
| 127 |
+
|
| 128 |
+
# Test URLs
|
| 129 |
+
test_urls = [
|
| 130 |
+
"https://docs.google.com/document/d/1J8Unkklwhk778jcARshISK0AdBZ34XikQpeBDAWAxY0/edit?tab=t.3t21ivxifp52#heading=h.vsxctn9u5gyw",
|
| 131 |
+
"https://docs.google.com/document/d/test123/edit",
|
| 132 |
+
"https://docs.google.com/document/d/another-test/edit?usp=sharing"
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
for url in test_urls:
|
| 136 |
+
embed_url = url.replace("edit", "preview")
|
| 137 |
+
download_url = url.replace("edit", "export?format=docx")
|
| 138 |
+
|
| 139 |
+
print(f"Original: {url}")
|
| 140 |
+
print(f"Embed: {embed_url}")
|
| 141 |
+
print(f"Download: {download_url}")
|
| 142 |
+
print()
|
| 143 |
+
|
| 144 |
+
def main():
|
| 145 |
+
"""Run all tests"""
|
| 146 |
+
print("π Week 4 Debate Case Debug Tests")
|
| 147 |
+
print("=" * 50)
|
| 148 |
+
|
| 149 |
+
# Run tests
|
| 150 |
+
tests = [
|
| 151 |
+
test_supabase_connection,
|
| 152 |
+
test_student_debate_case_table,
|
| 153 |
+
test_get_student_debate_case_function,
|
| 154 |
+
test_all_students_in_table,
|
| 155 |
+
test_username_matching,
|
| 156 |
+
test_google_doc_url_conversion
|
| 157 |
+
]
|
| 158 |
+
|
| 159 |
+
results = []
|
| 160 |
+
for test in tests:
|
| 161 |
+
try:
|
| 162 |
+
result = test()
|
| 163 |
+
results.append(result)
|
| 164 |
+
except Exception as e:
|
| 165 |
+
print(f"β Test {test.__name__} failed with exception: {str(e)}")
|
| 166 |
+
results.append(False)
|
| 167 |
+
|
| 168 |
+
# Summary
|
| 169 |
+
print("\n" + "=" * 50)
|
| 170 |
+
print("π Test Summary:")
|
| 171 |
+
passed = sum(results)
|
| 172 |
+
total = len(results)
|
| 173 |
+
print(f"β
Passed: {passed}/{total}")
|
| 174 |
+
print(f"β Failed: {total - passed}/{total}")
|
| 175 |
+
|
| 176 |
+
if passed == total:
|
| 177 |
+
print("π All tests passed!")
|
| 178 |
+
else:
|
| 179 |
+
print("β οΈ Some tests failed. Check the output above for details.")
|
| 180 |
+
|
| 181 |
+
if __name__ == "__main__":
|
| 182 |
+
main()
|