Skip to content

Commit

Permalink
fix(z2m): allow action_group individual value without a list
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviml committed Feb 6, 2021
1 parent ec4be32 commit f6a63ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
4 changes: 1 addition & 3 deletions apps/controllerx/cx_core/integration/z2m.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ async def event_callback(
)
return
if action_group_key in payload and "action_group" in self.kwargs:
action_group = self.kwargs["action_group"]
if isinstance(action_group, str):
action_group = [action_group]
action_group = self.controller.get_list(self.kwargs["action_group"])
if payload["action_group"] not in action_group:
self.controller.log(
f"Action group {payload['action_group']} not found in "
Expand Down
39 changes: 28 additions & 11 deletions tests/unit_tests/cx_core/integration/z2m_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any, Dict, Optional

import pytest
from cx_core.controller import Controller
Expand All @@ -7,13 +7,27 @@


@pytest.mark.parametrize(
"data, action_key, handle_action_called, expected_called_with",
"data, action_key, action_group, handle_action_called, expected_called_with",
[
({"payload": '{"event_1": "action_1"}'}, "event_1", True, "action_1"),
({}, None, False, Any),
({"payload": '{"action": "action_1"}'}, None, True, "action_1"),
({"payload": '{"event_1": "action_1"}'}, "event_2", False, "Any"),
({"payload": '{"action_rate": 195}'}, "action", False, "Any"),
({"payload": '{"event_1": "action_1"}'}, "event_1", None, True, "action_1"),
({}, None, None, False, Any),
({"payload": '{"action": "action_1"}'}, None, None, True, "action_1"),
(
{"payload": '{"action": "action_1", "action_group": 123}'},
None,
123,
True,
"action_1",
),
(
{"payload": '{"action": "action_1", "action_group": 123}'},
None,
321,
False,
"any",
),
({"payload": '{"event_1": "action_1"}'}, "event_2", None, False, "Any"),
({"payload": '{"action_rate": 195}'}, "action", None, False, "Any"),
],
)
@pytest.mark.asyncio
Expand All @@ -22,14 +36,17 @@ async def test_event_callback(
mocker: MockerFixture,
data: Dict,
action_key: str,
action_group: Optional[int],
handle_action_called: bool,
expected_called_with: str,
):
handle_action_patch = mocker.patch.object(fake_controller, "handle_action")
z2m_integration = Z2MIntegration(fake_controller, {})
z2m_integration.kwargs = (
{"action_key": action_key} if action_key is not None else {}
)
kwargs: Dict[str, Any] = {}
if action_key is not None:
kwargs["action_key"] = action_key
if action_group is not None:
kwargs["action_group"] = action_group
z2m_integration = Z2MIntegration(fake_controller, kwargs)
await z2m_integration.event_callback("test", data, {})

if handle_action_called:
Expand Down

0 comments on commit f6a63ba

Please sign in to comment.