Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 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,12 @@ 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.info("error while processing socrata metadata", error=str(e))
raise e



def pull_data(socrata_token: str, dataset_id: str, backup_dir: str, logger):
Expand Down
15 changes: 15 additions & 0 deletions nhsn/tests/test_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,18 @@ 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")
@pytest.mark.parametrize('dataset', DATASETS, ids=["data", "prelim_data"])
def test_check_last_updated_error(self, mock_socrata, dataset, caplog):
mock_client = MagicMock()
mock_socrata.return_value = mock_client
updatedAt = time.time()
mock_client.get_metadata.return_value = {"rowsUpdatedAt": updatedAt }
logger = get_structured_logger()

with pytest.raises(KeyError):
check_last_updated(mock_client, dataset["id"], logger)
assert "error while processing socrata metadata" in caplog.text

Loading