import requests import json print("=" * 60) print("COMPREHENSIVE API TESTING") print("=" * 60) base_url = "https://ranar118-voice-detection.hf.space" # Test 1: Check if site is accessible print("\n1. Testing root endpoint...") try: response = requests.get(f"{base_url}/", timeout=10) print(f" ✓ Status Code: {response.status_code}") print(f" ✓ Content-Type: {response.headers.get('content-type')}") print(f" ✓ Content Length: {len(response.content)} bytes") # Check if the HTML contains the updated URL if '/detect' in response.text and 'http://127.0.0.1:8000' not in response.text: print(" ✓ HTML has been updated with relative URL") elif 'http://127.0.0.1:8000' in response.text: print(" ✗ WARNING: HTML still contains localhost URL!") else: print(" ? Could not verify URL in HTML") except Exception as e: print(f" ✗ Error: {e}") # Test 2: Test /detect endpoint with proper authentication print("\n2. Testing /detect endpoint with API key...") try: headers = {"x-api-key": "my_secret_key_123"} # Use a simple test without actual audio response = requests.post(f"{base_url}/detect", headers=headers, timeout=10) print(f" Status Code: {response.status_code}") print(f" Response: {response.text[:200]}") if response.status_code == 400: print(" ✓ API is responding (400 expected without audio file)") elif response.status_code == 200: print(" ✓ API is working!") else: print(f" ? Unexpected status: {response.status_code}") except Exception as e: print(f" ✗ Error: {e}") # Test 3: Test without API key (should fail with 403) print("\n3. Testing /detect without API key (should fail)...") try: response = requests.post(f"{base_url}/detect", timeout=10) print(f" Status Code: {response.status_code}") if response.status_code == 403: print(" ✓ Authentication is working correctly") else: print(f" Response: {response.text[:200]}") except Exception as e: print(f" ✗ Error: {e}") # Test 4: Check CORS headers print("\n4. Checking CORS headers...") try: response = requests.options(f"{base_url}/detect", headers={ "Origin": "https://ranar118-voice-detection.hf.space", "Access-Control-Request-Method": "POST" }, timeout=10) print(f" Status Code: {response.status_code}") cors_headers = {k: v for k, v in response.headers.items() if 'access-control' in k.lower()} if cors_headers: print(f" CORS Headers: {cors_headers}") else: print(" ⚠ No CORS headers found (might need to add CORS middleware)") except Exception as e: print(f" ✗ Error: {e}") # Test 5: Test /generate endpoint print("\n5. Testing /generate endpoint...") try: response = requests.post(f"{base_url}/generate", headers={"Content-Type": "application/json"}, json={"text": "test", "murf_api_key": "test", "voice_id": "test"}, timeout=10) print(f" Status Code: {response.status_code}") print(f" Response: {response.text[:200]}") except Exception as e: print(f" ✗ Error: {e}") print("\n" + "=" * 60) print("TESTING COMPLETE") print("=" * 60)