Spaces:
Running
Running
| 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) | |