File size: 2,851 Bytes
af05087
 
 
 
 
 
 
 
 
74c7e34
af05087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
import requests
import json

def test_hackrx_api():
    """Test the HackRx FastAPI server"""
    
    # API endpoint
    # url = "http://localhost:8000/challenge"
    url = "http://localhost:8000/challenge"
    url = "https://Rahul-Samedavar-hackrx.hf.space"
    # Test data (sample from problem statement)
    test_data = {
        "url": "https://register.hackrx.in/showdown/startChallenge/dGVzdF90b2tlbl9leGFtcGxl",
        "questions": [
            "Go to the website and start the challenge. Complete the challenge and return the answers for the following questions: What is the challenge name?"
        ]
    }
    
    headers = {
        "Content-Type": "application/json"
    }
    
    print("Testing HackRx API...")
    print(f"URL: {url}")
    print(f"Request Data: {json.dumps(test_data, indent=2)}")
    print("-" * 50)
    
    try:
        # Send POST request
        response = requests.post(url, headers=headers, json=test_data, timeout=60)
        
        print(f"Status Code: {response.status_code}")
        
        if response.status_code == 200:
            result = response.json()
            print("Success!")
            print(f"Response: {json.dumps(result, indent=2)}")
        else:
            print("Error!")
            print(f"Response: {response.text}")
            
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")

def test_health_check():
    """Test health check endpoint"""
    url = "http://localhost:8000/health"
    
    try:
        response = requests.get(url)
        print(f"Health Check - Status: {response.status_code}")
        print(f"Response: {response.json()}")
    except requests.exceptions.RequestException as e:
        print(f"Health check failed: {e}")

def test_simple_example():
    """Test with a simple example"""
    url = "http://localhost:8000/challenge"
    
    test_data = {
        "url": "https://httpbin.org/html",
        "questions": ["What is the title of this page?"]
    }
    
    headers = {"Content-Type": "application/json"}
    
    print("\nTesting with simple example...")
    try:
        response = requests.post(url, headers=headers, json=test_data, timeout=30)
        print(f"Status: {response.status_code}")
        if response.status_code == 200:
            print(f"Response: {json.dumps(response.json(), indent=2)}")
        else:
            print(f"Error: {response.text}")
    except requests.exceptions.RequestException as e:
        print(f"Simple test failed: {e}")

if __name__ == "__main__":
    print("=" * 60)
    print("HackRx API Test Client")
    print("=" * 60)
    
    # Test health check first
    test_health_check()
    print()
    
    # Test simple example
    test_simple_example()
    print()
    
    # Test main challenge
    test_hackrx_api()
    print()
    print("Testing complete!")