Files
daily-journal-prompt/test_current_state.py

140 lines
4.9 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify the current state of the web application.
"""
import requests
import json
import time
BASE_URL = "http://localhost:8000"
def test_endpoint(endpoint, method="GET", data=None):
"""Test an API endpoint."""
url = f"{BASE_URL}{endpoint}"
try:
if method == "GET":
response = requests.get(url, timeout=10)
elif method == "POST":
response = requests.post(url, json=data, timeout=10)
else:
return False, f"Unsupported method: {method}"
if response.status_code == 200:
return True, response.json()
else:
return False, f"Status {response.status_code}: {response.text}"
except Exception as e:
return False, f"Error: {str(e)}"
def main():
print("Testing Daily Journal Prompt Web Application")
print("=" * 50)
# Test 1: Check if backend is running
print("\n1. Testing backend health...")
success, result = test_endpoint("/")
if success:
print("✓ Backend is running")
print(f" Response: {result}")
else:
print(f"✗ Backend health check failed: {result}")
return
# Test 2: Check documentation endpoints
print("\n2. Testing documentation endpoints...")
for endpoint in ["/docs", "/redoc"]:
try:
response = requests.get(f"{BASE_URL}{endpoint}", timeout=5)
if response.status_code == 200:
print(f"{endpoint} is accessible")
else:
print(f"{endpoint} returned {response.status_code}")
except Exception as e:
print(f"{endpoint} error: {str(e)}")
# Test 3: Check prompt history
print("\n3. Testing prompt history...")
success, result = test_endpoint("/api/v1/prompts/history")
if success:
if isinstance(result, list):
print(f"✓ History has {len(result)} prompts")
if len(result) > 0:
print(f" Most recent: {result[0]['text'][:50]}...")
else:
print(f"✗ History response is not a list: {type(result)}")
else:
print(f"✗ History endpoint failed: {result}")
# Test 4: Check pool stats
print("\n4. Testing pool stats...")
success, result = test_endpoint("/api/v1/prompts/stats")
if success:
print(f"✓ Pool stats: {result['total_prompts']}/{result['target_pool_size']} prompts")
print(f" Available sessions: {result['available_sessions']}")
print(f" Needs refill: {result['needs_refill']}")
else:
print(f"✗ Pool stats failed: {result}")
# Test 5: Check feedback endpoints
print("\n5. Testing feedback endpoints...")
# Check queued words
success, result = test_endpoint("/api/v1/feedback/queued")
if success:
queued_words = result.get('queued_words', [])
print(f"✓ Queued feedback words: {len(queued_words)} words")
if queued_words:
print(f" First word: {queued_words[0]['word']} (weight: {queued_words[0]['weight']})")
else:
print(f"✗ Queued words failed: {result}")
# Check active words
success, result = test_endpoint("/api/v1/feedback/active")
if success:
active_words = result.get('active_words', [])
print(f"✓ Active feedback words: {len(active_words)} words")
if active_words:
print(f" First word: {active_words[0]['word']} (weight: {active_words[0]['weight']})")
else:
print(f"✗ Active words failed: {result}")
# Test 6: Test draw prompts
print("\n6. Testing draw prompts...")
success, result = test_endpoint("/api/v1/prompts/draw?count=1")
if success:
prompts = result.get('prompts', [])
print(f"✓ Drew {len(prompts)} prompt(s)")
if prompts:
print(f" Prompt: {prompts[0][:50]}...")
# Check updated pool stats
success2, result2 = test_endpoint("/api/v1/prompts/stats")
if success2:
print(f" Updated pool: {result2['total_prompts']}/{result2['target_pool_size']}")
else:
print(f"✗ Draw prompts failed: {result}")
# Test 7: Test frontend accessibility
print("\n7. Testing frontend accessibility...")
try:
response = requests.get("http://localhost:3000", timeout=5)
if response.status_code == 200:
print("✓ Frontend is accessible at http://localhost:3000")
else:
print(f"✗ Frontend returned {response.status_code}")
except Exception as e:
print(f"✗ Frontend error: {str(e)}")
print("\n" + "=" * 50)
print("Test completed!")
print("\nNext steps:")
print("1. Open http://localhost:3000 in your browser")
print("2. Click 'Draw 3 New Prompts' to test the workflow")
print("3. Select a prompt and click 'Use Selected Prompt'")
print("4. Click 'Fill Prompt Pool' to test feedback workflow")
if __name__ == "__main__":
main()