Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ODL feed error when license already checked out (PP-1716) #2069

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/palace/manager/api/odl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 20 additions & 2 deletions tests/manager/api/odl/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
)

Expand Down