#!/usr/bin/env python3 """ Test script for hackrx/run endpoint """ import requests import json # Your ngrok URL BASE_URL = "https://c1c8ea4c476e.ngrok-free.app" def test_hackrx_run(): """Test the hackrx/run endpoint""" print("๐Ÿงช Testing hackrx/run endpoint...") url = f"{BASE_URL}/hackrx/run" payload = { "questions": [ "What is covered under this policy?", "What is the maximum coverage amount?" ] } try: print(f"URL: {url}") print(f"Payload: {json.dumps(payload, indent=2)}") response = requests.post( url, json=payload, headers={"Content-Type": "application/json"}, timeout=30 ) print(f"Status Code: {response.status_code}") print(f"Response: {json.dumps(response.json(), indent=2)}") if response.status_code == 200: print("โœ… hackrx/run endpoint is working!") return True else: print("โŒ hackrx/run endpoint failed") return False except requests.exceptions.ConnectionError: print("โŒ Connection error - server might not be running") return False except Exception as e: print(f"โŒ Error: {e}") return False def test_health(): """Test health endpoint""" print("\n๐Ÿ” Testing health endpoint...") try: response = requests.get(f"{BASE_URL}/api/health") print(f"Health Status: {response.status_code}") print(f"Health Response: {json.dumps(response.json(), indent=2)}") return response.status_code == 200 except Exception as e: print(f"โŒ Health check failed: {e}") return False def test_root(): """Test root endpoint""" print("\n๐Ÿ  Testing root endpoint...") try: response = requests.get(f"{BASE_URL}/") print(f"Root Status: {response.status_code}") print(f"Root Response: {json.dumps(response.json(), indent=2)}") return response.status_code == 200 except Exception as e: print(f"โŒ Root check failed: {e}") return False def main(): """Run all tests""" print("๐Ÿš€ Testing HackRX Endpoints") print("=" * 50) # Test basic endpoints first health_ok = test_health() root_ok = test_root() if not health_ok: print("โŒ Server is not responding. Please restart the Flask server.") return # Test the main hackrx/run endpoint hackrx_ok = test_hackrx_run() print("\n" + "=" * 50) print("๐Ÿ“Š TEST RESULTS") print("=" * 50) print(f"Health Check: {'โœ… PASS' if health_ok else 'โŒ FAIL'}") print(f"Root Endpoint: {'โœ… PASS' if root_ok else 'โŒ FAIL'}") print(f"HackRX Run: {'โœ… PASS' if hackrx_ok else 'โŒ FAIL'}") if hackrx_ok: print("\n๐ŸŽ‰ Your endpoint is ready for hackathon submission!") print(f"URL: {BASE_URL}/hackrx/run") else: print("\nโš ๏ธ Please restart your Flask server and try again.") if __name__ == "__main__": main()