add provider tasks tests

This commit is contained in:
Kenneth Kehl
2024-10-22 15:00:09 -07:00
parent 5d72b578c7
commit 2344516909
2 changed files with 15 additions and 9 deletions

View File

@@ -70,9 +70,13 @@ def get_s3_resource():
return s3_resource
def _get_bucket_name():
return current_app.config["CSV_UPLOAD_BUCKET"]["bucket"]
def list_s3_objects():
bucket_name = current_app.config["CSV_UPLOAD_BUCKET"]["bucket"]
bucket_name = _get_bucket_name()
s3_client = get_s3_client()
# Our reports only support 7 days, but pull 8 days to avoid
# any edge cases

View File

@@ -61,20 +61,22 @@ def test_cleanup_old_s3_objects(mocker):
def test_list_s3_objects(mocker):
mocker.patch("app.aws.s3._get_bucket_name", return_value="Foo")
mock_s3_client = mocker.Mock()
mocker.patch("app.aws.s3.get_s3_client", return_value=mock_s3_client)
lastmod30 = aware_utcnow() - timedelta(days=30)
lastmod3 = aware_utcnow() - timedelta(days=3)
mock_s3_client.list_objects_v2.return_value = {
"Contents": [
{"Key": "A", "LastModified": lastmod30},
{"Key": "B", "LastModified": lastmod3},
]
}
mock_s3_client.list_objects_v2.side_effect = [
{
"Contents": [
{"Key": "A", "LastModified": lastmod30},
{"Key": "B", "LastModified": lastmod3},
]
}
]
result = list_s3_objects()
assert result == ["B"]
assert list(result) == ["B"]
def test_get_s3_file_makes_correct_call(notify_api, mocker):