Skip to content

Commit

Permalink
Merge pull request #1916 from NYPL-Simplified/qa
Browse files Browse the repository at this point in the history
Deploy 4.1.7 to Production
  • Loading branch information
keithbauer authored Dec 20, 2023
2 parents 0fe73db + 4a8f66c commit b7dcbfb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
7 changes: 3 additions & 4 deletions api/clever/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"1": "E",
"2": "E",
"3": "E",
"4": "M", # Middle
"5": "M",
"6": "M",
"4": "E",
"5": "E",
"6": "M", # Middle
"7": "M",
"8": "M",
"9": "H", # High
Expand All @@ -72,7 +72,6 @@
"Ungraded": None,
}


def external_type_from_clever_grade(grade):
"""Maps a 'grade' value returned by the Clever API for student users to an external_type"""
return CLEVER_GRADE_TO_EXTERNAL_TYPE_MAP.get(grade, None)
Expand Down
3 changes: 3 additions & 0 deletions api/clever/title_i.json
Original file line number Diff line number Diff line change
Expand Up @@ -8681,6 +8681,9 @@
"063432013803",
"063432013878",
"063432013916",
"063432014499",
"063432014500",
"063432014617",
"063441002774",
"063441005369",
"063441005585",
Expand Down
3 changes: 2 additions & 1 deletion api/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def open_access_link(self, pool, lpdm):
always_available = OPDSFeed.makeelement(
"{%s}availability" % OPDSFeed.OPDS_NS, status="available"
)

link_tag.append(always_available)
return link_tag

Expand Down Expand Up @@ -1130,7 +1131,7 @@ def fulfill_link(self, license_pool, active_loan, delivery_mechanism,
active_loan=active_loan
)

children = AcquisitionFeed.license_tags(license_pool, active_loan, None)
children = AcquisitionFeed.license_tags(license_pool, active_loan, None, rel=rel, library=self.library)
link_tag.extend(children)

children = self.drm_device_registration_tags(
Expand Down
14 changes: 10 additions & 4 deletions core/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ def indirect_acquisition(cls, indirect_types):
return top_level_parent

@classmethod
def license_tags(cls, license_pool, loan, hold):
def license_tags(cls, license_pool, loan, hold, rel=None, library=None):
# Generate a list of licensing tags. These should be inserted
# into a <link> tag.
tags = []
Expand Down Expand Up @@ -1688,10 +1688,16 @@ def license_tags(cls, license_pool, loan, hold):
else:
status = 'reserved'
since = hold.start
elif (license_pool.open_access or license_pool.unlimited_access or license_pool.self_hosted or (
elif (license_pool.open_access or rel == OPDSFeed.OPEN_ACCESS_REL):
status = 'available'

default_loan_period = collection.default_loan_period(library) if library else collection.STANDARD_DEFAULT_LOAN_PERIOD

since = license_pool.availability_time
until = datetime.datetime.utcnow() + datetime.timedelta(days=default_loan_period)
elif (license_pool.unlimited_access or license_pool.self_hosted or (
license_pool.licenses_available > 0 and
license_pool.licenses_owned > 0)
):
license_pool.licenses_owned > 0)):
status = 'available'
else:
status='unavailable'
Expand Down
27 changes: 27 additions & 0 deletions core/tests/test_opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,33 @@ def test_license_tags_show_self_hosted_books(self):
assert 'status' in tags[0].attrib
assert 'available' == tags[0].attrib['status']

def test_license_tags_open_access(self):
# Arrange
edition, pool = self._edition(with_license_pool=True)
pool.open_access = True
pool.self_hosted = False
pool.unlimited_access = False
creation_time = datetime.datetime.utcnow()

# Act
tags = AcquisitionFeed.license_tags(
pool, None, None
)

# Assert
assert 1 == len(tags)

[tag] = tags

assert ('status' in tag.attrib) == True
assert 'available' == tag.attrib['status']
assert 'since' in tag.attrib
assert tag.attrib['since'] == pool.availability_time.strftime('%Y-%m-%dT%H:%M:%S+00:00')
assert 'until' in tag.attrib
assert tag.attrib['until'] == (creation_time + datetime.timedelta(days=21)).strftime('%Y-%m-%dT%H:%M:%SZ')
assert ('holds' in tag.attrib) == False
assert ('copies' in tag.attrib) == False

def test_single_entry(self):

# Here's a Work with two LicensePools.
Expand Down
5 changes: 3 additions & 2 deletions tests/clever/test_clever.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ def test_external_type_from_clever_grade(self):
THEN: The matching external_type value should be returned, or None if the match fails
"""
for e_grade in [
"InfantToddler", "Preschool", "PreKindergarten", "TransitionalKindergarten", "Kindergarten", "1", "2", "3"
"InfantToddler", "Preschool", "PreKindergarten", "TransitionalKindergarten",
"Kindergarten", "1", "2", "3", "4", "5"
]:
assert external_type_from_clever_grade(e_grade) == "E"

for m_grade in ["4", "5", "6", "7", "8"]:
for m_grade in ["6", "7", "8"]:
assert external_type_from_clever_grade(m_grade) == "M"

for h_grade in ["9", "10", "11", "12", "13", "PostGraduate"]:
Expand Down

0 comments on commit b7dcbfb

Please sign in to comment.