mirror of
https://github.com/home-assistant/core.git
synced 2025-11-05 08:59:57 +00:00
Fix hassio mocking in ESPHome dashboard tests (#143212)
This commit is contained in:
@@ -119,8 +119,10 @@ from .typing import (
|
||||
if TYPE_CHECKING:
|
||||
# Local import to avoid processing recorder and SQLite modules when running a
|
||||
# testcase which does not use the recorder.
|
||||
from homeassistant.auth.models import RefreshToken
|
||||
from homeassistant.components import recorder
|
||||
|
||||
|
||||
pytest.register_assert_rewrite("tests.common")
|
||||
|
||||
from .common import ( # noqa: E402, isort:skip
|
||||
@@ -1894,6 +1896,67 @@ def mock_bleak_scanner_start() -> Generator[MagicMock]:
|
||||
yield mock_bleak_scanner_start
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hassio_env(supervisor_is_connected: AsyncMock) -> Generator[None]:
|
||||
"""Fixture to inject hassio env."""
|
||||
from homeassistant.components.hassio import ( # pylint: disable=import-outside-toplevel
|
||||
HassioAPIError,
|
||||
)
|
||||
|
||||
from .components.hassio import ( # pylint: disable=import-outside-toplevel
|
||||
SUPERVISOR_TOKEN,
|
||||
)
|
||||
|
||||
with (
|
||||
patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}),
|
||||
patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}),
|
||||
patch(
|
||||
"homeassistant.components.hassio.HassIO.get_info",
|
||||
Mock(side_effect=HassioAPIError()),
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def hassio_stubs(
|
||||
hassio_env: None,
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
supervisor_client: AsyncMock,
|
||||
) -> RefreshToken:
|
||||
"""Create mock hassio http client."""
|
||||
from homeassistant.components.hassio import ( # pylint: disable=import-outside-toplevel
|
||||
HassioAPIError,
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.hassio.HassIO.update_hass_api",
|
||||
return_value={"result": "ok"},
|
||||
) as hass_api,
|
||||
patch(
|
||||
"homeassistant.components.hassio.HassIO.update_hass_timezone",
|
||||
return_value={"result": "ok"},
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.hassio.HassIO.get_info",
|
||||
side_effect=HassioAPIError(),
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.hassio.HassIO.get_ingress_panels",
|
||||
return_value={"panels": []},
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.hassio.issues.SupervisorIssues.setup",
|
||||
),
|
||||
):
|
||||
await async_setup_component(hass, "hassio", {})
|
||||
|
||||
return hass_api.call_args[0][1]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def integration_frame_path() -> str:
|
||||
"""Return the path to the integration frame.
|
||||
|
||||
Reference in New Issue
Block a user