diff --git a/tests/orchestrator/activities/test_formatters.py b/tests/orchestrator/activities/test_formatters.py index 92ba98c..b75cdfc 100644 --- a/tests/orchestrator/activities/test_formatters.py +++ b/tests/orchestrator/activities/test_formatters.py @@ -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 = { diff --git a/tests/orchestrator/utils/test_orchestrator_functions.py b/tests/orchestrator/utils/test_orchestrator_functions.py index 09c541d..e0b08a9 100644 --- a/tests/orchestrator/utils/test_orchestrator_functions.py +++ b/tests/orchestrator/utils/test_orchestrator_functions.py @@ -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"