Spaces:
Configuration error
Configuration error
Download tests/test_main.py from anu-122006/hackrx: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/anu-122006/hackrx/resolve/main/tests/test_main.py
- Command line
-
hf download hf://spaces/anu-122006/hackrx/tests/test_main.py
-
curl -L -o test_main.py https://huggingface.co/spaces/anu-122006/hackrx/resolve/main/tests/test_main.py
2.04 kB
| # ============================================================================ | |
| 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 | |
| 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 | |
| # ============================================================================ | |