This commit is contained in:
Kenneth Kehl
2024-09-10 11:12:43 -07:00
parent e236ed6404
commit 4e9e014a0c
3 changed files with 23 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import pytest
from botocore.exceptions import ClientError
from app.aws.s3 import (
cleanup_old_s3_objects,
file_exists,
get_job_from_s3,
get_personalisation_from_s3,
@@ -14,6 +15,7 @@ from app.aws.s3 import (
remove_s3_object,
)
from app.utils import utc_now
from notifications_utils import aware_utcnow
default_access_key = getenv("CSV_AWS_ACCESS_KEY_ID")
default_secret_key = getenv("CSV_AWS_SECRET_ACCESS_KEY")
@@ -28,6 +30,18 @@ def single_s3_object_stub(key="foo", last_modified=None):
}
def test_cleanup_old_s3_objects(mocker):
mocker.patch("app.aws.s3.get_bucket_name", return_value="Bucket")
mock_s3_client = mocker.Mock()
mocker.patch("app.aws.s3.get_s3_client", return_value=mock_s3_client)
mock_s3_client.list_objects_v2.return_value = {
"Contents": [{"Key": "A", "LastModified": aware_utcnow()}]
}
cleanup_old_s3_objects()
mock_s3_client.list_objects_v2.assert_called_with(Bucket="Bucket")
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(