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 8dd1209
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 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,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.
Expand Down Expand Up @@ -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

0 comments on commit 8dd1209

Please sign in to comment.