-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): add tests for listen_changes methods
- Loading branch information
Showing
8 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
from appdaemon.plugins.hass.hassapi import Hass | ||
from cx_core.controller import Controller | ||
from cx_core.integration.state import StateIntegration | ||
from pytest_mock.plugin import MockerFixture | ||
|
||
|
||
@pytest.mark.parametrize("attribute", ["sensor", "entity_id", None]) | ||
@pytest.mark.asyncio | ||
async def test_listen_changes( | ||
fake_controller: Controller, mocker: MockerFixture, attribute: Optional[str] | ||
): | ||
kwargs = {} | ||
if attribute is not None: | ||
kwargs["attribute"] = attribute | ||
controller_id = "controller_id" | ||
state_event_mock = mocker.patch.object(Hass, "listen_state") | ||
state_integration = StateIntegration(fake_controller, kwargs) | ||
|
||
await state_integration.listen_changes(controller_id) | ||
|
||
state_event_mock.assert_called_once_with( | ||
fake_controller, | ||
state_integration.state_callback, | ||
controller_id, | ||
attribute=attribute, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_callback( | ||
fake_controller: Controller, | ||
mocker: MockerFixture, | ||
): | ||
|
||
handle_action_patch = mocker.patch.object(fake_controller, "handle_action") | ||
state_integration = StateIntegration(fake_controller, {}) | ||
|
||
await state_integration.state_callback("test", None, "old_state", "new_state", {}) | ||
|
||
handle_action_patch.assert_called_once_with("new_state") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters