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!")