Skip to content

Commit 3149c13

Browse files
aysim319melange396
andauthored
changed logic to throw error (#2156)
* changed logic to throw error * Update nhsn/delphi_nhsn/pull.py Co-authored-by: george <george.haff@gmail.com> * Apply suggestions from code review Co-authored-by: george <george.haff@gmail.com> --------- Co-authored-by: george <george.haff@gmail.com>
1 parent 006c00e commit 3149c13

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

nhsn/delphi_nhsn/pull.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def check_last_updated(socrata_token, dataset_id, logger):
3333
-------
3434
3535
"""
36-
recently_updated_source = True
3736
try:
3837
client = Socrata("data.cdc.gov", socrata_token)
3938
response = client.get_metadata(dataset_id)
@@ -49,10 +48,11 @@ def check_last_updated(socrata_token, dataset_id, logger):
4948
)
5049
else:
5150
logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp)
51+
return recently_updated_source
5252
# pylint: disable=W0703
5353
except Exception as e:
54-
logger.info("error while processing socrata metadata; treating data as stale", error=str(e))
55-
return recently_updated_source
54+
logger.error("error while processing socrata metadata", error=str(e))
55+
raise
5656

5757

5858
def pull_data(socrata_token: str, dataset_id: str, backup_dir: str, logger):

nhsn/tests/test_pull.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,17 @@ def test_check_last_updated(self, mock_socrata, dataset, updatedAt, caplog):
176176
stale_msg = f"{dataset['msg_prefix']}NHSN data is stale; Skipping"
177177
assert stale_msg in caplog.text
178178

179+
180+
181+
@patch("delphi_nhsn.pull.Socrata")
182+
def test_check_last_updated_error(self, mock_socrata, caplog):
183+
mock_client = MagicMock()
184+
# mock metadata missing important field, "viewLastModified":
185+
mock_client.get_metadata.return_value = {"rowsUpdatedAt": time.time()}
186+
mock_socrata.return_value = mock_client
187+
logger = get_structured_logger()
188+
189+
with pytest.raises(KeyError):
190+
check_last_updated("fakesocratatoken", MAIN_DATASET_ID, logger)
191+
assert "error while processing socrata metadata" in caplog.text
192+

0 commit comments

Comments
 (0)