Skip to content

Commit 7865010

Browse files
committed
Amend DuplicateWorklistItemError to WorklistItemExistsError
1 parent ff20a06 commit 7865010

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/services/storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class InvalidStatusTransitionError(Exception):
291291
pass
292292

293293

294-
class DuplicateWorklistItemError(Exception):
294+
class WorklistItemExistsError(Exception):
295295
"""Raised when a worklist item with the same accession number already exists."""
296296

297297
pass
@@ -346,7 +346,7 @@ def store_worklist_item(
346346
)
347347
conn.commit()
348348
except sqlite3.IntegrityError:
349-
raise DuplicateWorklistItemError(f"Worklist item already exists: {worklist_item.accession_number}")
349+
raise WorklistItemExistsError(f"Worklist item already exists: {worklist_item.accession_number}")
350350

351351
return worklist_item.accession_number
352352

tests/services/test_storage.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
from pydicom.uid import generate_uid
77

88
from models import WorklistItem
9-
from services.storage import InvalidStatusTransitionError, MWLStorage, PACSStorage, WorklistItemNotFoundError
9+
from services.storage import (
10+
InvalidStatusTransitionError,
11+
MWLStorage,
12+
PACSStorage,
13+
WorklistItemExistsError,
14+
WorklistItemNotFoundError,
15+
)
1016

1117

1218
@pytest.fixture
@@ -136,6 +142,13 @@ def test_store_worklist_item(self, mwl_storage, result):
136142
assert row is not None
137143
assert row["patient_id"] == item.patient_id
138144

145+
def test_store_worklist_item_already_exists(self, mwl_storage, result):
146+
item = WorklistItem(**result)
147+
mwl_storage.store_worklist_item(item)
148+
149+
with pytest.raises(WorklistItemExistsError):
150+
mwl_storage.store_worklist_item(item)
151+
139152
def test_find_worklist_items(self, mwl_storage, result):
140153
item = self._insert_item(mwl_storage, result)
141154

0 commit comments

Comments
 (0)