Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/relay_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down
5 changes: 0 additions & 5 deletions tests/services/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

from models import WorklistItem
from services.storage import MWLStorage, PACSStorage, WorklistItemNotFoundError
from services.storage import (
MWLStorage,
PACSStorage,
WorklistItemNotFoundError,
)


@pytest.fixture
Expand Down
14 changes: 14 additions & 0 deletions tests/test_relay_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
Loading