SIENTIAPDE-1151
test: add unit tests for error handling in process_slots and build_tag_config functions to ensure proper notification on missing servers
This commit is contained in:
@@ -268,6 +268,70 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
}
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
@patch("orchestrator.activities.formatters.gather_read_tags",
|
||||
return_value={
|
||||
"1:test_tag_address": {
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address",
|
||||
"topics": ["raw_test_schedule"]
|
||||
},
|
||||
"2:test_tag_address2": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address2",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
}
|
||||
})
|
||||
@patch("orchestrator.activities.formatters.build_tag_config", side_effect=ValueError("test_error"))
|
||||
async def test_process_slots_exception(mock_build_tag_config, mock_gather_read_tags, formatters):
|
||||
input_data = {
|
||||
**metadata,
|
||||
"opc_servers": [
|
||||
{
|
||||
"id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"uri": "test_uri",
|
||||
"security_spec": {
|
||||
"test_name": "test_spec"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"uri": "test_uri2"
|
||||
}
|
||||
],
|
||||
"active_ingestors": [
|
||||
"test_active_ingestor1",
|
||||
"test_active_ingestor2"
|
||||
],
|
||||
"pipelines": "test_gather_read_tags"
|
||||
}
|
||||
|
||||
await formatters.process_slots(input_data)
|
||||
|
||||
formatters.send_notification.assert_has_calls([
|
||||
call(
|
||||
metadata=metadata['metadata'],
|
||||
notification_id="ORCHESTRATOR_BUILD_TAG_CONFIG_ERROR",
|
||||
message="test_error",
|
||||
block="orchestrator",
|
||||
level=NotificationLevel.ERROR
|
||||
),
|
||||
call(
|
||||
metadata=metadata['metadata'],
|
||||
notification_id="ORCHESTRATOR_BUILD_TAG_CONFIG_ERROR",
|
||||
message="test_error",
|
||||
block="orchestrator",
|
||||
level=NotificationLevel.ERROR
|
||||
)
|
||||
])
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_format_schedule_config(formatters):
|
||||
input_data = {
|
||||
|
||||
@@ -342,3 +342,16 @@ def test_build_tag_config():
|
||||
}
|
||||
}
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_build_tag_config_no_server_id():
|
||||
tag = {
|
||||
"server_id": "1",
|
||||
"tag_address": "test_tag_address"
|
||||
}
|
||||
opc_servers = {}
|
||||
|
||||
try:
|
||||
build_tag_config(tag, {}, opc_servers, 1)
|
||||
except ValueError as e:
|
||||
assert str(e) == "Server 1 not found in opc_servers"
|
||||
|
||||
Reference in New Issue
Block a user