File size: 2,040 Bytes
1a27ebc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ============================================================================

import pytest
import asyncio
from fastapi.testclient import TestClient
from unittest.mock import AsyncMock, MagicMock

from main import app

class TestHackRxAPI:
    """Test suite for HackRx 6.0 API"""
    
    def setup_method(self):
        """Setup test environment"""
        self.client = TestClient(app)
        
    def test_root_endpoint(self):
        """Test root endpoint returns correct information"""
        response = self.client.get("/")
        assert response.status_code == 200
        data = response.json()
        assert "HackRx 6.0" in data["message"]
        assert "endpoints" in data
        
    def test_health_endpoint(self):
        """Test health check endpoint"""
        response = self.client.get("/health")
        assert response.status_code == 200
        data = response.json()
        assert data["status"] == "healthy"
        assert "components" in data
        
    @pytest.mark.asyncio
    async def test_hackrx_run_endpoint_validation(self):
        """Test request validation"""
        # Test missing fields
        response = self.client.post("/hackrx/run", json={})
        assert response.status_code == 422
        
        # Test invalid URL
        response = self.client.post("/hackrx/run", json={
            "documents": "invalid-url",
            "questions": ["test question"]
        })
        assert response.status_code == 422
        
        # Test empty questions
        response = self.client.post("/hackrx/run", json={
            "documents": "https://example.com/test.pdf",
            "questions": []
        })
        assert response.status_code == 422
        
        # Test too many questions
        response = self.client.post("/hackrx/run", json={
            "documents": "https://example.com/test.pdf",
            "questions": ["question"] * 25
        })
        assert response.status_code == 422

# ============================================================================