22
33import pytest
44
5+ from models import WorklistItem
56from relay_listener import RelayListener
67from services .storage import MWLStorage
78
89
910class TestRelayListenerProcessesActions :
11+ @pytest .fixture
12+ def update_payload (self ):
13+ return {
14+ "action_id" : "action-12345" ,
15+ "action_type" : "worklist.update_item_status" ,
16+ "parameters" : {"worklist_item" : {"accession_number" : "ACC999999" , "status" : "in progress" }},
17+ }
18+
1019 @pytest .mark .asyncio
1120 async def test_relay_listener_creates_worklist_items (self , listener_payload , tmp_dir , fake_relay ):
1221 storage = MWLStorage (f"{ tmp_dir } /test_worklist.db" )
@@ -22,3 +31,34 @@ async def test_relay_listener_creates_worklist_items(self, listener_payload, tmp
2231 item = stored_items [0 ]
2332 assert item .accession_number == "ACC999999"
2433 assert item .patient_id == "999123456"
34+
35+ @pytest .mark .asyncio
36+ async def test_relay_listener_updates_worklist_item_status (self , update_payload , tmp_dir , fake_relay ):
37+ storage = MWLStorage (f"{ tmp_dir } /test_worklist.db" )
38+ listener = RelayListener (storage )
39+ relay_message = json .dumps ({"accept" : {"address" : "wss://accept-url" }})
40+
41+ storage .store_worklist_item (
42+ WorklistItem (** {
43+ "accession_number" : "ACC999999" ,
44+ "patient_id" : "999123456" ,
45+ "patient_name" : "Test^Patient" ,
46+ "patient_birth_date" : "19900101" ,
47+ "patient_sex" : "F" ,
48+ "scheduled_date" : "20240101" ,
49+ "scheduled_time" : "090000" ,
50+ "modality" : "MG" ,
51+ "study_description" : "Mammogram" ,
52+ "source_message_id" : "action-12345" ,
53+ })
54+ )
55+
56+ with fake_relay (relay_message , json .dumps (update_payload )) as ws_client :
57+ await listener .listen ()
58+
59+ ws_client .send .assert_called_once_with (json .dumps ({"accession_number" : "ACC999999" , "status" : "IN PROGRESS" }))
60+ stored_items = storage .find_worklist_items ()
61+ assert len (stored_items ) == 1
62+ item = stored_items [0 ]
63+ assert item .accession_number == "ACC999999"
64+ assert item .patient_id == "999123456"
0 commit comments