2020-09-13 11:32:41 -05:00
|
|
|
"""Define fixtures available for all tests."""
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
2020-09-13 11:32:41 -05:00
|
|
|
from canary.api import Api
|
2023-01-27 09:09:46 +01:00
|
|
|
import pytest
|
2020-09-13 11:32:41 -05:00
|
|
|
|
|
|
|
|
2023-01-27 09:09:46 +01:00
|
|
|
@pytest.fixture(autouse=True)
|
2020-11-11 00:03:16 +01:00
|
|
|
def mock_ffmpeg(hass):
|
|
|
|
"""Mock ffmpeg is loaded."""
|
|
|
|
hass.config.components.add("ffmpeg")
|
|
|
|
|
|
|
|
|
2023-01-27 09:09:46 +01:00
|
|
|
@pytest.fixture
|
2020-09-13 11:32:41 -05:00
|
|
|
def canary(hass):
|
|
|
|
"""Mock the CanaryApi for easier testing."""
|
|
|
|
with patch.object(Api, "login", return_value=True), patch(
|
2020-10-01 03:26:26 -05:00
|
|
|
"homeassistant.components.canary.Api"
|
|
|
|
) as mock_canary:
|
2020-09-13 11:32:41 -05:00
|
|
|
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
|
2020-09-18 23:22:19 -05:00
|
|
|
|
|
|
|
|
2023-01-27 09:09:46 +01:00
|
|
|
@pytest.fixture
|
2020-09-18 23:22:19 -05:00
|
|
|
def canary_config_flow(hass):
|
|
|
|
"""Mock the CanaryApi for easier config flow testing."""
|
|
|
|
with patch.object(Api, "login", return_value=True), patch(
|
|
|
|
"homeassistant.components.canary.config_flow.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
|