Improve canary tests (#39956)
This commit is contained in:
1 parent
da19854520
commit
17efa1bda5
5 files changed
+261
-227
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""Define fixtures available for all tests."""
|
||||
from canary.api import Api
|
||||
from pytest import fixture
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
|
||||
|
||||
def mock_canary_update(self, **kwargs):
|
||||
"""Get the latest data from py-canary."""
|
||||
self._update(**kwargs)
|
||||
|
||||
|
||||
@fixture
|
||||
def canary(hass):
|
||||
"""Mock the CanaryApi for easier testing."""
|
||||
with patch.object(Api, "login", return_value=True), patch(
|
||||
"homeassistant.components.canary.CanaryData.update", mock_canary_update
|
||||
), patch("homeassistant.components.canary.Api") as mock_canary:
|
||||
instance = mock_canary.return_value = Api(
|
||||
"test-username",
|
||||
"test-password",
|
||||
1,
|
||||
)
|
||||
|
||||
instance.login = MagicMock(return_value=True)
|
||||
instance.get_entries = MagicMock(return_value=[])
|
||||
instance.get_locations = MagicMock(return_value=[])
|
||||
instance.get_location = MagicMock(return_value=None)
|
||||
instance.get_modes = MagicMock(return_value=[])
|
||||
instance.get_readings = MagicMock(return_value=[])
|
||||
instance.get_latest_readings = MagicMock(return_value=[])
|
||||
instance.set_location_mode = MagicMock(return_value=None)
|
||||
|
||||
yield mock_canary
|
||||
Reference in new issue
Block a user