astris-backend / backend /tests /test_api.py
Destiny Otto
Add application file
0714f28
Raw History Blame Contribute Delete
1.39 kB
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_health_assets_and_model_card():
health = client.get("/api/health")
assert health.status_code == 200
assert health.json()["backend"] == "FastAPI + LangGraph"
assets = client.get("/api/assets")
assert assets.status_code == 200
assert any(row["asset"]["asset_id"] == "HSM-GBX-017" for row in assets.json())
model_card = client.get("/api/model-card").json()
assert model_card["embeddings"]["store"] == "Chroma persistent local collection"
def test_case_run_and_sse_stream():
response = client.post(
"/api/cases/CASE-GBX17-LUBE-STARVATION/run",
json={"query": "Diagnose GBX-17", "case_id": "CASE-GBX17-LUBE-STARVATION"},
)
assert response.status_code == 200
assert response.json()["risk"]["risk_level"] == "critical"
with client.stream("GET", "/api/review/stream?case_id=CASE-GBX17-LUBE-STARVATION") as stream:
text = "".join(stream.iter_text())
assert "event: tool_start" in text
assert "event: finish" in text
with client.stream("GET", "/api/chat/stream?query=Why%20is%20this%20critical%3F&case_id=CASE-GBX17-LUBE-STARVATION&agent_mode=structured") as stream:
chat_text = "".join(stream.iter_text())
assert "event: text_delta" in chat_text
assert "event: finish" in chat_text