Skip to content

Commit

Permalink
Add some type hints for our circulation api mocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Jun 5, 2024
1 parent d14b879 commit 8f82ea2
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 259 deletions.
36 changes: 19 additions & 17 deletions tests/manager/api/controller/test_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ def test_revoke_loan(
assert isinstance(patron, Patron)
loan, newly_created = loan_fixture.pool.loan_to(patron)

loan_fixture.manager.d_circulation.queue_checkin(loan_fixture.pool, True)
loan_fixture.manager.d_circulation.queue_checkin(loan_fixture.pool)

response = loan_fixture.manager.loans.revoke(loan_fixture.pool_id)

Expand Down Expand Up @@ -1156,9 +1156,7 @@ def test_revoke_hold(
assert isinstance(patron, Patron)
hold, newly_created = loan_fixture.pool.on_hold_to(patron, position=0)

loan_fixture.manager.d_circulation.queue_release_hold(
loan_fixture.pool, True
)
loan_fixture.manager.d_circulation.queue_release_hold(loan_fixture.pool)

response = loan_fixture.manager.loans.revoke(loan_fixture.pool_id)

Expand Down Expand Up @@ -1390,21 +1388,25 @@ def handle_conditional_request(last_modified=None):
bibliotheca_pool.open_access = False

loan_fixture.manager.d_circulation.add_remote_loan(
overdrive_pool.collection,
overdrive_pool.data_source,
overdrive_pool.identifier.type,
overdrive_pool.identifier.identifier,
utc_now(),
utc_now() + datetime.timedelta(seconds=3600),
LoanInfo(
overdrive_pool.collection,
overdrive_pool.data_source,
overdrive_pool.identifier.type,
overdrive_pool.identifier.identifier,
utc_now(),
utc_now() + datetime.timedelta(seconds=3600),
)
)
loan_fixture.manager.d_circulation.add_remote_hold(
bibliotheca_pool.collection,
bibliotheca_pool.data_source,
bibliotheca_pool.identifier.type,
bibliotheca_pool.identifier.identifier,
utc_now(),
utc_now() + datetime.timedelta(seconds=3600),
0,
HoldInfo(
bibliotheca_pool.collection,
bibliotheca_pool.data_source,
bibliotheca_pool.identifier.type,
bibliotheca_pool.identifier.identifier,
utc_now(),
utc_now() + datetime.timedelta(seconds=3600),
0,
)
)

# Making a new request so soon after the last one means the
Expand Down
24 changes: 14 additions & 10 deletions tests/manager/api/controller/test_odl_notify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import types
from unittest.mock import create_autospec

import flask
import pytest
Expand Down Expand Up @@ -67,26 +68,32 @@ class TestODLNotificationController:
when a loan's status changes."""

@pytest.mark.parametrize(
"protocol",
"api_cls",
[
pytest.param(ODLAPI.label(), id="ODL 1.x collection"),
pytest.param(ODL2API.label(), id="ODL 2.x collection"),
pytest.param(ODLAPI, id="ODL 1.x collection"),
pytest.param(ODL2API, id="ODL 2.x collection"),
],
)
def test_notify_success(
self,
protocol,
api_cls: type[ODLAPI] | type[ODL2API],
controller_fixture: ControllerFixture,
odl_fixture: ODLFixture,
):
db = controller_fixture.db

odl_fixture.collection.integration_configuration.protocol = protocol
odl_fixture.collection.integration_configuration.protocol = api_cls.label()
odl_fixture.pool.licenses_owned = 10
odl_fixture.pool.licenses_available = 5
loan, ignore = odl_fixture.pool.loan_to(odl_fixture.patron)
loan.external_identifier = db.fresh_str()

api = controller_fixture.manager.circulation_apis[
db.default_library().id
].api_for_license_pool(loan.license_pool)
update_loan_mock = create_autospec(api_cls.update_loan)
api.update_loan = update_loan_mock

with controller_fixture.request_context_with_library("/", method="POST"):
text = json.dumps(
{
Expand All @@ -101,11 +108,8 @@ def test_notify_success(
)
assert 200 == response.status_code

# The pool's availability has been updated.
api = controller_fixture.manager.circulation_apis[
db.default_library().id
].api_for_license_pool(loan.license_pool)
assert [loan.license_pool] == api.availability_updated_for
# Update loan was called with the expected arguments.
update_loan_mock.assert_called_once_with(loan, json.loads(text))

def test_notify_errors(self, controller_fixture: ControllerFixture):
db = controller_fixture.db
Expand Down
Loading

0 comments on commit 8f82ea2

Please sign in to comment.