Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| π― Quick Decision API Test | |
| Tests the improved error handling for expired/invalid decision IDs | |
| """ | |
| import requests | |
| import asyncio | |
| import logging | |
| from datetime import datetime | |
| # Configure logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def test_decision_endpoints(): | |
| """Test decision endpoints with various scenarios""" | |
| base_url = "http://localhost:8000" | |
| print("π― Testing Decision API Error Handling") | |
| print("=" * 50) | |
| # Test 1: Valid decision ID (should fail gracefully if expired) | |
| print("\n1. π§ͺ Testing expired decision ID...") | |
| expired_decision_id = "DEC-3FB627FB" # From the logs | |
| try: | |
| response = requests.get(f"{base_url}/api/decision/approve/{expired_decision_id}") | |
| print(f" π Status Code: {response.status_code}") | |
| print(f" π Content Type: {response.headers.get('content-type', 'unknown')}") | |
| if response.status_code == 200: | |
| print(" β Graceful handling - User sees friendly error page") | |
| # Check if it's HTML (user-friendly page) | |
| if 'text/html' in response.headers.get('content-type', ''): | |
| print(" π¨ HTML response - User-friendly interface") | |
| else: | |
| print(" π Non-HTML response") | |
| else: | |
| print(f" β Error response: {response.status_code}") | |
| except requests.exceptions.ConnectionError: | |
| print(" β οΈ Server not running - start with 'uvicorn main:app --reload --port 8000'") | |
| return False | |
| except Exception as e: | |
| print(f" β Unexpected error: {str(e)}") | |
| return False | |
| # Test 2: Invalid decision ID | |
| print("\n2. π§ͺ Testing invalid decision ID...") | |
| invalid_decision_id = "DEC-INVALID123" | |
| try: | |
| response = requests.get(f"{base_url}/api/decision/approve/{invalid_decision_id}") | |
| print(f" π Status Code: {response.status_code}") | |
| if response.status_code == 200: | |
| print(" β Graceful handling - User sees friendly error page") | |
| else: | |
| print(f" β Error response: {response.status_code}") | |
| except Exception as e: | |
| print(f" β Error: {str(e)}") | |
| # Test 3: Check pending decisions | |
| print("\n3. π§ͺ Testing pending decisions endpoint...") | |
| try: | |
| response = requests.get(f"{base_url}/api/decision/pending") | |
| print(f" π Status Code: {response.status_code}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| pending_count = data.get('pending_decisions', {}).get('total_pending', 0) | |
| print(f" π Pending decisions: {pending_count}") | |
| print(" β Pending decisions endpoint working") | |
| else: | |
| print(f" β Error response: {response.status_code}") | |
| except Exception as e: | |
| print(f" β Error: {str(e)}") | |
| print("\n" + "=" * 50) | |
| print("β Decision API error handling test completed!") | |
| print("\nπ What this means:") | |
| print(" β’ Sponsors clicking expired links get friendly error pages") | |
| print(" β’ No more 'dict object is not callable' crashes") | |
| print(" β’ Clear explanations of what went wrong") | |
| print(" β’ Better user experience for decision workflows") | |
| return True | |
| if __name__ == "__main__": | |
| print(f"π Test started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") | |
| success = test_decision_endpoints() | |
| if success: | |
| print("\nπ All tests completed successfully!") | |
| else: | |
| print("\nβ Some tests failed - check server status") |