core/tests/components/canary/conftest.py

66 lines
2.1 KiB
Python

"""Define fixtures available for all tests."""
from collections.abc import Generator
from unittest.mock import MagicMock, patch
from canary.api import Api
import pytest
from homeassistant.core import HomeAssistant
@pytest.fixture(autouse=True)
def mock_ffmpeg(hass: HomeAssistant) -> None:
"""Mock ffmpeg is loaded."""
hass.config.components.add("ffmpeg")
@pytest.fixture
def canary() -> Generator[MagicMock]:
"""Mock the CanaryApi for easier testing."""
with (
patch.object(Api, "login", return_value=True),
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
@pytest.fixture
def canary_config_flow() -> Generator[MagicMock]:
"""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