File size: 3,305 Bytes
dfa77fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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)