@@ -32,7 +32,7 @@ def plugin_manager(port_number: int) -> PluginManager:
3232 plugin_uuid = plugin_uuid ,
3333 plugin_registration_uuid = plugin_registration_uuid ,
3434 register_event = register_event ,
35- info = info
35+ info = info ,
3636 )
3737
3838
@@ -51,7 +51,7 @@ def patch_websocket_client(monkeypatch: pytest.MonkeyPatch) -> tuple[MagicMock,
5151 mock_websocket_client .__enter__ .return_value = mock_websocket_client
5252
5353 # 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 ()
5555 mock_websocket_client .listen_forever .return_value = [fake_event_message .model_dump_json ()]
5656
5757 monkeypatch .setattr ("streamdeck.manager.WebSocketClient" , lambda port : mock_websocket_client )
@@ -75,7 +75,9 @@ def mock_command_sender(mocker: pytest_mock.MockerFixture) -> Mock:
7575
7676
7777@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 :
7981 """Fixture that wraps and spies on the get_action_handlers method of the action_registry.
8082
8183 Args:
@@ -113,7 +115,9 @@ def test_plugin_manager_register_action(plugin_manager: PluginManager):
113115
114116
115117@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+ ):
117121 """Test that StreamDeckCommandSender.send_action_registration() method is called with correct arguments within the PluginManager.run() method."""
118122 plugin_manager .run ()
119123
@@ -125,16 +129,26 @@ def test_plugin_manager_sends_registration_event(mock_command_sender: Mock, plug
125129
126130@pytest .mark .usefixtures ("_spy_action_registry_get_action_handlers" )
127131@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+ ):
129135 """Test that PluginManager processes events correctly, calling event_adapter.validate_json and action_registry.get_action_handlers."""
130136 mock_websocket_client , fake_event_message = patch_websocket_client
131137
132138 plugin_manager .run ()
133139
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.
134142 mock_websocket_client .listen_forever .assert_called_once ()
135143
144+ # Check that the event_adapter.validate_json method was called with the stub json string returned by listen_forever().
136145 spied_event_adapter_validate_json = cast (Mock , event_adapter .validate_json )
137146 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.
138148 assert spied_event_adapter_validate_json .spy_return == fake_event_message
139149
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