diff --git a/src/palace/manager/api/odl/api.py b/src/palace/manager/api/odl/api.py index 74d990f50..d20d91c0a 100644 --- a/src/palace/manager/api/odl/api.py +++ b/src/palace/manager/api/odl/api.py @@ -442,6 +442,11 @@ def _checkout( json_response.get("type") == "http://opds-spec.org/odl/error/checkout/unavailable" ): + # TODO: This would be a good place to do an async availability update, since we know + # the book is unavailable, when we thought it was available. For now, we know that + # the license has no checkouts_available, so we do that update. + license.checkouts_available = 0 + licensepool.update_availability_from_licenses() raise NoAvailableCopies() raise diff --git a/tests/manager/api/odl/test_api.py b/tests/manager/api/odl/test_api.py index db84fe09f..9b558f7d5 100644 --- a/tests/manager/api/odl/test_api.py +++ b/tests/manager/api/odl/test_api.py @@ -738,7 +738,7 @@ def test_checkout_no_available_copies_unknown_to_us( ) # We think there are copies available. - opds2_with_odl_api_fixture.setup_license(concurrency=1, available=1) + license = opds2_with_odl_api_fixture.setup_license(concurrency=1, available=1) # But the distributor says there are no available copies. opds2_with_odl_api_fixture.mock_http.queue_response( @@ -751,11 +751,29 @@ def test_checkout_no_available_copies_unknown_to_us( checkout() assert db.session.query(Loan).count() == 0 + assert license.license_pool.licenses_available == 0 + assert license.checkouts_available == 0 + + def test_checkout_failures( + self, + db: DatabaseTransactionFixture, + opds2_with_odl_api_fixture: OPDS2WithODLApiFixture, + ) -> None: + checkout = partial( + opds2_with_odl_api_fixture.api.checkout, + opds2_with_odl_api_fixture.patron, + "pin", + opds2_with_odl_api_fixture.pool, + MagicMock(), + ) + + # We think there are copies available. + opds2_with_odl_api_fixture.setup_license(concurrency=1, available=1) # Test the case where we get bad JSON back from the distributor. opds2_with_odl_api_fixture.mock_http.queue_response( 400, - response_type, + "application/api-problem+json", content="hot garbage", )