1818 generate_expected_ack_content ,
1919 MOCK_MESSAGE_DETAILS ,
2020)
21- from constants import ACK_HEADERS , SOURCE_BUCKET_NAME , ACK_BUCKET_NAME , FILE_NAME_PROC_LAMBDA_NAME
2221
2322from unittest .mock import patch
2423from io import StringIO
2524
2625with patch .dict ("os.environ" , MOCK_ENVIRONMENT_DICT ):
2726 from update_ack_file import obtain_current_ack_content , create_ack_data , update_ack_file
2827
29- s3_client = boto3_client ("s3" , region_name = REGION_NAME )
3028firehose_client = boto3_client ("firehose" , region_name = REGION_NAME )
3129
3230
3331@patch .dict (os .environ , MOCK_ENVIRONMENT_DICT )
3432@mock_s3
3533class TestUpdateAckFile (unittest .TestCase ):
3634 """Tests for the functions in the update_ack_file module."""
37-
3835 def setUp (self ) -> None :
39- GenericSetUp (s3_client )
36+ self .s3_client = boto3_client ("s3" , region_name = REGION_NAME )
37+ GenericSetUp (self .s3_client )
4038
4139 # MOCK SOURCE FILE WITH 100 ROWS TO SIMULATE THE SCENARIO WHERE THE ACK FILE IS NOT FULL.
4240 # TODO: Test all other scenarios.
4341 mock_source_file_with_100_rows = StringIO ("\n " .join (f"Row { i } " for i in range (1 , 101 )))
44- s3_client .put_object (
42+ self . s3_client .put_object (
4543 Bucket = BucketNames .SOURCE ,
4644 Key = f"processing/{ MOCK_MESSAGE_DETAILS .file_key } " ,
4745 Body = mock_source_file_with_100_rows .getvalue (),
@@ -50,7 +48,7 @@ def setUp(self) -> None:
5048 self .mock_logger = self .logger_patcher .start ()
5149
5250 def tearDown (self ) -> None :
53- GenericTearDown (s3_client )
51+ GenericTearDown (self . s3_client )
5452
5553 def validate_ack_file_content (
5654 self , incoming_messages : list [dict ], existing_file_content : str = ValidValues .ack_headers
@@ -59,7 +57,7 @@ def validate_ack_file_content(
5957 Obtains the ack file content and ensures that it matches the expected content (expected content is based
6058 on the incoming messages).
6159 """
62- actual_ack_file_content = obtain_current_ack_file_content ()
60+ actual_ack_file_content = obtain_current_ack_file_content (self . s3_client )
6361 expected_ack_file_content = generate_expected_ack_content (incoming_messages , existing_file_content )
6462 self .assertEqual (expected_ack_file_content , actual_ack_file_content )
6563
@@ -114,17 +112,17 @@ def test_update_ack_file(self):
114112 ack_data_rows = test_case ["input_rows" ],
115113 )
116114
117- actual_ack_file_content = obtain_current_ack_file_content ()
115+ actual_ack_file_content = obtain_current_ack_file_content (self . s3_client )
118116 expected_ack_file_content = ValidValues .ack_headers + "\n " .join (test_case ["expected_rows" ]) + "\n "
119117 self .assertEqual (expected_ack_file_content , actual_ack_file_content )
120118
121- s3_client .delete_object (Bucket = BucketNames .DESTINATION , Key = MOCK_MESSAGE_DETAILS .temp_ack_file_key )
119+ self . s3_client .delete_object (Bucket = BucketNames .DESTINATION , Key = MOCK_MESSAGE_DETAILS .temp_ack_file_key )
122120
123121 def test_update_ack_file_existing (self ):
124122 """Test that update_ack_file correctly updates the ack file when there was an existing ack file"""
125123 # Mock existing content in the ack file
126124 existing_content = generate_sample_existing_ack_content ()
127- setup_existing_ack_file (MOCK_MESSAGE_DETAILS .temp_ack_file_key , existing_content )
125+ setup_existing_ack_file (MOCK_MESSAGE_DETAILS .temp_ack_file_key , existing_content , self . s3_client )
128126
129127 ack_data_rows = [ValidValues .ack_data_success_dict , ValidValues .ack_data_failure_dict ]
130128 update_ack_file (
@@ -135,7 +133,7 @@ def test_update_ack_file_existing(self):
135133 ack_data_rows = ack_data_rows ,
136134 )
137135
138- actual_ack_file_content = obtain_current_ack_file_content ()
136+ actual_ack_file_content = obtain_current_ack_file_content (self . s3_client )
139137 expected_rows = [
140138 generate_expected_ack_file_row (success = True , imms_id = DefaultValues .imms_id ),
141139 generate_expected_ack_file_row (success = False , imms_id = "" , diagnostics = "DIAGNOSTICS" ),
@@ -205,7 +203,7 @@ def test_obtain_current_ack_content_file_no_existing(self):
205203 def test_obtain_current_ack_content_file_exists (self ):
206204 """Test that the existing ack file content is retrieved and new rows are added."""
207205 existing_content = generate_sample_existing_ack_content ()
208- setup_existing_ack_file (MOCK_MESSAGE_DETAILS .temp_ack_file_key , existing_content )
206+ setup_existing_ack_file (MOCK_MESSAGE_DETAILS .temp_ack_file_key , existing_content , self . s3_client )
209207 result = obtain_current_ack_content (MOCK_MESSAGE_DETAILS .temp_ack_file_key )
210208 self .assertEqual (result .getvalue (), existing_content )
211209
0 commit comments