Cleanup redundant fixtures and move all other hassio addon fixtures to be shared (#124437)
This commit is contained in:
parent
6e5e96b047
commit
51dba1eec3
3 changed files with 124 additions and 152 deletions
|
@ -14,6 +14,8 @@ from homeassistant.const import STATE_OFF, STATE_ON
|
|||
from homeassistant.core import HomeAssistant
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.components.hassio.addon_manager import AddonManager
|
||||
|
||||
from .conversation import MockAgent
|
||||
from .device_tracker.common import MockScanner
|
||||
from .light.common import MockLight
|
||||
|
@ -182,6 +184,15 @@ def mock_legacy_device_tracker_setup() -> Callable[[HomeAssistant, MockScanner],
|
|||
return mock_legacy_device_tracker_setup
|
||||
|
||||
|
||||
@pytest.fixture(name="addon_manager")
|
||||
def addon_manager_fixture(hass: HomeAssistant) -> AddonManager:
|
||||
"""Return an AddonManager instance."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_addon_manager
|
||||
|
||||
return mock_addon_manager(hass)
|
||||
|
||||
|
||||
@pytest.fixture(name="discovery_info")
|
||||
def discovery_info_fixture() -> Any:
|
||||
"""Return the discovery info from the supervisor."""
|
||||
|
@ -269,3 +280,57 @@ def start_addon_fixture() -> Generator[AsyncMock]:
|
|||
from .hassio.common import mock_start_addon
|
||||
|
||||
yield from mock_start_addon()
|
||||
|
||||
|
||||
@pytest.fixture(name="restart_addon")
|
||||
def restart_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock restart add-on."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_restart_addon
|
||||
|
||||
yield from mock_restart_addon()
|
||||
|
||||
|
||||
@pytest.fixture(name="stop_addon")
|
||||
def stop_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock stop add-on."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_stop_addon
|
||||
|
||||
yield from mock_stop_addon()
|
||||
|
||||
|
||||
@pytest.fixture(name="set_addon_options")
|
||||
def set_addon_options_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock set add-on options."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_set_addon_options
|
||||
|
||||
yield from mock_set_addon_options()
|
||||
|
||||
|
||||
@pytest.fixture(name="uninstall_addon")
|
||||
def uninstall_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock uninstall add-on."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_uninstall_addon
|
||||
|
||||
yield from mock_uninstall_addon()
|
||||
|
||||
|
||||
@pytest.fixture(name="create_backup")
|
||||
def create_backup_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock create backup."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_create_backup
|
||||
|
||||
yield from mock_create_backup()
|
||||
|
||||
|
||||
@pytest.fixture(name="update_addon")
|
||||
def update_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock update add-on."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from .hassio.common import mock_update_addon
|
||||
|
||||
yield from mock_update_addon()
|
||||
|
|
|
@ -3,11 +3,20 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Generator
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import DEFAULT, AsyncMock, patch
|
||||
|
||||
from homeassistant.components.hassio.addon_manager import AddonManager
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def mock_addon_manager(hass: HomeAssistant) -> AddonManager:
|
||||
"""Return an AddonManager instance."""
|
||||
return AddonManager(hass, LOGGER, "Test", "test_addon")
|
||||
|
||||
|
||||
def mock_discovery_info() -> Any:
|
||||
"""Return the discovery info from the supervisor."""
|
||||
|
@ -72,7 +81,7 @@ def mock_addon_installed(
|
|||
"version": "1.0.0",
|
||||
}
|
||||
addon_info.return_value["available"] = True
|
||||
addon_info.return_value["hostname"] = "core-matter-server"
|
||||
addon_info.return_value["hostname"] = "core-test-addon"
|
||||
addon_info.return_value["state"] = "stopped"
|
||||
addon_info.return_value["version"] = "1.0.0"
|
||||
return addon_info
|
||||
|
@ -123,3 +132,51 @@ def mock_start_addon() -> Generator[AsyncMock]:
|
|||
"homeassistant.components.hassio.addon_manager.async_start_addon"
|
||||
) as start_addon:
|
||||
yield start_addon
|
||||
|
||||
|
||||
def mock_stop_addon() -> Generator[AsyncMock]:
|
||||
"""Mock stop add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_stop_addon"
|
||||
) as stop_addon:
|
||||
yield stop_addon
|
||||
|
||||
|
||||
def mock_restart_addon() -> Generator[AsyncMock]:
|
||||
"""Mock restart add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_restart_addon"
|
||||
) as restart_addon:
|
||||
yield restart_addon
|
||||
|
||||
|
||||
def mock_uninstall_addon() -> Generator[AsyncMock]:
|
||||
"""Mock uninstall add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_uninstall_addon"
|
||||
) as uninstall_addon:
|
||||
yield uninstall_addon
|
||||
|
||||
|
||||
def mock_set_addon_options() -> Generator[AsyncMock]:
|
||||
"""Mock set add-on options."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_set_addon_options"
|
||||
) as set_options:
|
||||
yield set_options
|
||||
|
||||
|
||||
def mock_create_backup() -> Generator[AsyncMock]:
|
||||
"""Mock create backup."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_create_backup"
|
||||
) as create_backup:
|
||||
yield create_backup
|
||||
|
||||
|
||||
def mock_update_addon() -> Generator[AsyncMock]:
|
||||
"""Mock update add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_update_addon"
|
||||
) as update_addon:
|
||||
yield update_addon
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Generator
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, call, patch
|
||||
from unittest.mock import AsyncMock, call
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -19,154 +17,6 @@ from homeassistant.components.hassio.addon_manager import (
|
|||
from homeassistant.components.hassio.handler import HassioAPIError
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture(name="addon_manager")
|
||||
def addon_manager_fixture(hass: HomeAssistant) -> AddonManager:
|
||||
"""Return an AddonManager instance."""
|
||||
return AddonManager(hass, LOGGER, "Test", "test_addon")
|
||||
|
||||
|
||||
@pytest.fixture(name="addon_not_installed")
|
||||
def addon_not_installed_fixture(
|
||||
addon_store_info: AsyncMock, addon_info: AsyncMock
|
||||
) -> AsyncMock:
|
||||
"""Mock add-on not installed."""
|
||||
addon_store_info.return_value["available"] = True
|
||||
return addon_info
|
||||
|
||||
|
||||
@pytest.fixture(name="addon_installed")
|
||||
def mock_addon_installed(
|
||||
addon_store_info: AsyncMock, addon_info: AsyncMock
|
||||
) -> AsyncMock:
|
||||
"""Mock add-on already installed but not running."""
|
||||
addon_store_info.return_value = {
|
||||
"available": True,
|
||||
"installed": "1.0.0",
|
||||
"state": "stopped",
|
||||
"version": "1.0.0",
|
||||
}
|
||||
addon_info.return_value["available"] = True
|
||||
addon_info.return_value["hostname"] = "core-test-addon"
|
||||
addon_info.return_value["state"] = "stopped"
|
||||
addon_info.return_value["version"] = "1.0.0"
|
||||
return addon_info
|
||||
|
||||
|
||||
@pytest.fixture(name="get_addon_discovery_info")
|
||||
def get_addon_discovery_info_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock get add-on discovery info."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_get_addon_discovery_info"
|
||||
) as get_addon_discovery_info:
|
||||
yield get_addon_discovery_info
|
||||
|
||||
|
||||
@pytest.fixture(name="addon_store_info")
|
||||
def addon_store_info_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock Supervisor add-on store info."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_get_addon_store_info"
|
||||
) as addon_store_info:
|
||||
addon_store_info.return_value = {
|
||||
"available": False,
|
||||
"installed": None,
|
||||
"state": None,
|
||||
"version": "1.0.0",
|
||||
}
|
||||
yield addon_store_info
|
||||
|
||||
|
||||
@pytest.fixture(name="addon_info")
|
||||
def addon_info_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock Supervisor add-on info."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_get_addon_info",
|
||||
) as addon_info:
|
||||
addon_info.return_value = {
|
||||
"available": False,
|
||||
"hostname": None,
|
||||
"options": {},
|
||||
"state": None,
|
||||
"update_available": False,
|
||||
"version": None,
|
||||
}
|
||||
yield addon_info
|
||||
|
||||
|
||||
@pytest.fixture(name="set_addon_options")
|
||||
def set_addon_options_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock set add-on options."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_set_addon_options"
|
||||
) as set_options:
|
||||
yield set_options
|
||||
|
||||
|
||||
@pytest.fixture(name="install_addon")
|
||||
def install_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock install add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_install_addon"
|
||||
) as install_addon:
|
||||
yield install_addon
|
||||
|
||||
|
||||
@pytest.fixture(name="uninstall_addon")
|
||||
def uninstall_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock uninstall add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_uninstall_addon"
|
||||
) as uninstall_addon:
|
||||
yield uninstall_addon
|
||||
|
||||
|
||||
@pytest.fixture(name="start_addon")
|
||||
def start_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock start add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_start_addon"
|
||||
) as start_addon:
|
||||
yield start_addon
|
||||
|
||||
|
||||
@pytest.fixture(name="restart_addon")
|
||||
def restart_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock restart add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_restart_addon"
|
||||
) as restart_addon:
|
||||
yield restart_addon
|
||||
|
||||
|
||||
@pytest.fixture(name="stop_addon")
|
||||
def stop_addon_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock stop add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_stop_addon"
|
||||
) as stop_addon:
|
||||
yield stop_addon
|
||||
|
||||
|
||||
@pytest.fixture(name="create_backup")
|
||||
def create_backup_fixture() -> Generator[AsyncMock]:
|
||||
"""Mock create backup."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_create_backup"
|
||||
) as create_backup:
|
||||
yield create_backup
|
||||
|
||||
|
||||
@pytest.fixture(name="update_addon")
|
||||
def mock_update_addon() -> Generator[AsyncMock]:
|
||||
"""Mock update add-on."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.addon_manager.async_update_addon"
|
||||
) as update_addon:
|
||||
yield update_addon
|
||||
|
||||
|
||||
async def test_not_installed_raises_exception(
|
||||
addon_manager: AddonManager,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue