maniyakhan/todo-stack
0
1#!/usr/bin/env python32"""3Test script to verify the API is working properly and returning JSON responses4"""5 6import json7import requests8import sys9 10def test_api_responses():11 """Test that API endpoints return proper JSON responses"""12 13 base_url = "http://localhost:8000" # Default FastAPI port14 15 print("Testing API endpoints for proper JSON responses...")16 17 # Test health endpoint18 try:19 response = requests.get(f"{base_url}/health")20 print(f"Health endpoint: Status {response.status_code}")21 22 # Check if response is JSON23 try:24 data = response.json()25 print(f"Health endpoint returned JSON: {data}")26 except json.JSONDecodeError:27 print(f"ERROR: Health endpoint returned non-JSON: {response.text[:200]}...")28 return False29 30 except Exception as e:31 print(f"Could not reach health endpoint: {e}")32 print("Make sure the backend server is running on http://localhost:8000")33 return False34 35 # Test root endpoint36 try:37 response = requests.get(f"{base_url}/")38 print(f"Root endpoint: Status {response.status_code}")39 40 # Check if response is JSON41 try:42 data = response.json()43 print(f"Root endpoint returned JSON: {data}")44 except json.JSONDecodeError:45 print(f"ERROR: Root endpoint returned non-JSON: {response.text[:200]}...")46 return False47 48 except Exception as e:49 print(f"Could not reach root endpoint: {e}")50 return False51 52 print("All endpoints returned proper JSON responses!")53 return True54 55if __name__ == "__main__":56 success = test_api_responses()57 if not success:58 sys.exit(1)59 print("\n✅ API JSON response test passed!")