22
33from unittest import TestCase
44from unittest .mock import patch
5- from datetime import datetime , timezone
5+ from datetime import datetime , timedelta , timezone
66from moto import mock_s3
77from boto3 import client as boto3_client
88
1111
1212# Ensure environment variables are mocked before importing from src files
1313with patch .dict ("os.environ" , MOCK_ENVIRONMENT_DICT ):
14+ from constants import AUDIT_TABLE_TTL_DAYS
1415 from clients import REGION_NAME
1516 from utils_for_filenameprocessor import (
16- get_created_at_formatted_string ,
17+ get_creation_and_expiry_times ,
1718 move_file
1819 )
1920
@@ -32,20 +33,24 @@ def tearDown(self):
3233 """Tear down the s3 buckets"""
3334 GenericTearDown (s3_client )
3435
35- def test_get_created_at_formatted_string (self ):
36- """Test that get_created_at_formatted_string can correctly get the created_at_formatted_string"""
36+ def test_get_creation_and_expiry_times (self ):
37+ """Test that get_creation_and_expiry_times can correctly get the created_at_formatted_string"""
3738 bucket_name = BucketNames .SOURCE
3839 file_key = "test_file_key"
3940
4041 s3_client .put_object (Bucket = bucket_name , Key = file_key )
4142
42- mock_last_modified = {"LastModified" : datetime (2024 , 1 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )}
43- expected_result = "20240101T12000000"
43+ mock_last_modified_created_at = datetime (2024 , 1 , 1 , 12 , 0 , 0 , tzinfo = timezone .utc )
44+ mock_last_modified = {"LastModified" : mock_last_modified_created_at }
45+ expected_result_created_at = "20240101T12000000"
46+ expected_expiry_datetime = mock_last_modified_created_at + timedelta (days = int (AUDIT_TABLE_TTL_DAYS ))
47+ expected_result_expires_at = int (expected_expiry_datetime .timestamp ())
4448
4549 with patch ("utils_for_filenameprocessor.s3_client.get_object" , return_value = mock_last_modified ):
46- created_at_formatted_string = get_created_at_formatted_string (bucket_name , file_key )
50+ created_at_formatted_string , expires_at = get_creation_and_expiry_times (bucket_name , file_key )
4751
48- self .assertEqual (created_at_formatted_string , expected_result )
52+ self .assertEqual (created_at_formatted_string , expected_result_created_at )
53+ self .assertEqual (expires_at , expected_result_expires_at )
4954
5055 def test_move_file (self ):
5156 """Tests that move_file correctly moves a file from one location to another within a single S3 bucket"""
0 commit comments