diff --git a/api/clever/__init__.py b/api/clever/__init__.py index 93a67c400..fe60dabb5 100644 --- a/api/clever/__init__.py +++ b/api/clever/__init__.py @@ -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 @@ -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) diff --git a/api/clever/title_i.json b/api/clever/title_i.json index c1515179b..99d9de733 100644 --- a/api/clever/title_i.json +++ b/api/clever/title_i.json @@ -8681,6 +8681,9 @@ "063432013803", "063432013878", "063432013916", + "063432014499", + "063432014500", + "063432014617", "063441002774", "063441005369", "063441005585", diff --git a/api/opds.py b/api/opds.py index eb7c6fb4f..9261217a6 100644 --- a/api/opds.py +++ b/api/opds.py @@ -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 @@ -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( diff --git a/core/opds.py b/core/opds.py index 9dec1c0eb..d842d2ae8 100644 --- a/core/opds.py +++ b/core/opds.py @@ -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 tag. tags = [] @@ -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' diff --git a/core/tests/test_opds.py b/core/tests/test_opds.py index 5cbaa3be2..4c5455eec 100644 --- a/core/tests/test_opds.py +++ b/core/tests/test_opds.py @@ -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. diff --git a/tests/clever/test_clever.py b/tests/clever/test_clever.py index 2a8e6cf02..c5dd4f349 100644 --- a/tests/clever/test_clever.py +++ b/tests/clever/test_clever.py @@ -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"]: