Spaces:
Sleeping
Sleeping
Dhruva P Gowda
Deploy ShockMap MVP: High-fidelity UI overhaul, animated graph particles, live GDELT ingestion, and production scaffolding
f59a149 Download backend/tests/test_integration.py from shield137/shockmap-api: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/shield137/shockmap-api/resolve/main/backend/tests/test_integration.py
- Command line
-
hf download hf://spaces/shield137/shockmap-api/backend/tests/test_integration.py
-
curl -L -o test_integration.py https://huggingface.co/spaces/shield137/shockmap-api/resolve/main/backend/tests/test_integration.py
2.61 kB
| import pytest | |
| import os | |
| from httpx import AsyncClient, ASGITransport | |
| from app.main import app | |
| # Configuration for test environment | |
| BASE_URL = "http://localhost:8080" | |
| GEMINI_KEY_PRESENT = bool(os.getenv("GEMINI_API_KEY")) | |
| async def client(): | |
| transport = ASGITransport(app=app) | |
| async with AsyncClient(transport=transport, base_url=BASE_URL) as ac: | |
| yield ac | |
| async def test_healthz_ok(client): | |
| response = await client.get("/healthz") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["status"] == "ok" | |
| assert isinstance(data["gnn_loaded"], bool) | |
| async def test_graph_returns_nodes(client): | |
| response = await client.get("/api/v1/graph") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "nodes" in data | |
| assert len(data["nodes"]) > 20 | |
| async def test_drugs_filter_tier_1(client): | |
| response = await client.get("/api/v1/drugs", params={"tier": 1}) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| for drug in data["drugs"]: | |
| assert drug["nlem_tier"] == "TIER_1" | |
| async def test_drug_detail_paracetamol(client): | |
| response = await client.get("/api/v1/drug/paracetamol") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["drug"]["id"] == "paracetamol" | |
| assert "criticality_breakdown" in data | |
| async def test_alerts_critical(client): | |
| response = await client.get("/api/v1/alerts", params={"severity": "CRITICAL"}) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| # Check if our known paracetamol alert is present | |
| alert_ids = [a["id"] for a in data["alerts"]] | |
| assert "alert_paracetamol_2024_q1" in alert_ids | |
| async def test_query_grounded(client): | |
| response = await client.post("/api/v1/query", json={ | |
| "question": "Which drugs depend most on Hebei?" | |
| }) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert len(data["answer"]) > 30 | |
| assert len(data["citations"]) > 0 | |
| async def test_simulate_hebei_paracetamol(client): | |
| response = await client.post("/api/v1/simulate", json={ | |
| "province": "Hebei", | |
| "duration_days": 14, | |
| "severity": "full_shutdown" | |
| }) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| affected_ids = [d["id"] for d in data["affected_drugs"]] | |
| assert "paracetamol" in affected_ids | |