Skip to content
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
6 changes: 3 additions & 3 deletions nhsn/delphi_nhsn/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def check_last_updated(socrata_token, dataset_id, logger):
-------

"""
recently_updated_source = True
try:
client = Socrata("data.cdc.gov", socrata_token)
response = client.get_metadata(dataset_id)
Expand All @@ -49,10 +48,11 @@ def check_last_updated(socrata_token, dataset_id, logger):
)
else:
logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp)
return recently_updated_source
# pylint: disable=W0703
except Exception as e:
logger.info("error while processing socrata metadata; treating data as stale", error=str(e))
return recently_updated_source
logger.error("error while processing socrata metadata", error=str(e))
raise


def pull_data(socrata_token: str, dataset_id: str, backup_dir: str, logger):
Expand Down
14 changes: 14 additions & 0 deletions nhsn/tests/test_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,17 @@ def test_check_last_updated(self, mock_socrata, dataset, updatedAt, caplog):
stale_msg = f"{dataset['msg_prefix']}NHSN data is stale; Skipping"
assert stale_msg in caplog.text



@patch("delphi_nhsn.pull.Socrata")
def test_check_last_updated_error(self, mock_socrata, caplog):
mock_client = MagicMock()
# mock metadata missing important field, "viewLastModified":
mock_client.get_metadata.return_value = {"rowsUpdatedAt": time.time()}
mock_socrata.return_value = mock_client
logger = get_structured_logger()

with pytest.raises(KeyError):
check_last_updated("fakesocratatoken", MAIN_DATASET_ID, logger)
assert "error while processing socrata metadata" in caplog.text