|
1 | 1 | import asyncio |
2 | 2 | import time |
3 | | -from unittest.mock import AsyncMock |
| 3 | +from unittest.mock import AsyncMock, MagicMock |
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
@@ -165,54 +165,27 @@ async def test_action(message_payload): ... |
165 | 165 |
|
166 | 166 | monkeypatch.setattr(plugins, "loaded_plugins", {"plugin1": Plugin}, raising=False) |
167 | 167 |
|
168 | | - assert request_handler.get_action("plugin.plugin1.test_action") == Plugin.actions.test_action |
| 168 | + expected_action = Plugin.actions.test_action |
| 169 | + assert request_handler.get_action("plugin.plugin1.actions.test_action") == expected_action |
169 | 170 |
|
170 | 171 |
|
171 | 172 | async def test_get_action_unknown_plugin(caplog, monkeypatch): |
172 | | - """'get_action' should return 'None' when the plugin doesn't exists""" |
173 | | - monkeypatch.setattr(plugins, "loaded_plugins", {"plugin1": "plugin1"}, raising=False) |
| 173 | + """'get_action' should return 'None' when the attribute path could not be resolved""" |
| 174 | + monkeypatch.setattr( |
| 175 | + request_handler, |
| 176 | + "get_plugin_attribute", |
| 177 | + MagicMock(side_effect=ValueError("Some error from the function")), |
| 178 | + ) |
174 | 179 |
|
175 | 180 | action = request_handler.get_action("plugin.plugin2.test_action") |
176 | 181 |
|
177 | 182 | assert action is None |
178 | | - assert_message_in_log(caplog, "Plugin 'plugin2' unknown") |
179 | | - |
180 | | - |
181 | | -async def test_get_action_plugin_no_actions(caplog, monkeypatch): |
182 | | - """'get_action' should return 'None' when the plugin doesn't have actions""" |
183 | | - |
184 | | - class Plugin: ... |
185 | | - |
186 | | - monkeypatch.setattr(plugins, "loaded_plugins", {"plugin1": Plugin}, raising=False) |
187 | | - |
188 | | - action = request_handler.get_action("plugin.plugin1.test_action") |
189 | | - |
190 | | - assert action is None |
191 | | - assert_message_in_log(caplog, "Plugin 'plugin1' doesn't have actions") |
192 | | - |
193 | | - |
194 | | -async def test_get_action_unknown_action(caplog, monkeypatch): |
195 | | - """'get_action' should return 'None' when the action doesn't exists""" |
196 | | - |
197 | | - class Plugin: |
198 | | - class actions: ... |
199 | | - |
200 | | - monkeypatch.setattr(plugins, "loaded_plugins", {"plugin1": Plugin}, raising=False) |
201 | | - |
202 | | - action = request_handler.get_action("plugin.plugin1.test_action") |
203 | | - |
204 | | - assert action is None |
205 | | - assert_message_in_log(caplog, "Action 'plugin1.test_action' unknown") |
| 183 | + assert_message_in_log(caplog, "Some error from the function") |
206 | 184 |
|
207 | 185 |
|
208 | 186 | @pytest.mark.parametrize( |
209 | 187 | "action_name", |
210 | | - [ |
211 | | - "alert_acknowledge", |
212 | | - "alert_lock", |
213 | | - "alert_solve", |
214 | | - "issue_drop", |
215 | | - ], |
| 188 | + ["alert_acknowledge", "alert_lock", "alert_solve", "issue_drop"], |
216 | 189 | ) |
217 | 190 | async def test_run_action(monkeypatch, action_name): |
218 | 191 | """'run' should executed the requested action""" |
|
0 commit comments