File size: 1,266 Bytes
e9462cd | 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 | from fastapi.testclient import TestClient
from app import app
client = TestClient(app)
def test_health() -> None:
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["ok"] is True
assert "generator_model" in data
def test_chat_general() -> None:
response = client.post("/chat", json={"message": "What can you do in this game?"})
assert response.status_code == 200
data = response.json()
assert "reply" in data
assert "meta" in data
def test_logging_roundtrip() -> None:
start = client.post("/log/session/start", json={"participant_id": "test_user"})
assert start.status_code == 200
session_id = start.json()["session_id"]
event = client.post(
"/log/event",
json={
"participant_id": "test_user",
"session_id": session_id,
"event_type": "AIAppOpened",
"payload": {"questionIndex": 1},
},
)
assert event.status_code == 200
research = client.get(f"/research/session/{session_id}")
assert research.status_code == 200
data = research.json()
assert data["ok"] is True
assert data["session"]["session_id"] == session_id
assert len(data["events"]) >= 1
|