-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit includes the PlaceHold command along with its corresponding command handler and method.
- Loading branch information
Showing
40 changed files
with
113 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
tests/lending/app/bdd/hold_handlers/features/place_a_hold_on_a_book.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
tests/lending/app/bdd/hold_handlers/step_defs/hold_steps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pytest_bdd import scenarios | ||
|
||
from .step_defs.hold_steps import * # noqa: F403 | ||
|
||
scenarios("./features") |
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.