mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 09:12:06 -05:00
fix tests
This commit is contained in:
@@ -209,7 +209,7 @@
|
||||
"filename": "tests/app/aws/test_s3.py",
|
||||
"hashed_secret": "67a74306b06d0c01624fe0d0249a570f4d093747",
|
||||
"is_verified": false,
|
||||
"line_number": 25,
|
||||
"line_number": 28,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
@@ -384,5 +384,5 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"generated_at": "2024-09-26T20:18:10Z"
|
||||
"generated_at": "2024-09-26T20:29:19Z"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from datetime import timedelta
|
||||
import os
|
||||
from os import getenv
|
||||
|
||||
@@ -5,6 +6,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 +16,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,30 +31,31 @@ def single_s3_object_stub(key="foo", last_modified=None):
|
||||
}
|
||||
|
||||
|
||||
# def test_cleanup_old_s3_objects(mocker):
|
||||
# """
|
||||
# Currently we are going to delete s3 objects if they are more than 14 days old,
|
||||
# because we want to delete all jobs older than 7 days, and jobs can be scheduled
|
||||
# three days in advance, and on top of that we want to leave a little cushion for
|
||||
# the time being. This test shows that a 3 day old job ("B") is not deleted,
|
||||
# whereas a 30 day old job ("A") is.
|
||||
# """
|
||||
# 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_remove_csv_object = mocker.patch("app.aws.s3.remove_csv_object")
|
||||
# lastmod30 = aware_utcnow() - timedelta(days=30)
|
||||
# lastmod3 = aware_utcnow() - timedelta(days=3)
|
||||
def test_cleanup_old_s3_objects(mocker):
|
||||
"""
|
||||
Currently we are going to delete s3 objects if they are more than 14 days old,
|
||||
because we want to delete all jobs older than 7 days, and jobs can be scheduled
|
||||
three days in advance, and on top of that we want to leave a little cushion for
|
||||
the time being. This test shows that a 3 day old job ("B") is not deleted,
|
||||
whereas a 30 day old job ("A") is.
|
||||
"""
|
||||
mocker.patch("app.aws.s3.get_bucket_name", return_value="Bucket")
|
||||
|
||||
# mock_s3_client.list_objects_v2.return_value = {
|
||||
# "Contents": [
|
||||
# {"Key": "A", "LastModified": lastmod30},
|
||||
# {"Key": "B", "LastModified": lastmod3},
|
||||
# ]
|
||||
# }
|
||||
# cleanup_old_s3_objects()
|
||||
# mock_s3_client.list_objects_v2.assert_called_with(Bucket="Bucket")
|
||||
# mock_remove_csv_object.assert_called_once_with("A")
|
||||
mock_s3_client = mocker.Mock()
|
||||
mocker.patch("app.aws.s3.get_s3_client", return_value=mock_s3_client)
|
||||
mock_remove_csv_object = mocker.patch("app.aws.s3.remove_csv_object")
|
||||
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},
|
||||
]
|
||||
}
|
||||
cleanup_old_s3_objects()
|
||||
mock_s3_client.list_objects_v2.assert_called_with(Bucket="Bucket")
|
||||
mock_remove_csv_object.assert_called_once_with("A")
|
||||
|
||||
|
||||
def test_get_s3_file_makes_correct_call(notify_api, mocker):
|
||||
|
||||
Reference in New Issue
Block a user