diff --git a/src/relay_listener.py b/src/relay_listener.py index 5b117c8b..88e65012 100644 --- a/src/relay_listener.py +++ b/src/relay_listener.py @@ -28,12 +28,8 @@ logger = logging.getLogger(__name__) DB_PATH = os.getenv("MWL_DB_PATH", "/var/lib/pacs/worklist.db") -SAS_TOKEN_EXPIRY_SECONDS = 3600 - -ACTIONS = { - "worklist.create_item": CreateWorklistItem, -} EXPIRED_TOKEN = "ExpiredToken" +SAS_TOKEN_EXPIRY_SECONDS = 3600 class RelayListener: @@ -86,11 +82,12 @@ def process_action(self, payload: dict): """Process incoming action payload.""" action_name = payload.get("action_type", "no-op") - action_class = ACTIONS.get(action_name) - if not action_class: - raise ValueError(f"Unknown action: {action_name}") - - return action_class(self.storage).call(payload) + if action_name == "echo": + return {"status": "echo", "payload": payload} + elif action_name == "worklist.create_item": + return CreateWorklistItem(self.storage).call(payload) + else: + raise ValueError(f"Unsupported action: {action_name}") def _connect(self): """Connect to Azure Relay.""" diff --git a/tests/services/test_storage.py b/tests/services/test_storage.py index 9a761a8c..fcf5ce91 100644 --- a/tests/services/test_storage.py +++ b/tests/services/test_storage.py @@ -7,11 +7,6 @@ from models import WorklistItem from services.storage import MWLStorage, PACSStorage, WorklistItemNotFoundError -from services.storage import ( - MWLStorage, - PACSStorage, - WorklistItemNotFoundError, -) @pytest.fixture diff --git a/tests/test_relay_listener.py b/tests/test_relay_listener.py index a3595790..c384f9d8 100644 --- a/tests/test_relay_listener.py +++ b/tests/test_relay_listener.py @@ -34,6 +34,20 @@ def test_relay_listener_initialization(self, storage_instance): assert subject.relay_uri.key_name == "test-key-name" assert subject.relay_uri.shared_access_key == "test-key-value" + @pytest.mark.asyncio + async def test_relay_listener_listen_echo(self, storage_instance, fake_relay): + subject = RelayListener(storage_instance) + + relay_message = json.dumps({"accept": {"address": "wss://accept-url"}}) + client_payload = json.dumps({"action_type": "echo", "message": "Hello, Relay!"}) + + with fake_relay(relay_message, client_payload) as client_ws: + await subject.listen() + + client_ws.send.assert_called_once_with( + json.dumps({"status": "echo", "payload": {"action_type": "echo", "message": "Hello, Relay!"}}) + ) + @pytest.mark.asyncio async def test_relay_listener_listen(self, storage_instance, listener_payload, fake_relay): storage_instance.store_worklist_action.return_value = {"action_id": "action-12345", "status": "created"}