diff --git a/tests/service/test_interface.py b/tests/service/test_interface.py index ab992e8d2..5bb64d14f 100644 --- a/tests/service/test_interface.py +++ b/tests/service/test_interface.py @@ -1,10 +1,13 @@ import uuid from dataclasses import dataclass -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, Mock, patch import pytest +from bluesky_stomp.messaging import MessagingTemplate from ophyd.sim import SynAxis +from stomp.connect import StompConnection11 as Connection +from blueapi.config import ApplicationConfig, StompConfig from blueapi.core import MsgGenerator from blueapi.core.context import BlueskyContext from blueapi.service import interface @@ -14,6 +17,16 @@ from blueapi.worker.task_worker import TrackableTask +@pytest.fixture +def mock_connection() -> Mock: + return Mock(spec=Connection) + + +@pytest.fixture +def template(mock_connection: Mock) -> MessagingTemplate: + return MessagingTemplate(conn=mock_connection) + + @pytest.fixture(autouse=True) def ensure_worker_stopped(): """This saves every test having to call this at the end. @@ -266,3 +279,9 @@ def test_get_task_by_id(context_mock: MagicMock): is_pending=True, errors=[], ) + + +def test_stomp_config(template: MessagingTemplate): + with patch("blueapi.cli.cli.MessagingTemplate.for_broker", return_value=template): + interface.set_config(ApplicationConfig(stomp=StompConfig())) + assert interface.messaging_template() is not None