@@ -115,6 +115,7 @@ def test_set_records_succeeded_count_raises(self):
115115 self .mock_logger .error .assert_called_once ()
116116
117117 def test_increment_records_failed_count (self ):
118+ """Checks audit table correctly increments the records_failed count"""
118119 test_message_id = "1234"
119120 audit_table .increment_records_failed_count (test_message_id )
120121 self .mock_dynamodb_client .update_item .assert_called_once_with (
@@ -134,3 +135,30 @@ def test_increment_records_failed_count_raises(self):
134135 audit_table .increment_records_failed_count ("msg1" )
135136 self .assertIn ("fail!" , str (ctx .exception ))
136137 self .mock_logger .error .assert_called_once ()
138+
139+ def test_set_audit_table_ingestion_complete (self ):
140+ """Checks audit table correctly sets ingestion_complete to the requested value"""
141+ test_file_key = "RSV_Vaccinations_v5_X26_20210730T12000000.csv"
142+ test_message_id = "1234"
143+ test_start_time = 1627647000
144+ audit_table .set_audit_table_ingestion_complete (test_file_key , test_message_id , test_start_time )
145+ self .mock_dynamodb_client .update_item .assert_called_once_with (
146+ TableName = AUDIT_TABLE_NAME ,
147+ Key = {AuditTableKeys .MESSAGE_ID : {"S" : test_message_id }},
148+ UpdateExpression = f"SET #{ AuditTableKeys .INGESTION_COMPLETE } = :{ AuditTableKeys .INGESTION_COMPLETE } " ,
149+ ExpressionAttributeNames = {f"#{ AuditTableKeys .INGESTION_COMPLETE } " : AuditTableKeys .INGESTION_COMPLETE },
150+ ExpressionAttributeValues = {f":{ AuditTableKeys .INGESTION_COMPLETE } " : {"S" : "20210730T12100000" }},
151+ ConditionExpression = "attribute_exists(message_id)" ,
152+ ReturnValues = "UPDATED_NEW" ,
153+ )
154+ self .mock_logger .info .assert_called_once ()
155+
156+ def test_set_audit_table_ingestion_complete_throws_exception_with_invalid_id (self ):
157+ test_file_key = "RSV_Vaccinations_v5_X26_20210730T12000000.csv"
158+ test_message_id = "1234"
159+ test_start_time = 1627647000
160+ self .mock_dynamodb_client .update_item .side_effect = Exception ("fail!" )
161+ with self .assertRaises (UnhandledAuditTableError ) as ctx :
162+ audit_table .set_audit_table_ingestion_complete (test_file_key , test_message_id , test_start_time )
163+ self .assertIn ("fail!" , str (ctx .exception ))
164+ self .mock_logger .error .assert_called_once ()
0 commit comments