|
20 | 20 | ) |
21 | 21 | from blueapi.client.event_bus import AnyEvent, EventBusClient |
22 | 22 | from blueapi.client.rest import BlueapiRestClient, BlueskyRemoteControlError |
23 | | -from blueapi.config import MissingStompConfigurationError |
| 23 | +from blueapi.config import MissingStompConfigurationError, StompConfig, TcpUrl |
24 | 24 | from blueapi.core import DataEvent |
25 | 25 | from blueapi.service.model import ( |
26 | 26 | DeviceModel, |
@@ -385,6 +385,27 @@ def test_cannot_run_task_without_message_bus(client: BlueapiClient, mock_rest: M |
385 | 385 | client.run_task(TaskRequest(name="foo", instrument_session="cm12345-1")) |
386 | 386 |
|
387 | 387 |
|
| 388 | +@patch("blueapi.client.client.EventBusClient") |
| 389 | +def test_run_task_with_stomp_config_from_server( |
| 390 | + ebc: Mock, client: BlueapiClient, mock_rest: Mock |
| 391 | +): |
| 392 | + mock_rest.get_stomp_config.return_value = StompConfig( |
| 393 | + enabled=True, url=TcpUrl("tcp://localhost:9876"), auth=None |
| 394 | + ) |
| 395 | + mock_rest.create_task.return_value = TaskResponse(task_id="foo") |
| 396 | + mock_rest.update_worker_task.return_value = TaskResponse(task_id="foo") |
| 397 | + events = MagicMock(spec=EventBusClient, name="EventBusClient") |
| 398 | + ctx = Mock(correlation_id="foo") |
| 399 | + events.subscribe_to_all_events.side_effect = lambda on_event: on_event( |
| 400 | + COMPLETE_EVENT, ctx |
| 401 | + ) |
| 402 | + ebc.from_stomp_config.return_value = events |
| 403 | + |
| 404 | + client.run_task(TaskRequest(name="foo", instrument_session="cm12345-1")) |
| 405 | + |
| 406 | + mock_rest.get_stomp_config.assert_called_once() |
| 407 | + |
| 408 | + |
388 | 409 | def test_run_task_sets_up_control( |
389 | 410 | client_with_events: BlueapiClient, |
390 | 411 | mock_rest: Mock, |
|
0 commit comments