Priyansh Saxena commited on
Commit
d5fb3e9
·
1 Parent(s): d0b0680

test: add end-to-end tests

Browse files
Files changed (2) hide show
  1. tests/__init__.py +0 -0
  2. tests/test_e2e.py +151 -0
tests/__init__.py ADDED
File without changes
tests/test_e2e.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ os.environ["MOCK_LLM"] = "true"
4
+
5
+ import pytest
6
+ from httpx import AsyncClient, ASGITransport
7
+
8
+ from app.main import app
9
+
10
+
11
+ @pytest.fixture
12
+ async def client():
13
+ transport = ASGITransport(app=app)
14
+ async with AsyncClient(transport=transport, base_url="http://test") as c:
15
+ yield c
16
+
17
+
18
+ @pytest.mark.asyncio(loop_scope="function")
19
+ async def test_health_endpoint(client):
20
+ response = await client.get("/health")
21
+ assert response.status_code == 200
22
+ data = response.json()
23
+ assert data["status"] == "ok"
24
+ assert data["mock_mode"] is True
25
+
26
+
27
+ @pytest.mark.asyncio(loop_scope="function")
28
+ async def test_full_intake_flow(client):
29
+ session_id = "test1"
30
+
31
+ response = await client.post("/chat", json={"session_id": session_id, "message": "hello"})
32
+ assert response.status_code == 200
33
+ data = response.json()
34
+ assert data["reply"]
35
+ assert data["state"] in ["intake", "hpi"]
36
+
37
+ responses = [
38
+ "I have chest pain since this morning",
39
+ "It started about 3 hours ago",
40
+ "In the center of my chest",
41
+ "It has been constant",
42
+ "It feels like pressure",
43
+ "About a 7 out of 10",
44
+ "It gets worse when I walk",
45
+ "Resting helps a little",
46
+ "palpitations present, no syncope",
47
+ "mild shortness of breath, no cough",
48
+ "done",
49
+ ]
50
+
51
+ final_data = None
52
+ for resp_text in responses:
53
+ response = await client.post("/chat", json={"session_id": session_id, "message": resp_text})
54
+ assert response.status_code == 200
55
+ final_data = response.json()
56
+
57
+ assert final_data is not None
58
+ assert final_data["state"] == "done"
59
+ assert "brief" in final_data
60
+ assert final_data["brief"] is not None
61
+
62
+ brief = final_data["brief"]
63
+ assert "chief_complaint" in brief
64
+ assert "hpi" in brief
65
+ assert "ros" in brief
66
+
67
+
68
+ @pytest.mark.asyncio(loop_scope="function")
69
+ async def test_hpi_reprompt(client):
70
+ session_id = "test_vague"
71
+
72
+ await client.post("/chat", json={"session_id": session_id, "message": "hello"})
73
+ await client.post("/chat", json={"session_id": session_id, "message": "I have chest pain"})
74
+
75
+ response = await client.post("/chat", json={"session_id": session_id, "message": "When did it start?"})
76
+
77
+ vague_response = await client.post("/chat", json={"session_id": session_id, "message": "I don't know"})
78
+ assert vague_response.status_code == 200
79
+ data = vague_response.json()
80
+ assert "specific" in data["reply"].lower() or "when" in data["reply"].lower()
81
+
82
+
83
+ @pytest.mark.asyncio(loop_scope="function")
84
+ async def test_ros_scoping(client):
85
+ session_id = "test_chest_pain"
86
+
87
+ await client.post("/chat", json={"session_id": session_id, "message": "hello"})
88
+ await client.post("/chat", json={"session_id": session_id, "message": "I have chest pain"})
89
+
90
+ hpi_responses = [
91
+ "It started 3 hours ago",
92
+ "In the center of my chest",
93
+ "It has been constant",
94
+ "It feels like pressure",
95
+ "7 out of 10",
96
+ "Walking makes it worse",
97
+ "Resting helps",
98
+ ]
99
+
100
+ for resp in hpi_responses:
101
+ await client.post("/chat", json={"session_id": session_id, "message": resp})
102
+
103
+ ros_response = await client.post("/chat", json={"session_id": session_id, "message": "ready for ROS"})
104
+ ros_data = ros_response.json()
105
+
106
+ await client.post("/chat", json={"session_id": session_id, "message": "cardiac:palpitations,no syncope|respiratory:shortness of breath,no cough"})
107
+
108
+ final_response = await client.post("/chat", json={"session_id": session_id, "message": "done"})
109
+ final_data = final_response.json()
110
+
111
+ if final_data.get("brief"):
112
+ ros_keys = list(final_data["brief"]["ros"].keys())
113
+ assert "cardiac" in ros_keys or "respiratory" in ros_keys
114
+
115
+
116
+ @pytest.mark.asyncio(loop_scope="function")
117
+ async def test_brief_structure(client):
118
+ session_id = "test_brief"
119
+
120
+ messages = [
121
+ "hello",
122
+ "I have chest pain",
123
+ "It started 3 hours ago",
124
+ "In the center of my chest",
125
+ "Constant",
126
+ "Pressure-like",
127
+ "7 out of 10",
128
+ "Walking worsens it",
129
+ "Resting helps",
130
+ "cardiac:palpitations,no syncope|respiratory:shortness of breath,no cough",
131
+ ]
132
+
133
+ for msg in messages:
134
+ response = await client.post("/chat", json={"session_id": session_id, "message": msg})
135
+ assert response.status_code == 200
136
+
137
+ final_data = response.json()
138
+
139
+ if final_data.get("brief"):
140
+ brief = final_data["brief"]
141
+ from app.schemas import ClinicalBrief
142
+ validated = ClinicalBrief.model_validate(brief)
143
+
144
+ assert validated.chief_complaint
145
+ assert validated.hpi.onset
146
+ assert validated.hpi.location
147
+ assert validated.hpi.duration
148
+ assert validated.hpi.character
149
+ assert validated.hpi.severity
150
+ assert validated.hpi.aggravating
151
+ assert validated.hpi.relieving