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

SFR-1890_MichiganNYPLFlags #291

Merged
merged 3 commits into from
Feb 8, 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
11 changes: 3 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# CHANGELOG
## unreleased version -- v0.12.4
## Added
- New /fulfill endpoint with ability to check for NYPL login in Bearer authorization header
- Fulfill endpoint returns pre-signed URLs for objects in private buckets when user is logged in
- Change default development port to 5050 due to macOS Monterey and higher occupying port 5000 by default
# Removed
- Deleted Tugboat configuration as Tugboat is no longer used and no longer builds

## unreleased version -- v0.12.4
## Added
- New script to add nypl_login flag to Links objects
- Added nypl_login flag to nypl mapping
- Added nypl_login flags to NYPL and University of Michigan mapping and process
- New APIUtils method to generate a presigned url for S3 actions
- New /fulfill endpoint with ability to check for NYPL login in Bearer authorization header
- Fulfill endpoint returns pre-signed URLs for objects in private buckets when user is logged in
- Change default development port to 5050 due to macOS Monterey and higher occupying port 5000 by default
- Added new University of Michigan process and mapping for ingestion
- New directory for test JSON files that will be ingested
## Fixed
- NYPL records not being added due to SQLAlchemy error
- Bardo CCE API and Hathi DataFiles URL updated
- Deleted Tugboat configuration as Tugboat is no longer used and no longer builds

## 2023-09-05 version -- v0.12.3
## Removed
Expand Down
4 changes: 2 additions & 2 deletions processes/UofM.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def processUofMRecord(self, record):
UofMRec = UofMMapping(record)
UofMRec.applyMapping()
self.addHasPartMapping(record, UofMRec.record)
self.storePDFManifest(UofMRec.record)
#self.storePDFManifest(UofMRec.record)
self.addDCDWToUpdateList(UofMRec)

except (MappingError, HTTPError, ConnectionError, IndexError, TypeError) as e:
Expand All @@ -67,7 +67,7 @@ def addHasPartMapping(self, resultsRecord, record):
urlPDFObject,
'UofM',
'application/pdf',
'{"catalog": false, "download": true, "reader": false, "embed": false}'
'{"catalog": false, "download": true, "reader": false, "embed": false, "nypl_login": true}'
])
record.has_part.append(linkString)

Expand Down
26 changes: 15 additions & 11 deletions scripts/nyplLoginFlags.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

from model import Link
from model import Link, Item
from model.postgres.item import ITEM_LINKS
from managers import DBManager
from sqlalchemy import or_
import json

def main():

'''Updating NYPL Link flags with a new nypl_login flag'''
'''Updating Link flags with a new nypl_login flag'''

dbManager = DBManager(
user= os.environ.get('POSTGRES_USER', None),
Expand All @@ -21,13 +20,18 @@ def main():

dbManager.createSession()

for link in dbManager.session.query(Link) \
.filter(or_(Link.media_type == 'application/html+edd', Link.media_type == 'application/x.html+edd')).all():
if link.flags and 'edd' in link.flags and link.flags['edd'] == True:
#The link.flags doesn't update if the dict method isn't called on it
newLinkFlag = dict(link.flags)
newLinkFlag['nypl_login'] = True
link.flags = newLinkFlag

for item in dbManager.session.query(Item) \
.filter(Item.source == 'UofM'):
for link in dbManager.session.query(Link) \
.join(ITEM_LINKS) \
.filter(ITEM_LINKS.c.item_id == item.id) \
.filter(Link.media_type == 'application/pdf').all():
if link.flags:
#The link.flags doesn't update if the dict method isn't called on it
newLinkFlag = dict(link.flags)
newLinkFlag['nypl_login'] = True
link.flags = newLinkFlag

dbManager.commitChanges()

Expand Down
28 changes: 14 additions & 14 deletions tests/unit/test_UofM_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_processUofMRecord_success(self, testProcess, mocker):
mockMapping.applyMapping.assert_called_once()

processMocks['addHasPartMapping'].assert_called_once_with(mockMapping, 'testRecord')
processMocks['storePDFManifest'].assert_called_once_with('testRecord')
#processMocks['storePDFManifest'].assert_called_once_with('testRecord')
processMocks['addDCDWToUpdateList'].assert_called_once_with(mockMapping)

def test_processUofMRecord_error(self, mocker):
Expand All @@ -65,23 +65,23 @@ def test_processUofMRecord_error(self, mocker):

assert pytest.raises(MappingError)

def test_storePDFManifest(self, testProcess, mocker):
mockRecord = mocker.MagicMock(identifiers=['1|UofM'])
mockRecord.has_part = [
'1|testURI|UofM|application/pdf|{}',
]
# def test_storePDFManifest(self, testProcess, mocker):
# mockRecord = mocker.MagicMock(identifiers=['1|UofM'])
# mockRecord.has_part = [
# '1|testURI|UofM|application/pdf|{}',
# ]

mockGenerateMan = mocker.patch.object(UofMProcess, 'generateManifest')
mockGenerateMan.return_value = 'testJSON'
mockCreateMan = mocker.patch.object(UofMProcess, 'createManifestInS3')
# mockGenerateMan = mocker.patch.object(UofMProcess, 'generateManifest')
# mockGenerateMan.return_value = 'testJSON'
# mockCreateMan = mocker.patch.object(UofMProcess, 'createManifestInS3')

testProcess.storePDFManifest(mockRecord)
# testProcess.storePDFManifest(mockRecord)

testManifestURI = 'https://test_aws_bucket.s3.amazonaws.com/manifests/UofM/1.json'
assert mockRecord.has_part[0] == '1|{}|UofM|application/webpub+json|{{"catalog": false, "download": false, "reader": true, "embed": false}}'.format(testManifestURI)
# testManifestURI = 'https://test_aws_bucket.s3.amazonaws.com/manifests/UofM/1.json'
# assert mockRecord.has_part[0] == '1|{}|UofM|application/webpub+json|{{"catalog": false, "download": false, "reader": true, "embed": false}}'.format(testManifestURI)

mockGenerateMan.assert_called_once_with(mockRecord, 'testURI', testManifestURI)
mockCreateMan.assert_called_once_with('manifests/UofM/1.json', 'testJSON')
# mockGenerateMan.assert_called_once_with(mockRecord, 'testURI', testManifestURI)
# mockCreateMan.assert_called_once_with('manifests/UofM/1.json', 'testJSON')

def test_createManifestInS3(self, testProcess, mocker):
mockPut = mocker.patch.object(UofMProcess, 'putObjectInBucket')
Expand Down
Loading