import requests import json import sys def verify_api(): url = "http://localhost:8000/infer/video" # Create a dummy video file for testing if one doesn't exist with open("sample_input.mp4", "wb") as f: f.write(b"dummy video content") try: files = {'file': open('sample_input.mp4', 'rb')} data = {'skill_level': 'intermediate'} print(f"Sending request to {url}...") response = requests.post(url, files=files, data=data) print(f"Status Code: {response.status_code}") if response.status_code == 200: print("Response validation successful!") try: json_resp = response.json() # strict validation check - keys must match our schema required_keys = ['frames', 'prediction', 'predictions', 'contact', 'ksi', 'coaching'] missing = [k for k in required_keys if k not in json_resp] if missing: print(f"❌ Missing keys in response: {missing}") sys.exit(1) else: print("✅ Response structure verified against required keys.") print("Sample of response:") print(json.dumps(json_resp, indent=2)[:500] + "...") except ValueError: print("❌ Response is not valid JSON") sys.exit(1) else: print(f"❌ Request failed with status {response.status_code}") print(response.text) # We expect a 500 here because our dummy video is invalid, but it proves the endpoint is reachable # and our error handling is working if it returns JSON if response.headers.get('content-type') == 'application/json': print("✅ Error handling verified: Received JSON error response.") else: print("❌ Error handling failed: Did not receive JSON error response.") except Exception as e: print(f"❌ Verification failed with exception: {e}") finally: files['file'].close() if __name__ == "__main__": verify_api()