-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_utils_for_filenameprocessor.py
More file actions
52 lines (39 loc) · 1.85 KB
/
test_utils_for_filenameprocessor.py
File metadata and controls
52 lines (39 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Tests for utils_for_filenameprocessor functions"""
from datetime import UTC, datetime, timedelta
from unittest import TestCase
from unittest.mock import patch
from moto import mock_aws
from utils_for_tests.mock_environment_variables import (
MOCK_ENVIRONMENT_DICT,
)
from utils_for_tests.utils_for_filenameprocessor_tests import (
GenericSetUp,
GenericTearDown,
create_boto3_clients,
)
# Ensure environment variables are mocked before importing from src files
with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT):
from constants import AUDIT_TABLE_TTL_DAYS
from utils_for_filenameprocessor import get_creation_and_expiry_times
s3_client = None
@mock_aws
class TestUtilsForFilenameprocessor(TestCase):
"""Tests for utils_for_filenameprocessor functions"""
def setUp(self):
"""Set up the s3 buckets"""
global s3_client
(s3_client,) = create_boto3_clients("s3")
GenericSetUp(s3_client)
def tearDown(self):
"""Tear down the s3 buckets"""
GenericTearDown(s3_client)
def test_get_creation_and_expiry_times(self):
"""Test that get_creation_and_expiry_times can correctly get the created_at_formatted_string"""
mock_last_modified_created_at = datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC)
mock_last_modified_s3_response = {"LastModified": mock_last_modified_created_at}
expected_result_created_at = "20240101T12000000"
expected_expiry_datetime = mock_last_modified_created_at + timedelta(days=int(AUDIT_TABLE_TTL_DAYS))
expected_result_expires_at = int(expected_expiry_datetime.timestamp())
created_at_formatted_string, expires_at = get_creation_and_expiry_times(mock_last_modified_s3_response)
self.assertEqual(created_at_formatted_string, expected_result_created_at)
self.assertEqual(expires_at, expected_result_expires_at)