Skip to content

Commit

Permalink
added mock test for interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Sep 3, 2024
1 parent 3d2d53b commit 29342df
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/service/test_interface.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +17,18 @@
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:
template = MessagingTemplate(conn=mock_connection)
template.disconnect = MagicMock()
return template


@pytest.fixture(autouse=True)
def ensure_worker_stopped():
"""This saves every test having to call this at the end.
Expand Down Expand Up @@ -266,3 +281,11 @@ def test_get_task_by_id(context_mock: MagicMock):
is_pending=True,
errors=[],
)


def test_stomp_config(template: MessagingTemplate):
with patch(
"blueapi.service.interface.MessagingTemplate.for_broker", return_value=template
):
interface.set_config(ApplicationConfig(stomp=StompConfig()))
assert interface.messaging_template() is not None

0 comments on commit 29342df

Please sign in to comment.