Skip to content

Commit

Permalink
Ignore axis now fulfillment (PP-1929) (#2210)
Browse files Browse the repository at this point in the history
* Ignore axis now fulfillment

* Update comment

* Code review feedback
  • Loading branch information
jonathangreen authored Dec 12, 2024
1 parent ec00a8e commit c31677f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/palace/manager/api/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Axis360API(
# The name Axis 360 gives to its web interface. We use it as the
# name for the underlying access control system.
AXISNOW = "AxisNow"
BLIO = "Blio"

delivery_mechanism_to_internal_format = {
(epub, no_drm): "ePub",
Expand Down Expand Up @@ -980,9 +981,9 @@ def process_first(

class BibliographicParser(Axis360Parser[tuple[Metadata, CirculationData]], LoggerMixin):
DELIVERY_DATA_FOR_AXIS_FORMAT = {
"Blio": None, # Legacy format, handled the same way as AxisNow
Axis360API.BLIO: None, # Legacy format, handled the same way as AxisNow
"Acoustik": (None, DeliveryMechanism.FINDAWAY_DRM), # Audiobooks
"AxisNow": None, # Handled specially, for ebooks only.
Axis360API.AXISNOW: None, # Handled specially, for ebooks only.
"ePub": (Representation.EPUB_MEDIA_TYPE, DeliveryMechanism.ADOBE_DRM),
"PDF": (Representation.PDF_MEDIA_TYPE, DeliveryMechanism.ADOBE_DRM),
}
Expand Down Expand Up @@ -1226,7 +1227,7 @@ def extract_bibliographic(
informal_name = format_tag.text
seen_formats.append(informal_name)

if informal_name == "Blio":
if informal_name == Axis360API.BLIO:
# We will be adding an AxisNow FormatData.
blio_seen = True
continue
Expand Down Expand Up @@ -1568,6 +1569,12 @@ def process_one(

info: AxisLoanInfo | HoldInfo | None = None
if checked_out:
# When the item is checked out, it can be locked to a particular DRM format. So even though
# the item supports other formats, it can only be fulfilled in the format that was checked out.
# This format is returned in the checkoutFormat tag.
checkout_format = self.text_of_optional_subtag(
availability, "axis:checkoutFormat", ns
)
start_date = self._xpath1_date(availability, "axis:checkoutStartDate", ns)
end_date = self._xpath1_date(availability, "axis:checkoutEndDate", ns)
download_url = self.text_of_optional_subtag(
Expand All @@ -1578,6 +1585,14 @@ def process_one(
or ""
)

if not self.internal_format and (
checkout_format == self.api.AXISNOW or checkout_format == self.api.BLIO
):
# If we didn't explicitly ask for a format, ignore any AxisNow or Blio formats, since
# we can't fulfill them. If we add AxisNow and Blio support in the future, we can remove
# this check.
return None

fulfillment: Fulfillment | None
if download_url and self.internal_format != self.api.AXISNOW:
# The patron wants a direct link to the book, which we can deliver
Expand Down
8 changes: 7 additions & 1 deletion tests/manager/api/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_fulfill(self, axis360: Axis360Fixture):
pytest.raises(NoActiveLoan, fulfill)

# If an ebook is checked out and we're not asking for it to be
# fulfilled through AxisNow, we get a Axis360AcsFulfillment
# fulfilled through Adobe DRM, we get a Axis360AcsFulfillment
# object with a content link.
data = axis360.sample_data("availability_with_loan_and_hold.xml")
axis360.api.queue_response(200, content=data)
Expand Down Expand Up @@ -551,6 +551,12 @@ def test_patron_activity(self, axis360: Axis360Fixture):
assert isinstance(hold2, HoldInfo)
assert isinstance(loan, LoanInfo)

# If the activity includes something with a Blio format, it is not included in the results.
data = axis360.sample_data("availability_with_axisnow_fulfillment.xml")
axis360.api.queue_response(200, content=data)
results = axis360.api.patron_activity(patron, "pin")
assert len(results) == 0

def test_update_licensepools_for_identifiers(self, axis360: Axis360Fixture):
class Mock(MockAxis360API):
"""Simulates an Axis 360 API that knows about some
Expand Down

0 comments on commit c31677f

Please sign in to comment.