1818 MOCK_ODS_CODE_TO_SUPPLIER
1919)
2020from tests .utils_for_tests .mock_environment_variables import MOCK_ENVIRONMENT_DICT , BucketNames , Sqs
21- from tests .utils_for_tests .values_for_tests import MOCK_CREATED_AT_FORMATTED_STRING , MOCK_EXPIRES_AT , MockFileDetails
21+ from tests .utils_for_tests .values_for_tests import MOCK_CREATED_AT_FORMATTED_STRING , MockFileDetails , \
22+ MOCK_BATCH_FILE_CONTENT , MOCK_FILE_HEADERS , MOCK_EXPIRES_AT
2223
2324# Ensure environment variables are mocked before importing from src files
2425with patch .dict ("os.environ" , MOCK_ENVIRONMENT_DICT ):
@@ -99,7 +100,7 @@ def make_record(file_key: str):
99100 @staticmethod
100101 def make_record_with_message_id (file_key : str , message_id : str ):
101102 """
102- Makes a record which includes a message_id, with the s3 bucket name set to BucketNames.SOURCE and and
103+ Makes a record which includes a message_id, with the s3 bucket name set to BucketNames.SOURCE and
103104 s3 object key set to the file_key.
104105 """
105106 return {"s3" : {"bucket" : {"name" : BucketNames .SOURCE }, "object" : {"key" : file_key }}, "message_id" : message_id }
@@ -184,7 +185,7 @@ def test_lambda_handler_new_file_success_and_first_in_queue(self):
184185 for file_details in test_cases :
185186 with self .subTest (file_details .name ):
186187 # Set up the file in the source bucket
187- s3_client .put_object (Bucket = BucketNames .SOURCE , Key = file_details .file_key )
188+ s3_client .put_object (Bucket = BucketNames .SOURCE , Key = file_details .file_key , Body = MOCK_BATCH_FILE_CONTENT )
188189
189190 with ( # noqa: E999
190191 patch ("file_name_processor.uuid4" , return_value = file_details .message_id ), # noqa: E999
@@ -195,6 +196,29 @@ def test_lambda_handler_new_file_success_and_first_in_queue(self):
195196 self .assert_sqs_message (file_details )
196197 self .assert_no_ack_file (file_details )
197198
199+ def test_lambda_handler_correctly_flags_empty_file (self ):
200+ """
201+ VED-757 Tests that for an empty batch file:
202+ * The file status is updated to 'Not processed - empty file' in the audit table
203+ * The message is not sent to SQS
204+ * The failure inf_ack file is created
205+ """
206+ file_details = MockFileDetails .ravs_rsv_1
207+
208+ s3_client .put_object (Bucket = BucketNames .SOURCE , Key = file_details .file_key , Body = MOCK_FILE_HEADERS )
209+
210+ with ( # noqa: E999
211+ patch ("file_name_processor.uuid4" , return_value = file_details .message_id ), # noqa: E999
212+ ): # noqa: E999
213+ lambda_handler (
214+ self .make_event ([self .make_record_with_message_id (file_details .file_key , file_details .message_id )]),
215+ None ,
216+ )
217+
218+ assert_audit_table_entry (file_details , FileStatus .EMPTY )
219+ self .assert_no_sqs_message ()
220+ self .assert_ack_file_contents (file_details )
221+
198222 def test_lambda_handler_non_root_file (self ):
199223 """
200224 Tests that when the file is not in the root of the source bucket, no action is taken:
@@ -222,7 +246,7 @@ def test_lambda_invalid_file_key_no_other_files_in_queue(self):
222246 * The failure inf_ack file is created
223247 """
224248 invalid_file_key = "InvalidVaccineType_Vaccinations_v5_YGM41_20240708T12130100.csv"
225- s3_client .put_object (Bucket = BucketNames .SOURCE , Key = invalid_file_key )
249+ s3_client .put_object (Bucket = BucketNames .SOURCE , Key = invalid_file_key , Body = MOCK_BATCH_FILE_CONTENT )
226250 file_details = deepcopy (MockFileDetails .ravs_rsv_1 )
227251 file_details .file_key = invalid_file_key
228252 file_details .ack_file_key = self .get_ack_file_key (invalid_file_key )
@@ -259,7 +283,7 @@ def test_lambda_invalid_permissions_other_files_in_queue(self):
259283 * The failure inf_ack file is created
260284 """
261285 file_details = MockFileDetails .ravs_rsv_1
262- s3_client .put_object (Bucket = BucketNames .SOURCE , Key = file_details .file_key )
286+ s3_client .put_object (Bucket = BucketNames .SOURCE , Key = file_details .file_key , Body = MOCK_BATCH_FILE_CONTENT )
263287
264288 queued_file_details = MockFileDetails .ravs_rsv_2
265289 add_entry_to_table (queued_file_details , FileStatus .QUEUED )
0 commit comments