From 2344516909f1391339805b6d2ec82d4d45864dfa Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 22 Oct 2024 15:00:09 -0700 Subject: [PATCH] add provider tasks tests --- app/aws/s3.py | 6 +++++- tests/app/aws/test_s3.py | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/aws/s3.py b/app/aws/s3.py index 703b917f0..44785cf98 100644 --- a/app/aws/s3.py +++ b/app/aws/s3.py @@ -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 diff --git a/tests/app/aws/test_s3.py b/tests/app/aws/test_s3.py index 6f2b1aff3..8411ae5bb 100644 --- a/tests/app/aws/test_s3.py +++ b/tests/app/aws/test_s3.py @@ -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):