Skip to content

Commit b7dcbfb

Browse files
authored
Merge pull request #1916 from NYPL-Simplified/qa
Deploy 4.1.7 to Production
2 parents 0fe73db + 4a8f66c commit b7dcbfb

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed

api/clever/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
"1": "E",
5858
"2": "E",
5959
"3": "E",
60-
"4": "M", # Middle
61-
"5": "M",
62-
"6": "M",
60+
"4": "E",
61+
"5": "E",
62+
"6": "M", # Middle
6363
"7": "M",
6464
"8": "M",
6565
"9": "H", # High
@@ -72,7 +72,6 @@
7272
"Ungraded": None,
7373
}
7474

75-
7675
def external_type_from_clever_grade(grade):
7776
"""Maps a 'grade' value returned by the Clever API for student users to an external_type"""
7877
return CLEVER_GRADE_TO_EXTERNAL_TYPE_MAP.get(grade, None)

api/clever/title_i.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8681,6 +8681,9 @@
86818681
"063432013803",
86828682
"063432013878",
86838683
"063432013916",
8684+
"063432014499",
8685+
"063432014500",
8686+
"063432014617",
86848687
"063441002774",
86858688
"063441005369",
86868689
"063441005585",

api/opds.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def open_access_link(self, pool, lpdm):
425425
always_available = OPDSFeed.makeelement(
426426
"{%s}availability" % OPDSFeed.OPDS_NS, status="available"
427427
)
428+
428429
link_tag.append(always_available)
429430
return link_tag
430431

@@ -1130,7 +1131,7 @@ def fulfill_link(self, license_pool, active_loan, delivery_mechanism,
11301131
active_loan=active_loan
11311132
)
11321133

1133-
children = AcquisitionFeed.license_tags(license_pool, active_loan, None)
1134+
children = AcquisitionFeed.license_tags(license_pool, active_loan, None, rel=rel, library=self.library)
11341135
link_tag.extend(children)
11351136

11361137
children = self.drm_device_registration_tags(

core/opds.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ def indirect_acquisition(cls, indirect_types):
16501650
return top_level_parent
16511651

16521652
@classmethod
1653-
def license_tags(cls, license_pool, loan, hold):
1653+
def license_tags(cls, license_pool, loan, hold, rel=None, library=None):
16541654
# Generate a list of licensing tags. These should be inserted
16551655
# into a <link> tag.
16561656
tags = []
@@ -1688,10 +1688,16 @@ def license_tags(cls, license_pool, loan, hold):
16881688
else:
16891689
status = 'reserved'
16901690
since = hold.start
1691-
elif (license_pool.open_access or license_pool.unlimited_access or license_pool.self_hosted or (
1691+
elif (license_pool.open_access or rel == OPDSFeed.OPEN_ACCESS_REL):
1692+
status = 'available'
1693+
1694+
default_loan_period = collection.default_loan_period(library) if library else collection.STANDARD_DEFAULT_LOAN_PERIOD
1695+
1696+
since = license_pool.availability_time
1697+
until = datetime.datetime.utcnow() + datetime.timedelta(days=default_loan_period)
1698+
elif (license_pool.unlimited_access or license_pool.self_hosted or (
16921699
license_pool.licenses_available > 0 and
1693-
license_pool.licenses_owned > 0)
1694-
):
1700+
license_pool.licenses_owned > 0)):
16951701
status = 'available'
16961702
else:
16971703
status='unavailable'

core/tests/test_opds.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,33 @@ def test_license_tags_show_self_hosted_books(self):
16251625
assert 'status' in tags[0].attrib
16261626
assert 'available' == tags[0].attrib['status']
16271627

1628+
def test_license_tags_open_access(self):
1629+
# Arrange
1630+
edition, pool = self._edition(with_license_pool=True)
1631+
pool.open_access = True
1632+
pool.self_hosted = False
1633+
pool.unlimited_access = False
1634+
creation_time = datetime.datetime.utcnow()
1635+
1636+
# Act
1637+
tags = AcquisitionFeed.license_tags(
1638+
pool, None, None
1639+
)
1640+
1641+
# Assert
1642+
assert 1 == len(tags)
1643+
1644+
[tag] = tags
1645+
1646+
assert ('status' in tag.attrib) == True
1647+
assert 'available' == tag.attrib['status']
1648+
assert 'since' in tag.attrib
1649+
assert tag.attrib['since'] == pool.availability_time.strftime('%Y-%m-%dT%H:%M:%S+00:00')
1650+
assert 'until' in tag.attrib
1651+
assert tag.attrib['until'] == (creation_time + datetime.timedelta(days=21)).strftime('%Y-%m-%dT%H:%M:%SZ')
1652+
assert ('holds' in tag.attrib) == False
1653+
assert ('copies' in tag.attrib) == False
1654+
16281655
def test_single_entry(self):
16291656

16301657
# Here's a Work with two LicensePools.

tests/clever/test_clever.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ def test_external_type_from_clever_grade(self):
4646
THEN: The matching external_type value should be returned, or None if the match fails
4747
"""
4848
for e_grade in [
49-
"InfantToddler", "Preschool", "PreKindergarten", "TransitionalKindergarten", "Kindergarten", "1", "2", "3"
49+
"InfantToddler", "Preschool", "PreKindergarten", "TransitionalKindergarten",
50+
"Kindergarten", "1", "2", "3", "4", "5"
5051
]:
5152
assert external_type_from_clever_grade(e_grade) == "E"
5253

53-
for m_grade in ["4", "5", "6", "7", "8"]:
54+
for m_grade in ["6", "7", "8"]:
5455
assert external_type_from_clever_grade(m_grade) == "M"
5556

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

0 commit comments

Comments
 (0)