File size: 2,352 Bytes
ec96972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script for Hugging Face Spaces deployment
"""

import requests
import json
import sys

def test_health_check(base_url):
    """Test the health check endpoint"""
    try:
        response = requests.get(f"{base_url}/")
        print(f"Health check status: {response.status_code}")
        print(f"Response: {response.json()}")
        return response.status_code == 200
    except Exception as e:
        print(f"Health check failed: {e}")
        return False

def test_api_endpoint(base_url, api_key):
    """Test the main API endpoint"""
    try:
        url = f"{base_url}/api/v1/hackrx/run"
        headers = {
            "Content-Type": "application/json",
            "Authorization": f"Bearer {api_key}"
        }
        data = {
            "documents": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
            "questions": ["What is this document about?"]
        }
        
        response = requests.post(url, headers=headers, json=data)
        print(f"API test status: {response.status_code}")
        print(f"Response: {response.json()}")
        return response.status_code == 200
    except Exception as e:
        print(f"API test failed: {e}")
        return False

def main():
    if len(sys.argv) < 2:
        print("Usage: python test_deployment.py <base_url> [api_key]")
        print("Example: python test_deployment.py https://your-space-name.hf.space your_api_key")
        sys.exit(1)
    
    base_url = sys.argv[1].rstrip('/')
    api_key = sys.argv[2] if len(sys.argv) > 2 else "test_token"
    
    print(f"Testing deployment at: {base_url}")
    print("=" * 50)
    
    # Test health check
    print("1. Testing health check...")
    health_ok = test_health_check(base_url)
    
    # Test API endpoint
    print("\n2. Testing API endpoint...")
    api_ok = test_api_endpoint(base_url, api_key)
    
    # Summary
    print("\n" + "=" * 50)
    print("DEPLOYMENT TEST SUMMARY")
    print("=" * 50)
    print(f"Health check: {'✅ PASS' if health_ok else '❌ FAIL'}")
    print(f"API endpoint: {'✅ PASS' if api_ok else '❌ FAIL'}")
    
    if health_ok and api_ok:
        print("\n🎉 Deployment is working correctly!")
    else:
        print("\n⚠️  Some tests failed. Check the logs above for details.")

if __name__ == "__main__":
    main()