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_1864_NoNYPLRecordsCreated #279

Merged
merged 2 commits into from
Dec 21, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- New script to add nypl_login flag to Links objects
- Added nypl_login flag to nypl mapping
## Fixed
- NYPL records not being added due to SQLAlchemy error

## 2023-09-05 version -- v0.12.3
## Removed
Expand Down
3 changes: 3 additions & 0 deletions processes/nypl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .core import CoreProcess
from managers.db import DBManager
from mappings.nypl import NYPLMapping
from sqlalchemy import text


class NYPLProcess(CoreProcess):
Expand Down Expand Up @@ -100,9 +101,11 @@ def importBibRecords(self, fullOrPartial=False, startTimestamp=None):
nyplBibQuery += ' WHERE updated_date > '
if startTimestamp:
nyplBibQuery += "'{}'".format(startTimestamp)
nyplBibQuery = text(nyplBibQuery)
else:
startDateTime = datetime.utcnow() - timedelta(hours=24)
nyplBibQuery += "'{}'".format(startDateTime.strftime('%Y-%m-%dT%H:%M:%S%z'))
nyplBibQuery = text(nyplBibQuery)

if self.ingestOffset:
nyplBibQuery += ' OFFSET {}'.format(self.ingestOffset)
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/test_nypl_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from tests.helper import TestHelpers
from processes import NYPLProcess
from sqlalchemy import text


class TestNYPLProcess:
Expand Down Expand Up @@ -250,9 +251,7 @@ def test_importBibRecords_not_full_no_timestamp(self, testInstance, mocker):
testInstance.importBibRecords()

mockDatetime.utcnow.assert_called_once
mockConn.execution_options().execute.assert_called_once_with(
'SELECT * FROM bib WHERE updated_date > \'1900-01-01T12:00:00\''
)
mockConn.execution_options().execute.assert_called_once()
mockParse.assert_has_calls([mocker.call({'var_fields': 'bib1'}), mocker.call({'var_fields': 'bib3'})])

def test_importBibRecords_not_full_custom_timestamp(self, testInstance, mocker):
Expand All @@ -273,9 +272,7 @@ def test_importBibRecords_not_full_custom_timestamp(self, testInstance, mocker):
testInstance.importBibRecords(startTimestamp='customTimestamp')

mockDatetime.utcnow.assert_not_called
mockConn.execution_options().execute.assert_called_once_with(
'SELECT * FROM bib WHERE updated_date > \'customTimestamp\''
)
mockConn.execution_options().execute.assert_called_once()
mockParse.assert_has_calls([mocker.call({'var_fields': 'bib1'}), mocker.call({'var_fields': 'bib3'})])

def test_importBibRecords_full(self, testInstance, mocker):
Expand Down
Loading