From 3d88a889b7efe025c6ad0c4c134d9236271cecf7 Mon Sep 17 00:00:00 2001 From: Subhash Bhushan Date: Tue, 13 Aug 2024 14:21:13 -0700 Subject: [PATCH] Introduce Patron command handler This commit includes the PlaceHold command along with its corresponding command handler and method. --- .vscode/launch.json | 2 +- src/lending/__init__.py | 2 + .../lending/app/patron}/__init__.py | 0 src/lending/app/patron/hold.py | 24 +++++++++ src/lending/model/holding_service.py | 6 +-- src/lending/model/patron/hold.py | 4 +- .../bdd/hold_handlers}/__init__.py | 0 .../features/place_a_hold_on_a_book.feature | 8 +++ .../bdd/hold_handlers/step_defs}/__init__.py | 0 .../bdd/hold_handlers/step_defs/hold_steps.py | 52 +++++++++++++++++++ .../bdd/hold_handlers}/test_holds.py | 0 .../holds => model/bdd/additions}/__init__.py | 0 .../features/book_instanced_added.feature | 0 .../bdd/additions/step_defs/addition_steps.py | 0 .../bdd/additions/test_additions.py | 0 .../bdd/checkouts/__init__.py} | 0 .../features/check_out_a_book.feature | 0 .../features/overdue_checkouts.feature | 0 .../checkouts/features/return_a_book.feature | 0 .../bdd/checkouts/step_defs/checkout_steps.py | 2 +- .../bdd/checkouts/test_checkouts.py | 0 .../bdd/daily_sheet/__init__.py} | 0 .../features/checkouts_tracking.feature | 0 .../features/expiring_holds_sheet.feature | 0 .../features/holds_tracking.feature | 0 .../features/overdue_checkouts_sheet.feature | 0 .../step_defs/daily_sheet_steps.py | 8 +-- .../bdd/daily_sheet/test_daily_sheet.py | 0 tests/lending/model/bdd/holds/__init__.py | 0 .../bdd/holds/features/cancel_a_hold.feature | 0 .../bdd/holds/features/hold_limits.feature | 0 .../open_and_close_ended_holds.feature | 0 .../features/place_a_hold_on_a_book.feature | 0 .../bdd/holds/step_defs/hold_steps.py | 20 +++---- tests/lending/model/bdd/holds/test_holds.py | 5 ++ .../model/tdd/book/test_book_aggregate.py | 0 .../tdd/book/test_book_instance_entity.py | 0 .../tdd/patron/test_checkout_entity.py | 0 .../tdd/patron/test_hold_entity.py | 0 .../tdd/patron/test_patron_aggregate.py | 0 40 files changed, 113 insertions(+), 20 deletions(-) rename {tests/lending/bdd/additions => src/lending/app/patron}/__init__.py (100%) create mode 100644 src/lending/app/patron/hold.py rename tests/lending/{bdd/checkouts => app/bdd/hold_handlers}/__init__.py (100%) create mode 100644 tests/lending/app/bdd/hold_handlers/features/place_a_hold_on_a_book.feature rename tests/lending/{bdd/daily_sheet => app/bdd/hold_handlers/step_defs}/__init__.py (100%) create mode 100644 tests/lending/app/bdd/hold_handlers/step_defs/hold_steps.py rename tests/lending/{bdd/holds => app/bdd/hold_handlers}/test_holds.py (100%) rename tests/lending/{bdd/holds => model/bdd/additions}/__init__.py (100%) rename tests/lending/{ => model}/bdd/additions/features/book_instanced_added.feature (100%) rename tests/lending/{ => model}/bdd/additions/step_defs/addition_steps.py (100%) rename tests/lending/{ => model}/bdd/additions/test_additions.py (100%) rename tests/lending/{tdd/book/test_book_aggregate.py => model/bdd/checkouts/__init__.py} (100%) rename tests/lending/{ => model}/bdd/checkouts/features/check_out_a_book.feature (100%) rename tests/lending/{ => model}/bdd/checkouts/features/overdue_checkouts.feature (100%) rename tests/lending/{ => model}/bdd/checkouts/features/return_a_book.feature (100%) rename tests/lending/{ => model}/bdd/checkouts/step_defs/checkout_steps.py (98%) rename tests/lending/{ => model}/bdd/checkouts/test_checkouts.py (100%) rename tests/lending/{tdd/book/test_book_instance_entity.py => model/bdd/daily_sheet/__init__.py} (100%) rename tests/lending/{ => model}/bdd/daily_sheet/features/checkouts_tracking.feature (100%) rename tests/lending/{ => model}/bdd/daily_sheet/features/expiring_holds_sheet.feature (100%) rename tests/lending/{ => model}/bdd/daily_sheet/features/holds_tracking.feature (100%) rename tests/lending/{ => model}/bdd/daily_sheet/features/overdue_checkouts_sheet.feature (100%) rename tests/lending/{ => model}/bdd/daily_sheet/step_defs/daily_sheet_steps.py (99%) rename tests/lending/{ => model}/bdd/daily_sheet/test_daily_sheet.py (100%) create mode 100644 tests/lending/model/bdd/holds/__init__.py rename tests/lending/{ => model}/bdd/holds/features/cancel_a_hold.feature (100%) rename tests/lending/{ => model}/bdd/holds/features/hold_limits.feature (100%) rename tests/lending/{ => model}/bdd/holds/features/open_and_close_ended_holds.feature (100%) rename tests/lending/{ => model}/bdd/holds/features/place_a_hold_on_a_book.feature (100%) rename tests/lending/{ => model}/bdd/holds/step_defs/hold_steps.py (97%) create mode 100644 tests/lending/model/bdd/holds/test_holds.py create mode 100644 tests/lending/model/tdd/book/test_book_aggregate.py create mode 100644 tests/lending/model/tdd/book/test_book_instance_entity.py rename tests/lending/{ => model}/tdd/patron/test_checkout_entity.py (100%) rename tests/lending/{ => model}/tdd/patron/test_hold_entity.py (100%) rename tests/lending/{ => model}/tdd/patron/test_patron_aggregate.py (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 819f08e..a45d466 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "module": "pytest", "justMyCode": false, "args": [ - "tests/lending/bdd/checkouts/test_checkouts.py::test_patron_checks_out_a_book_on_hold", + "tests/lending/model/bdd/holds/test_holds.py::test_regular_patron_tries_to_place_an_openended_hold", ] }, ] diff --git a/src/lending/__init__.py b/src/lending/__init__.py index 29bb951..ff883d2 100644 --- a/src/lending/__init__.py +++ b/src/lending/__init__.py @@ -18,6 +18,7 @@ ) from lending.app.dailysheet import DailySheet # isort:skip +from lending.app.patron.hold import PlaceHold # isort:skip __all__ = [ @@ -33,6 +34,7 @@ "BookStatus", "BookType", "place_hold", + "PlaceHold", "DailySheetService", "checkout", "DailySheet", diff --git a/tests/lending/bdd/additions/__init__.py b/src/lending/app/patron/__init__.py similarity index 100% rename from tests/lending/bdd/additions/__init__.py rename to src/lending/app/patron/__init__.py diff --git a/src/lending/app/patron/hold.py b/src/lending/app/patron/hold.py new file mode 100644 index 0000000..38e1ac1 --- /dev/null +++ b/src/lending/app/patron/hold.py @@ -0,0 +1,24 @@ +from protean import current_domain, handle +from protean.fields import Identifier, String + +from lending import Book, Patron, place_hold +from lending.domain import lending + + +@lending.command(part_of="Patron") +class PlaceHold: + patron_id = Identifier(required=True) + book_id = Identifier(required=True) + branch_id = Identifier(required=True) + hold_type = String(required=True) + + +@lending.command_handler(part_of="Patron") +class HoldCommandHandler: + @handle(PlaceHold) + def handle_PlaceHold(self, command: PlaceHold) -> None: + patron = current_domain.repository_for(Patron).get(command.patron_id) + book = current_domain.repository_for(Book).get(command.book_id) + + place_hold(patron, book, command.branch_id, command.hold_type)() + current_domain.repository_for(Patron).add(patron) diff --git a/src/lending/model/holding_service.py b/src/lending/model/holding_service.py index 7093ff1..c2e1b5b 100644 --- a/src/lending/model/holding_service.py +++ b/src/lending/model/holding_service.py @@ -19,7 +19,7 @@ @lending.domain_service(part_of=[Patron, Book]) class place_hold: def __init__( - self, patron: Patron, book: Book, branch_id: Identifier, hold_type: HoldType + self, patron: Patron, book: Book, branch_id: Identifier, hold_type: str ): self.patron = patron self.book = book @@ -49,7 +49,7 @@ def book_already_on_hold_cannot_be_placed_on_hold(self): def regular_patrons_cannot_place_open_ended_holds(self): if ( self.patron.patron_type == PatronType.REGULAR.value - and self.hold_type == HoldType.OPEN_ENDED + and self.hold_type == HoldType.OPEN_ENDED.value ): raise ValidationError( {"hold_type": ["Regular patrons cannot place open-ended holds"]} @@ -97,7 +97,7 @@ def __call__(self): hold = Hold( book_id=self.book.id, branch_id=self.branch_id, - hold_type=self.hold_type.value, + hold_type=self.hold_type, status=HoldStatus.ACTIVE.value, requested_at=datetime.now(), expires_on=expires_on, diff --git a/src/lending/model/patron/hold.py b/src/lending/model/patron/hold.py index 603e170..0018d3a 100644 --- a/src/lending/model/patron/hold.py +++ b/src/lending/model/patron/hold.py @@ -78,7 +78,9 @@ def expire(self): ) def cancel(self): - if self.status == HoldStatus.EXPIRED.value or self.expires_on < date.today(): + if self.status == HoldStatus.EXPIRED.value or ( + self.expires_on is not None and self.expires_on < date.today() + ): raise ValidationError({"expired_hold": ["Cannot cancel expired holds"]}) if self.status == HoldStatus.CHECKED_OUT.value: diff --git a/tests/lending/bdd/checkouts/__init__.py b/tests/lending/app/bdd/hold_handlers/__init__.py similarity index 100% rename from tests/lending/bdd/checkouts/__init__.py rename to tests/lending/app/bdd/hold_handlers/__init__.py diff --git a/tests/lending/app/bdd/hold_handlers/features/place_a_hold_on_a_book.feature b/tests/lending/app/bdd/hold_handlers/features/place_a_hold_on_a_book.feature new file mode 100644 index 0000000..48ec108 --- /dev/null +++ b/tests/lending/app/bdd/hold_handlers/features/place_a_hold_on_a_book.feature @@ -0,0 +1,8 @@ +Feature: Place a Hold on a Book + + Scenario: Regular patron places a hold on an available circulating book + Given a circulating book is available + And a regular patron is logged in + When the patron places a hold on the book + Then the hold is successfully placed + And the book is marked as held \ No newline at end of file diff --git a/tests/lending/bdd/daily_sheet/__init__.py b/tests/lending/app/bdd/hold_handlers/step_defs/__init__.py similarity index 100% rename from tests/lending/bdd/daily_sheet/__init__.py rename to tests/lending/app/bdd/hold_handlers/step_defs/__init__.py diff --git a/tests/lending/app/bdd/hold_handlers/step_defs/hold_steps.py b/tests/lending/app/bdd/hold_handlers/step_defs/hold_steps.py new file mode 100644 index 0000000..303bc56 --- /dev/null +++ b/tests/lending/app/bdd/hold_handlers/step_defs/hold_steps.py @@ -0,0 +1,52 @@ +import pytest +from protean import current_domain, g +from pytest_bdd import given, then, when + +from lending import Book, BookStatus, HoldType, PlaceHold + + +@pytest.fixture(autouse=True) +def reset_globals(): + yield + + if hasattr(g, "current_user"): + delattr(g, "current_user") + if hasattr(g, "current_book"): + delattr(g, "current_book") + if hasattr(g, "current_exception"): + delattr(g, "current_exception") + + +@given("a circulating book is available") +def a_circulating_book_is_available(circulating_book): + g.current_book = circulating_book + + +@given("a regular patron is logged in") +def a_regular_patron_is_logged_in(regular_patron): + g.current_user = regular_patron + + +@when("the patron places a hold on the book") +def the_patron_places_a_hold_on_the_book(): + command = PlaceHold( + patron_id=g.current_user.id, + book_id=g.current_book.id, + branch_id="1", + hold_type=HoldType.CLOSED_ENDED.value, + ) + current_domain.process(command) + + +@then("the hold is successfully placed") +def the_hold_is_successfully_placed(): + message = current_domain.event_store.store.read_last_message( + f"library::patron-{g.current_user.id}" + ) + assert message.metadata.type == "Library.HoldPlaced.v1" + + +@then("the book is marked as held") +def the_book_is_marked_as_held(): + book = current_domain.repository_for(Book).get(g.current_book.id) + assert book.status == BookStatus.ON_HOLD.value diff --git a/tests/lending/bdd/holds/test_holds.py b/tests/lending/app/bdd/hold_handlers/test_holds.py similarity index 100% rename from tests/lending/bdd/holds/test_holds.py rename to tests/lending/app/bdd/hold_handlers/test_holds.py diff --git a/tests/lending/bdd/holds/__init__.py b/tests/lending/model/bdd/additions/__init__.py similarity index 100% rename from tests/lending/bdd/holds/__init__.py rename to tests/lending/model/bdd/additions/__init__.py diff --git a/tests/lending/bdd/additions/features/book_instanced_added.feature b/tests/lending/model/bdd/additions/features/book_instanced_added.feature similarity index 100% rename from tests/lending/bdd/additions/features/book_instanced_added.feature rename to tests/lending/model/bdd/additions/features/book_instanced_added.feature diff --git a/tests/lending/bdd/additions/step_defs/addition_steps.py b/tests/lending/model/bdd/additions/step_defs/addition_steps.py similarity index 100% rename from tests/lending/bdd/additions/step_defs/addition_steps.py rename to tests/lending/model/bdd/additions/step_defs/addition_steps.py diff --git a/tests/lending/bdd/additions/test_additions.py b/tests/lending/model/bdd/additions/test_additions.py similarity index 100% rename from tests/lending/bdd/additions/test_additions.py rename to tests/lending/model/bdd/additions/test_additions.py diff --git a/tests/lending/tdd/book/test_book_aggregate.py b/tests/lending/model/bdd/checkouts/__init__.py similarity index 100% rename from tests/lending/tdd/book/test_book_aggregate.py rename to tests/lending/model/bdd/checkouts/__init__.py diff --git a/tests/lending/bdd/checkouts/features/check_out_a_book.feature b/tests/lending/model/bdd/checkouts/features/check_out_a_book.feature similarity index 100% rename from tests/lending/bdd/checkouts/features/check_out_a_book.feature rename to tests/lending/model/bdd/checkouts/features/check_out_a_book.feature diff --git a/tests/lending/bdd/checkouts/features/overdue_checkouts.feature b/tests/lending/model/bdd/checkouts/features/overdue_checkouts.feature similarity index 100% rename from tests/lending/bdd/checkouts/features/overdue_checkouts.feature rename to tests/lending/model/bdd/checkouts/features/overdue_checkouts.feature diff --git a/tests/lending/bdd/checkouts/features/return_a_book.feature b/tests/lending/model/bdd/checkouts/features/return_a_book.feature similarity index 100% rename from tests/lending/bdd/checkouts/features/return_a_book.feature rename to tests/lending/model/bdd/checkouts/features/return_a_book.feature diff --git a/tests/lending/bdd/checkouts/step_defs/checkout_steps.py b/tests/lending/model/bdd/checkouts/step_defs/checkout_steps.py similarity index 98% rename from tests/lending/bdd/checkouts/step_defs/checkout_steps.py rename to tests/lending/model/bdd/checkouts/step_defs/checkout_steps.py index 090ca89..98c2eb6 100644 --- a/tests/lending/bdd/checkouts/step_defs/checkout_steps.py +++ b/tests/lending/model/bdd/checkouts/step_defs/checkout_steps.py @@ -50,7 +50,7 @@ def regular_patron(regular_patron): @given("the patron has a hold on the book") def patron_with_active_hold(patron, book): - place_hold(g.current_user, book, "1", HoldType.CLOSED_ENDED)() + place_hold(g.current_user, book, "1", HoldType.CLOSED_ENDED.value)() @given("a patron has checked out a book") diff --git a/tests/lending/bdd/checkouts/test_checkouts.py b/tests/lending/model/bdd/checkouts/test_checkouts.py similarity index 100% rename from tests/lending/bdd/checkouts/test_checkouts.py rename to tests/lending/model/bdd/checkouts/test_checkouts.py diff --git a/tests/lending/tdd/book/test_book_instance_entity.py b/tests/lending/model/bdd/daily_sheet/__init__.py similarity index 100% rename from tests/lending/tdd/book/test_book_instance_entity.py rename to tests/lending/model/bdd/daily_sheet/__init__.py diff --git a/tests/lending/bdd/daily_sheet/features/checkouts_tracking.feature b/tests/lending/model/bdd/daily_sheet/features/checkouts_tracking.feature similarity index 100% rename from tests/lending/bdd/daily_sheet/features/checkouts_tracking.feature rename to tests/lending/model/bdd/daily_sheet/features/checkouts_tracking.feature diff --git a/tests/lending/bdd/daily_sheet/features/expiring_holds_sheet.feature b/tests/lending/model/bdd/daily_sheet/features/expiring_holds_sheet.feature similarity index 100% rename from tests/lending/bdd/daily_sheet/features/expiring_holds_sheet.feature rename to tests/lending/model/bdd/daily_sheet/features/expiring_holds_sheet.feature diff --git a/tests/lending/bdd/daily_sheet/features/holds_tracking.feature b/tests/lending/model/bdd/daily_sheet/features/holds_tracking.feature similarity index 100% rename from tests/lending/bdd/daily_sheet/features/holds_tracking.feature rename to tests/lending/model/bdd/daily_sheet/features/holds_tracking.feature diff --git a/tests/lending/bdd/daily_sheet/features/overdue_checkouts_sheet.feature b/tests/lending/model/bdd/daily_sheet/features/overdue_checkouts_sheet.feature similarity index 100% rename from tests/lending/bdd/daily_sheet/features/overdue_checkouts_sheet.feature rename to tests/lending/model/bdd/daily_sheet/features/overdue_checkouts_sheet.feature diff --git a/tests/lending/bdd/daily_sheet/step_defs/daily_sheet_steps.py b/tests/lending/model/bdd/daily_sheet/step_defs/daily_sheet_steps.py similarity index 99% rename from tests/lending/bdd/daily_sheet/step_defs/daily_sheet_steps.py rename to tests/lending/model/bdd/daily_sheet/step_defs/daily_sheet_steps.py index 4ce7ea8..b925077 100644 --- a/tests/lending/bdd/daily_sheet/step_defs/daily_sheet_steps.py +++ b/tests/lending/model/bdd/daily_sheet/step_defs/daily_sheet_steps.py @@ -54,7 +54,7 @@ def patron_with_active_hold(patron, book): with UnitOfWork(): refreshed_patron = current_domain.repository_for(Patron).get(patron.id) - place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) @@ -95,7 +95,7 @@ def generated_daily_sheet_for_expiring_holds(patron, book): # Place Hold refreshed_patron = current_domain.repository_for(Patron).get(patron.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) # Expire Hold @@ -152,7 +152,7 @@ def generated_daily_sheet_for_overdue_checkouts(patron, book): def place_hold_on_book(): try: refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) except ValidationError as exc: g.current_exception = exc @@ -214,7 +214,7 @@ def generate_daily_sheet(patron, book): # Place Hold refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) # Expire Hold diff --git a/tests/lending/bdd/daily_sheet/test_daily_sheet.py b/tests/lending/model/bdd/daily_sheet/test_daily_sheet.py similarity index 100% rename from tests/lending/bdd/daily_sheet/test_daily_sheet.py rename to tests/lending/model/bdd/daily_sheet/test_daily_sheet.py diff --git a/tests/lending/model/bdd/holds/__init__.py b/tests/lending/model/bdd/holds/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/lending/bdd/holds/features/cancel_a_hold.feature b/tests/lending/model/bdd/holds/features/cancel_a_hold.feature similarity index 100% rename from tests/lending/bdd/holds/features/cancel_a_hold.feature rename to tests/lending/model/bdd/holds/features/cancel_a_hold.feature diff --git a/tests/lending/bdd/holds/features/hold_limits.feature b/tests/lending/model/bdd/holds/features/hold_limits.feature similarity index 100% rename from tests/lending/bdd/holds/features/hold_limits.feature rename to tests/lending/model/bdd/holds/features/hold_limits.feature diff --git a/tests/lending/bdd/holds/features/open_and_close_ended_holds.feature b/tests/lending/model/bdd/holds/features/open_and_close_ended_holds.feature similarity index 100% rename from tests/lending/bdd/holds/features/open_and_close_ended_holds.feature rename to tests/lending/model/bdd/holds/features/open_and_close_ended_holds.feature diff --git a/tests/lending/bdd/holds/features/place_a_hold_on_a_book.feature b/tests/lending/model/bdd/holds/features/place_a_hold_on_a_book.feature similarity index 100% rename from tests/lending/bdd/holds/features/place_a_hold_on_a_book.feature rename to tests/lending/model/bdd/holds/features/place_a_hold_on_a_book.feature diff --git a/tests/lending/bdd/holds/step_defs/hold_steps.py b/tests/lending/model/bdd/holds/step_defs/hold_steps.py similarity index 97% rename from tests/lending/bdd/holds/step_defs/hold_steps.py rename to tests/lending/model/bdd/holds/step_defs/hold_steps.py index 02a7b33..138ae8f 100644 --- a/tests/lending/bdd/holds/step_defs/hold_steps.py +++ b/tests/lending/model/bdd/holds/step_defs/hold_steps.py @@ -65,7 +65,7 @@ def more_than_two_overdue_checkouts(overdue_checkouts_patron): @given("a closed-ended hold is placed") def closed_ended_hold_placed(): refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) @@ -86,7 +86,7 @@ def patron_with_fewer_than_five_holds(): def patron_with_exactly_five_holds(five_books): for i in range(5): refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, five_books[i], "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, five_books[i], "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) @@ -99,7 +99,7 @@ def patron_with_active_hold(patron, book): g.current_book = book refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) @@ -109,7 +109,7 @@ def patron_with_expired_hold(patron, book): g.current_book = book refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) @@ -123,7 +123,7 @@ def patron_with_checked_out_hold(patron, book): g.current_book = book refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) @@ -138,7 +138,7 @@ def patron_with_checked_out_hold(patron, book): def place_hold_on_book(): try: refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) except ValidationError as exc: g.current_exception = exc @@ -149,7 +149,7 @@ def place_hold_on_book(): def place_open_ended_hold(): try: refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.OPEN_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.OPEN_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) except ValidationError as exc: g.current_exception = exc @@ -159,7 +159,7 @@ def place_open_ended_hold(): def closed_ended_hold(): try: refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) except ValidationError as exc: g.current_exception = exc @@ -176,12 +176,12 @@ def check_expiring_holds(): def place_more_than_five_holds(five_books): for i in range(5): refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, five_books[i], "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, five_books[i], "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) # Place one more hold refreshed_patron = current_domain.repository_for(Patron).get(g.current_user.id) - place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED)() + place_hold(refreshed_patron, g.current_book, "1", HoldType.CLOSED_ENDED.value)() current_domain.repository_for(Patron).add(refreshed_patron) diff --git a/tests/lending/model/bdd/holds/test_holds.py b/tests/lending/model/bdd/holds/test_holds.py new file mode 100644 index 0000000..50121b5 --- /dev/null +++ b/tests/lending/model/bdd/holds/test_holds.py @@ -0,0 +1,5 @@ +from pytest_bdd import scenarios + +from .step_defs.hold_steps import * # noqa: F403 + +scenarios("./features") diff --git a/tests/lending/model/tdd/book/test_book_aggregate.py b/tests/lending/model/tdd/book/test_book_aggregate.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/lending/model/tdd/book/test_book_instance_entity.py b/tests/lending/model/tdd/book/test_book_instance_entity.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/lending/tdd/patron/test_checkout_entity.py b/tests/lending/model/tdd/patron/test_checkout_entity.py similarity index 100% rename from tests/lending/tdd/patron/test_checkout_entity.py rename to tests/lending/model/tdd/patron/test_checkout_entity.py diff --git a/tests/lending/tdd/patron/test_hold_entity.py b/tests/lending/model/tdd/patron/test_hold_entity.py similarity index 100% rename from tests/lending/tdd/patron/test_hold_entity.py rename to tests/lending/model/tdd/patron/test_hold_entity.py diff --git a/tests/lending/tdd/patron/test_patron_aggregate.py b/tests/lending/model/tdd/patron/test_patron_aggregate.py similarity index 100% rename from tests/lending/tdd/patron/test_patron_aggregate.py rename to tests/lending/model/tdd/patron/test_patron_aggregate.py