SIENTIAPDE-1110
Enhance Gates and Redis activities by adding metadata parameter to apply_aggregation and notification methods. Refactor notification handling to use send_notification for improved consistency. Update tests to reflect changes in notification method calls and ensure proper functionality with new metadata integration.
This commit is contained in:
@@ -11,7 +11,9 @@ def gates_fixture():
|
||||
"""Fixture to create a Gates instance with mocked dependencies."""
|
||||
logger = Mock()
|
||||
notification_handler = MagicMock()
|
||||
return Gates(logger=logger, notification_handler=notification_handler)
|
||||
gates = Gates(logger=logger, notification_handler=notification_handler)
|
||||
gates.send_notification = MagicMock()
|
||||
return gates
|
||||
|
||||
|
||||
metadata = {
|
||||
@@ -51,7 +53,7 @@ async def test_data_quality_gate_with_null_values_filter_discard(gates_fixture):
|
||||
# Verify
|
||||
assert len(result['tag']) == 2
|
||||
assert 'tag2' not in result['tag']
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_called_once()
|
||||
gates_fixture.send_notification.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -84,7 +86,7 @@ async def test_data_quality_gate_with_out_of_bounds_filter_keep(gates_fixture):
|
||||
|
||||
# Verify data is kept but notification is sent
|
||||
assert len(result['tag']) == 3 # All rows kept
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_called_once()
|
||||
gates_fixture.send_notification.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -117,7 +119,7 @@ async def test_data_quality_gate_with_multiple_filters(gates_fixture):
|
||||
assert result == {'tag': {0: 'tag1', 3: 'tag4'}, 'name': {0: 'tag1', 3: 'tag4'}, 'value': {
|
||||
0: 1.0, 3: 4.0}, 'timestamp': {0: '2023-01-01', 3: '2023-01-04'}}
|
||||
# Should be called twice (once for each filter)
|
||||
assert gates_fixture.notification_handler.build_and_send_notification.call_count == 2
|
||||
assert gates_fixture.send_notification.call_count == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -184,8 +186,8 @@ async def test_data_quality_gate_with_filter_error(gates_fixture):
|
||||
|
||||
# Verify error notification is sent and data is unchanged
|
||||
assert len(result['tag']) == 1
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_called_once()
|
||||
call_args = gates_fixture.notification_handler.build_and_send_notification.call_args[1]
|
||||
gates_fixture.send_notification.assert_called_once()
|
||||
call_args = gates_fixture.send_notification.call_args[1]
|
||||
assert call_args['notification_id'] == "DATA_QUALITY_GATE_ISSUES"
|
||||
assert call_args['level'] == NotificationLevel.ERROR
|
||||
assert "Filter error" in call_args['message']
|
||||
@@ -214,7 +216,7 @@ async def test_data_quality_gate_with_empty_data(gates_fixture):
|
||||
|
||||
# Verify empty result and no notifications
|
||||
assert len(result['tag']) == 0
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_not_called()
|
||||
gates_fixture.send_notification.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -240,7 +242,7 @@ async def test_data_quality_gate_with_no_filters(gates_fixture):
|
||||
|
||||
# Verify data is unchanged and no notifications
|
||||
assert len(result['tag']) == 1
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_not_called()
|
||||
gates_fixture.send_notification.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -265,14 +267,15 @@ async def test_data_quality_gate_with_no_filters(gates_fixture):
|
||||
)
|
||||
def test_apply_aggregation(gates_fixture, group_data, aggr_function, expected_result):
|
||||
"""Test apply_aggregation method with various scenarios."""
|
||||
result = gates_fixture.apply_aggregation(group_data, aggr_function)
|
||||
result = gates_fixture.apply_aggregation(
|
||||
group_data, aggr_function, metadata)
|
||||
assert result == expected_result
|
||||
|
||||
# Check notification was sent for invalid function
|
||||
if aggr_function == 'invalid':
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_called_once()
|
||||
gates_fixture.send_notification.assert_called_once()
|
||||
else:
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_not_called()
|
||||
gates_fixture.send_notification.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -308,7 +311,7 @@ async def test_aggregate_data(gates_fixture):
|
||||
|
||||
# Verify
|
||||
assert result == expected_result
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_not_called()
|
||||
gates_fixture.send_notification.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -342,7 +345,7 @@ async def test_aggregate_data_with_continue(gates_fixture):
|
||||
|
||||
# Verify
|
||||
assert result == expected_result
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_not_called()
|
||||
gates_fixture.send_notification.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -373,7 +376,8 @@ async def test_aggregate_data_raise_exception(gates_fixture):
|
||||
await gates_fixture.aggregate_data(input_data)
|
||||
except Exception as e:
|
||||
assert str(e) == "Test exception"
|
||||
gates_fixture.notification_handler.build_and_send_notification.assert_called_once_with(
|
||||
gates_fixture.send_notification.assert_called_once_with(
|
||||
metadata=metadata['metadata'],
|
||||
notification_id="AGGREGATION_ISSUES",
|
||||
message="Error aggregating data: Test exception",
|
||||
block="aggregate_data",
|
||||
|
||||
Reference in New Issue
Block a user