@@ -32,7 +32,7 @@ def plugin_manager(port_number: int) -> PluginManager:
32
32
plugin_uuid = plugin_uuid ,
33
33
plugin_registration_uuid = plugin_registration_uuid ,
34
34
register_event = register_event ,
35
- info = info
35
+ info = info ,
36
36
)
37
37
38
38
@@ -51,7 +51,7 @@ def patch_websocket_client(monkeypatch: pytest.MonkeyPatch) -> tuple[MagicMock,
51
51
mock_websocket_client .__enter__ .return_value = mock_websocket_client
52
52
53
53
# Create a fake event message, and convert it to a json string to be passed back by the client.listen_forever() method.
54
- fake_event_message = DialRotateEventFactory .build ()
54
+ fake_event_message : DialRotateEvent = DialRotateEventFactory .build ()
55
55
mock_websocket_client .listen_forever .return_value = [fake_event_message .model_dump_json ()]
56
56
57
57
monkeypatch .setattr ("streamdeck.manager.WebSocketClient" , lambda port : mock_websocket_client )
@@ -75,7 +75,9 @@ def mock_command_sender(mocker: pytest_mock.MockerFixture) -> Mock:
75
75
76
76
77
77
@pytest .fixture
78
- def _spy_action_registry_get_action_handlers (mocker : pytest_mock .MockerFixture , plugin_manager : PluginManager ) -> None :
78
+ def _spy_action_registry_get_action_handlers (
79
+ mocker : pytest_mock .MockerFixture , plugin_manager : PluginManager
80
+ ) -> None :
79
81
"""Fixture that wraps and spies on the get_action_handlers method of the action_registry.
80
82
81
83
Args:
@@ -113,7 +115,9 @@ def test_plugin_manager_register_action(plugin_manager: PluginManager):
113
115
114
116
115
117
@pytest .mark .usefixtures ("patch_websocket_client" )
116
- def test_plugin_manager_sends_registration_event (mock_command_sender : Mock , plugin_manager : PluginManager ):
118
+ def test_plugin_manager_sends_registration_event (
119
+ mock_command_sender : Mock , plugin_manager : PluginManager
120
+ ):
117
121
"""Test that StreamDeckCommandSender.send_action_registration() method is called with correct arguments within the PluginManager.run() method."""
118
122
plugin_manager .run ()
119
123
@@ -125,16 +129,26 @@ def test_plugin_manager_sends_registration_event(mock_command_sender: Mock, plug
125
129
126
130
@pytest .mark .usefixtures ("_spy_action_registry_get_action_handlers" )
127
131
@pytest .mark .usefixtures ("_spy_event_adapter_validate_json" )
128
- def test_plugin_manager_process_event (patch_websocket_client : tuple [MagicMock , EventBase ], plugin_manager : PluginManager ):
132
+ def test_plugin_manager_process_event (
133
+ patch_websocket_client : tuple [MagicMock , EventBase ], plugin_manager : PluginManager
134
+ ):
129
135
"""Test that PluginManager processes events correctly, calling event_adapter.validate_json and action_registry.get_action_handlers."""
130
136
mock_websocket_client , fake_event_message = patch_websocket_client
131
137
132
138
plugin_manager .run ()
133
139
140
+ # First check that the WebSocketClient's listen_forever() method was called.
141
+ # This has been stubbed to return the fake_event_message's json string.
134
142
mock_websocket_client .listen_forever .assert_called_once ()
135
143
144
+ # Check that the event_adapter.validate_json method was called with the stub json string returned by listen_forever().
136
145
spied_event_adapter_validate_json = cast (Mock , event_adapter .validate_json )
137
146
spied_event_adapter_validate_json .assert_called_once_with (fake_event_message .model_dump_json ())
147
+ # Check that the validate_json method returns the same event type model as the fake_event_message.
138
148
assert spied_event_adapter_validate_json .spy_return == fake_event_message
139
149
140
- cast (Mock , plugin_manager ._registry .get_action_handlers ).assert_called_once_with (fake_event_message .event )
150
+ # Check that the action_registry.get_action_handlers method was called with the event name and action uuid.
151
+ cast (Mock , plugin_manager ._registry .get_action_handlers ).assert_called_once_with (
152
+ event_name = fake_event_message .event , event_action_uuid = fake_event_message .action
153
+ )
154
+
0 commit comments