@@ -189,53 +189,22 @@ def test_lambda_handler_main(self):
189189 {
190190 "description" : "Multiple messages: all with diagnostics (failure messages)" ,
191191 "messages" : [
192- {
193- "row_id" : "row^1" ,
194- "diagnostics" : DiagnosticsDictionaries .UNIQUE_ID_MISSING
195- },
196- {
197- "row_id" : "row^2" ,
198- "diagnostics" : DiagnosticsDictionaries .NO_PERMISSIONS
199- },
200- {
201- "row_id" : "row^3" ,
202- "diagnostics" : DiagnosticsDictionaries .RESOURCE_NOT_FOUND_ERROR
203- },
192+ {"row_id" : "row^1" , "diagnostics" : DiagnosticsDictionaries .UNIQUE_ID_MISSING },
193+ {"row_id" : "row^2" , "diagnostics" : DiagnosticsDictionaries .NO_PERMISSIONS },
194+ {"row_id" : "row^3" , "diagnostics" : DiagnosticsDictionaries .RESOURCE_NOT_FOUND_ERROR },
204195 ],
205196 },
206197 {
207198 "description" : "Multiple messages: mixture of success and failure messages" ,
208199 "messages" : [
209- {
210- "row_id" : "row^1" ,
211- "imms_id" : "TEST_IMMS_ID"
212- },
213- {
214- "row_id" : "row^2" ,
215- "diagnostics" : DiagnosticsDictionaries .UNIQUE_ID_MISSING
216- },
217- {
218- "row_id" : "row^3" ,
219- "diagnostics" : DiagnosticsDictionaries .CUSTOM_VALIDATION_ERROR
220- },
221- {
222- "row_id" : "row^4"
223- },
224- {
225- "row_id" : "row^5" ,
226- "diagnostics" : DiagnosticsDictionaries .CUSTOM_VALIDATION_ERROR
227- },
228- {
229- "row_id" : "row^6" ,
230- "diagnostics" : DiagnosticsDictionaries .CUSTOM_VALIDATION_ERROR
231- },
232- {
233- "row_id" : "row^7"
234- },
235- {
236- "row_id" : "row^8" ,
237- "diagnostics" : DiagnosticsDictionaries .IDENTIFIER_DUPLICATION_ERROR
238- },
200+ {"row_id" : "row^1" , "imms_id" : "TEST_IMMS_ID" },
201+ {"row_id" : "row^2" , "diagnostics" : DiagnosticsDictionaries .UNIQUE_ID_MISSING },
202+ {"row_id" : "row^3" , "diagnostics" : DiagnosticsDictionaries .CUSTOM_VALIDATION_ERROR },
203+ {"row_id" : "row^4" },
204+ {"row_id" : "row^5" , "diagnostics" : DiagnosticsDictionaries .CUSTOM_VALIDATION_ERROR },
205+ {"row_id" : "row^6" , "diagnostics" : DiagnosticsDictionaries .CUSTOM_VALIDATION_ERROR },
206+ {"row_id" : "row^7" },
207+ {"row_id" : "row^8" , "diagnostics" : DiagnosticsDictionaries .IDENTIFIER_DUPLICATION_ERROR },
239208 ],
240209 },
241210 {
@@ -244,12 +213,7 @@ def test_lambda_handler_main(self):
244213 },
245214 {
246215 "description" : "Single row: malformed diagnostics info from forwarder" ,
247- "messages" : [
248- {
249- "row_id" : "row^1" ,
250- "diagnostics" : "SHOULD BE A DICTIONARY, NOT A STRING"
251- }
252- ],
216+ "messages" : [{"row_id" : "row^1" , "diagnostics" : "SHOULD BE A DICTIONARY, NOT A STRING" }],
253217 },
254218 ]
255219
@@ -278,60 +242,49 @@ def test_lambda_handler_updates_ack_file_but_does_not_mark_complete_when_records
278242 # Original source file had 100 records
279243 add_audit_entry_to_table (self .dynamodb_client , mock_batch_message_id , record_count = 100 )
280244 array_of_success_messages = [
281- {** BASE_SUCCESS_MESSAGE , "row_id" : f"{ mock_batch_message_id } ^{ i } " , "imms_id" : f"imms_{ i } " ,
282- "local_id" : f"local^{ i } " }
245+ {
246+ ** BASE_SUCCESS_MESSAGE ,
247+ "row_id" : f"{ mock_batch_message_id } ^{ i } " ,
248+ "imms_id" : f"imms_{ i } " ,
249+ "local_id" : f"local^{ i } " ,
250+ }
283251 for i in range (1 , 4 )
284252 ]
285- test_event = {
286- "Records" : [
287- {"body" : json .dumps (array_of_success_messages )}
288- ]
289- }
253+ test_event = {"Records" : [{"body" : json .dumps (array_of_success_messages )}]}
290254
291255 response = lambda_handler (event = test_event , context = {})
292256
293257 self .assertEqual (response , EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS )
294258 validate_ack_file_content (
295259 self .s3_client ,
296- [
297- * array_of_success_messages
298- ],
260+ [* array_of_success_messages ],
299261 existing_file_content = ValidValues .ack_headers ,
300262 )
301263 self .assert_ack_and_source_file_locations_correct (
302264 MOCK_MESSAGE_DETAILS .file_key ,
303265 MOCK_MESSAGE_DETAILS .temp_ack_file_key ,
304266 MOCK_MESSAGE_DETAILS .archive_ack_file_key ,
305- is_complete = False
267+ is_complete = False ,
306268 )
307269 self .assert_audit_entry_status_equals (mock_batch_message_id , "Preprocessed" )
308270
309271 @patch ("utils_for_ack_lambda.get_record_count_by_message_id" , return_value = 500 )
310- def test_lambda_handler_uses_message_id_to_record_count_cache_to_reduce_ddb_calls (
311- self ,
312- mock_get_record_count : Mock
313- ):
272+ def test_lambda_handler_uses_message_id_to_record_count_cache_to_reduce_ddb_calls (self , mock_get_record_count : Mock ):
314273 """The DynamoDB Audit table is used to store the total record count for each source file. To reduce calls each
315274 time - this test checks that we cache the value as this lambda is called many times for large files"""
316275 mock_batch_message_id = "622cdeea-461e-4a83-acb5-7871d47ddbcd"
317276
318277 # Original source file had 500 records
319278 add_audit_entry_to_table (self .dynamodb_client , mock_batch_message_id , record_count = 500 )
320279
321- message_one = [{** BASE_SUCCESS_MESSAGE , "row_id" : f"{ mock_batch_message_id } ^1" , "imms_id" : "imms_1" ,
322- "local_id" : "local^1" }]
323- message_two = [{** BASE_SUCCESS_MESSAGE , "row_id" : f"{ mock_batch_message_id } ^2" , "imms_id" : "imms_2" ,
324- "local_id" : "local^2" }]
325- test_event_one = {
326- "Records" : [
327- {"body" : json .dumps (message_one )}
328- ]
329- }
330- test_event_two = {
331- "Records" : [
332- {"body" : json .dumps (message_two )}
333- ]
334- }
280+ message_one = [
281+ {** BASE_SUCCESS_MESSAGE , "row_id" : f"{ mock_batch_message_id } ^1" , "imms_id" : "imms_1" , "local_id" : "local^1" }
282+ ]
283+ message_two = [
284+ {** BASE_SUCCESS_MESSAGE , "row_id" : f"{ mock_batch_message_id } ^2" , "imms_id" : "imms_2" , "local_id" : "local^2" }
285+ ]
286+ test_event_one = {"Records" : [{"body" : json .dumps (message_one )}]}
287+ test_event_two = {"Records" : [{"body" : json .dumps (message_two )}]}
335288
336289 response = lambda_handler (event = test_event_one , context = {})
337290 self .assertEqual (response , EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS )
@@ -342,16 +295,14 @@ def test_lambda_handler_uses_message_id_to_record_count_cache_to_reduce_ddb_call
342295 mock_get_record_count .assert_called_once_with (mock_batch_message_id )
343296 validate_ack_file_content (
344297 self .s3_client ,
345- [
346- * message_one , * message_two
347- ],
298+ [* message_one , * message_two ],
348299 existing_file_content = ValidValues .ack_headers ,
349300 )
350301 self .assert_ack_and_source_file_locations_correct (
351302 MOCK_MESSAGE_DETAILS .file_key ,
352303 MOCK_MESSAGE_DETAILS .temp_ack_file_key ,
353304 MOCK_MESSAGE_DETAILS .archive_ack_file_key ,
354- is_complete = False
305+ is_complete = False ,
355306 )
356307 self .assertEqual (_BATCH_EVENT_ID_TO_RECORD_COUNT_MAP [mock_batch_message_id ], 500 )
357308 self .assert_audit_entry_status_equals (mock_batch_message_id , "Preprocessed" )
@@ -379,32 +330,27 @@ def test_lambda_handler_updates_ack_file_and_marks_complete_when_all_records_pro
379330 )
380331
381332 array_of_success_messages = [
382- {** BASE_SUCCESS_MESSAGE , "row_id" : f"{ mock_batch_message_id } ^{ i } " , "imms_id" : f"imms_{ i } " ,
383- "local_id" : f"local^{ i } " }
333+ {
334+ ** BASE_SUCCESS_MESSAGE ,
335+ "row_id" : f"{ mock_batch_message_id } ^{ i } " ,
336+ "imms_id" : f"imms_{ i } " ,
337+ "local_id" : f"local^{ i } " ,
338+ }
384339 for i in range (50 , 101 )
385340 ]
386- test_event = {
387- "Records" : [
388- {"body" : json .dumps (array_of_success_messages )}
389- ]
390- }
341+ test_event = {"Records" : [{"body" : json .dumps (array_of_success_messages )}]}
391342
392343 response = lambda_handler (event = test_event , context = {})
393344
394345 self .assertEqual (response , EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS )
395346 validate_ack_file_content (
396- self .s3_client ,
397- [
398- * array_of_success_messages
399- ],
400- existing_file_content = existing_ack_content ,
401- is_complete = True
347+ self .s3_client , [* array_of_success_messages ], existing_file_content = existing_ack_content , is_complete = True
402348 )
403349 self .assert_ack_and_source_file_locations_correct (
404350 MOCK_MESSAGE_DETAILS .file_key ,
405351 MOCK_MESSAGE_DETAILS .temp_ack_file_key ,
406352 MOCK_MESSAGE_DETAILS .archive_ack_file_key ,
407- is_complete = True
353+ is_complete = True ,
408354 )
409355 self .assert_audit_entry_status_equals (mock_batch_message_id , "Processed" )
410356
0 commit comments