SIENTIAPDE-994
Update requirements.txt with new dependencies and refactor activity methods for improved functionality and error handling
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import ANY, MagicMock, patch
|
||||
from pandas import DataFrame
|
||||
from pytest import fixture, mark
|
||||
|
||||
from laborious.activities.gates import Gates
|
||||
from sientia_do.notifications.models import NotificationLevel
|
||||
|
||||
|
||||
@fixture
|
||||
@@ -272,3 +273,36 @@ async def test_input_gate_no_filtered(
|
||||
assert empty_data_input_args[0][0].equals(DataFrame(
|
||||
{'variable': ['variable1', 'variable2'], 'value': [1, 2]}))
|
||||
assert empty_data_input_args[0][1] == input_data['filters']['EMPTY_DATA']
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
@patch('laborious.activities.gates.filter_functions')
|
||||
async def test_input_gate_error(
|
||||
filter_functions_mock,
|
||||
gates
|
||||
):
|
||||
filter_functions_mock.__getitem__.side_effect = KeyError('test')
|
||||
|
||||
input_data = {
|
||||
'filters': {
|
||||
'SPECIFIC_VARIABLES_NULL_VALUES': {
|
||||
'POLICY': 'stop',
|
||||
'VARIABLES': ['variable2']
|
||||
}
|
||||
},
|
||||
'data': {
|
||||
'variable': ['variable1', 'variable2'],
|
||||
'value': [1, 2]
|
||||
}
|
||||
}
|
||||
|
||||
result = await gates.input_gate(input_data)
|
||||
assert result == (None, 0)
|
||||
|
||||
gates.notification_handler.build_and_send_notification.assert_called_once_with(
|
||||
notification_id='INTPUT_GATE_ERROR__SPECIFIC_VARIABLES_NULL_VALUES',
|
||||
message="Error in filter SPECIFIC_VARIABLES_NULL_VALUES:{'POLICY': 'stop', 'VARIABLES': ['variable2']}: \n 'test'",
|
||||
block='input_gate',
|
||||
level=NotificationLevel.ERROR,
|
||||
attachment_content=ANY
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user