Skip to content

Commit aa8035f

Browse files
committed
Update Tests
1 parent 1580a4b commit aa8035f

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

delta_backend/src/common/mappings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
Define enums for event names, operations, and action flags.
2+
Enums for event names, operations, and action flags.
33
44
# case eventName operation actionFlag
55
----------------- --------- --------- ----------
66
create INSERT CREATE NEW
77
update MODIFY UPDATE UPDATE
8-
logically delete MODIFY DELETE DELETE
9-
physically delete REMOVE REMOVE N/A
8+
logical delete MODIFY DELETE DELETE
9+
physical delete REMOVE REMOVE N/A
1010
"""
1111

1212
class EventName():

delta_backend/tests/test_convert_to_flat_json.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ def assert_dynamodb_record(self, operation_flag, action_flag, items, expected_va
126126
self.assertIsInstance(imms_data, dict)
127127
self.assertGreater(len(imms_data), 0)
128128

129-
for key, expected_value in expected_values.items():
130-
self.assertIn(key, filtered_items[0], f"{key} is missing")
131-
if (filtered_items[0][key] != expected_value):
132-
print (f"{key} mismatch {filtered_items[0][key]} != {expected_value}")
133-
134129
# Check Imms JSON structure matches exactly
135130
self.assertEqual(imms_data, expected_imms, "Imms data does not match expected JSON structure")
136131

delta_backend/tests/test_delta.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,31 @@ def test_handler_failure(self, mock_boto_resource):
125125
@patch("boto3.resource")
126126
def test_handler_success_update(self, mock_boto_resource):
127127
# Arrange
128+
mock_table = self.setup_mock_dynamodb(mock_boto_resource)
128129
self.setup_mock_dynamodb(mock_boto_resource)
129-
event = ValuesForTests.get_event(event_name=EventName.UPDATE, operation=Operation.UPDATE)
130+
imms_id = "test-update-imms-id"
131+
event = ValuesForTests.get_event(event_name=EventName.UPDATE, operation=Operation.UPDATE, imms_id=imms_id)
130132

131133
# Act
132134
result = handler(event, self.context)
133135

134136
# Assert
135137
self.assertTrue(result)
138+
mock_table.put_item.assert_called()
139+
self.mock_firehose_logger.send_log.assert_called() # check logged
140+
put_item_call_args = mock_table.put_item.call_args # check data written to DynamoDB
141+
put_item_data = put_item_call_args.kwargs["Item"]
142+
self.assertIn("Imms", put_item_data)
143+
self.assertEqual(put_item_data["Imms"]["ACTION_FLAG"], ActionFlag.UPDATE)
144+
self.assertEqual(put_item_data["Operation"], Operation.UPDATE)
145+
self.assertEqual(put_item_data["ImmsID"], imms_id)
136146

137147
@patch("boto3.resource")
138-
def test_handler_success_remove(self, mock_boto_resource):
148+
def test_handler_success_delete_physical(self, mock_boto_resource):
139149
# Arrange
140150
mock_table = self.setup_mock_dynamodb(mock_boto_resource)
141151
imms_id = "test-update-imms-id"
142-
event = ValuesForTests.get_event(event_name=EventName.UPDATE, operation=Operation.UPDATE, imms_id=imms_id)
152+
event = ValuesForTests.get_event(event_name=EventName.DELETE_PHYSICAL, operation=Operation.DELETE_PHYSICAL, imms_id=imms_id)
143153

144154
# Act
145155
result = handler(event, self.context)
@@ -151,8 +161,30 @@ def test_handler_success_remove(self, mock_boto_resource):
151161
put_item_call_args = mock_table.put_item.call_args # check data written to DynamoDB
152162
put_item_data = put_item_call_args.kwargs["Item"]
153163
self.assertIn("Imms", put_item_data)
154-
self.assertEqual(put_item_data["Imms"]["ACTION_FLAG"], ActionFlag.UPDATE)
155-
self.assertEqual(put_item_data["Operation"], Operation.UPDATE)
164+
self.assertEqual(put_item_data["Operation"], Operation.DELETE_PHYSICAL)
165+
self.assertEqual(put_item_data["ImmsID"], imms_id)
166+
self.assertEqual(put_item_data["Imms"], "") # check imms has been blanked out
167+
168+
@patch("boto3.resource")
169+
def test_handler_success_delete_logical(self, mock_boto_resource):
170+
# Arrange
171+
mock_table = self.setup_mock_dynamodb(mock_boto_resource)
172+
imms_id = "test-update-imms-id"
173+
event = ValuesForTests.get_event(event_name=EventName.UPDATE,
174+
operation=Operation.DELETE_LOGICAL,
175+
imms_id=imms_id)
176+
# Act
177+
result = handler(event, self.context)
178+
179+
# Assert
180+
self.assertTrue(result)
181+
mock_table.put_item.assert_called()
182+
self.mock_firehose_logger.send_log.assert_called() # check logged
183+
put_item_call_args = mock_table.put_item.call_args # check data written to DynamoDB
184+
put_item_data = put_item_call_args.kwargs["Item"]
185+
self.assertIn("Imms", put_item_data)
186+
self.assertEqual(put_item_data["Imms"]["ACTION_FLAG"], ActionFlag.DELETE_LOGICAL)
187+
self.assertEqual(put_item_data["Operation"], Operation.DELETE_LOGICAL)
156188
self.assertEqual(put_item_data["ImmsID"], imms_id)
157189

158190
@patch("boto3.resource")
@@ -195,7 +227,7 @@ def test_handler_exception_intrusion_check_false(self, mocked_intrusion, mock_bo
195227

196228
self.assertFalse(response)
197229

198-
@patch("delta.logger.info") # Mock logging
230+
@patch("delta.logger.info")
199231
def test_dps_record_skipped(self, mock_logger_info):
200232
event = ValuesForTests.get_event(supplier="DPSFULL")
201233
context = {}
@@ -245,7 +277,6 @@ def test_send_message_multi_records_diverse(self, mock_boto_resource):
245277
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "id3", ActionFlag.DELETE_LOGICAL),
246278
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "id4"),
247279
]
248-
# Generate the event using ValuesForTests.get_multi_record_event
249280
event = ValuesForTests.get_multi_record_event(records_config)
250281

251282
# Act
@@ -266,7 +297,6 @@ def test_send_message_multi_create(self, mock_boto_resource):
266297
RecordConfig(EventName.CREATE, Operation.CREATE, "create-id2", ActionFlag.CREATE),
267298
RecordConfig(EventName.CREATE, Operation.CREATE, "create-id3", ActionFlag.CREATE)
268299
]
269-
# Generate the event using ValuesForTests.get_multi_record_event
270300
event = ValuesForTests.get_multi_record_event(records_config)
271301

272302
# Act
@@ -288,7 +318,6 @@ def test_send_message_multi_update(self, mock_boto_resource):
288318
RecordConfig(EventName.UPDATE, Operation.UPDATE, "update-id2", ActionFlag.UPDATE),
289319
RecordConfig(EventName.UPDATE, Operation.UPDATE, "update-id3", ActionFlag.UPDATE)
290320
]
291-
# Generate the event using ValuesForTests.get_multi_record_event
292321
event = ValuesForTests.get_multi_record_event(records_config)
293322

294323
# Act
@@ -305,11 +334,10 @@ def test_send_message_multi_logical_delete(self, mock_boto_resource):
305334
mock_table = self.setup_mock_dynamodb(mock_boto_resource)
306335

307336
records_config = [
308-
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "update-id1", ActionFlag.DELETE_LOGICAL),
309-
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "update-id2", ActionFlag.DELETE_LOGICAL),
310-
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "update-id3", ActionFlag.DELETE_LOGICAL)
337+
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "delete-id1", ActionFlag.DELETE_LOGICAL),
338+
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "delete-id2", ActionFlag.DELETE_LOGICAL),
339+
RecordConfig(EventName.DELETE_LOGICAL, Operation.DELETE_LOGICAL, "delete-id3", ActionFlag.DELETE_LOGICAL)
311340
]
312-
# Generate the event using ValuesForTests.get_multi_record_event
313341
event = ValuesForTests.get_multi_record_event(records_config)
314342

315343
# Act
@@ -326,11 +354,10 @@ def test_send_message_multi_physical_delete(self, mock_boto_resource):
326354
mock_table = self.setup_mock_dynamodb(mock_boto_resource)
327355

328356
records_config = [
329-
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "update-id1"),
330-
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "update-id2"),
331-
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "update-id3")
357+
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "remove-id1"),
358+
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "remove-id2"),
359+
RecordConfig(EventName.DELETE_PHYSICAL, Operation.DELETE_PHYSICAL, "remove-id3")
332360
]
333-
# Generate the event using ValuesForTests.get_multi_record_event
334361
event = ValuesForTests.get_multi_record_event(records_config)
335362

336363
# Act

0 commit comments

Comments
 (0)