From 5d72b578c726099a6cbfcb5b86dffa211b7327ee Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 22 Oct 2024 14:33:17 -0700 Subject: [PATCH] add provider tasks tests --- .ds.baseline | 4 ++-- tests/app/aws/test_s3.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.ds.baseline b/.ds.baseline index 1c279e018..544afe311 100644 --- a/.ds.baseline +++ b/.ds.baseline @@ -209,7 +209,7 @@ "filename": "tests/app/aws/test_s3.py", "hashed_secret": "67a74306b06d0c01624fe0d0249a570f4d093747", "is_verified": false, - "line_number": 29, + "line_number": 30, "is_secret": false } ], @@ -384,5 +384,5 @@ } ] }, - "generated_at": "2024-09-27T16:42:53Z" + "generated_at": "2024-10-22T21:33:13Z" } diff --git a/tests/app/aws/test_s3.py b/tests/app/aws/test_s3.py index e468c4426..6f2b1aff3 100644 --- a/tests/app/aws/test_s3.py +++ b/tests/app/aws/test_s3.py @@ -13,6 +13,7 @@ from app.aws.s3 import ( get_personalisation_from_s3, get_phone_number_from_s3, get_s3_file, + list_s3_objects, remove_csv_object, remove_s3_object, ) @@ -59,6 +60,23 @@ def test_cleanup_old_s3_objects(mocker): mock_remove_csv_object.assert_called_once_with("A") +def test_list_s3_objects(mocker): + + 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}, + ] + } + result = list_s3_objects() + assert result == ["B"] + + def test_get_s3_file_makes_correct_call(notify_api, mocker): get_s3_mock = mocker.patch("app.aws.s3.get_s3_object") get_s3_file(