mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Velbus add init testcases (#134533)
This commit is contained in:
parent
afa95293dc
commit
c7f6630718
@ -1,20 +1,51 @@
|
||||
"""Tests for the Velbus component initialisation."""
|
||||
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from velbusaio.exceptions import VelbusConnectionFailed
|
||||
|
||||
from homeassistant.components.velbus import VelbusConfigEntry
|
||||
from homeassistant.components.velbus.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import CONF_NAME, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from . import init_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("controller")
|
||||
async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
async def test_setup_connection_failed(
|
||||
hass: HomeAssistant,
|
||||
config_entry: VelbusConfigEntry,
|
||||
controller: MagicMock,
|
||||
) -> None:
|
||||
"""Test the setup that fails during velbus connect."""
|
||||
controller.return_value.connect.side_effect = VelbusConnectionFailed()
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_setup_start_failed(
|
||||
hass: HomeAssistant,
|
||||
config_entry: VelbusConfigEntry,
|
||||
controller: MagicMock,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the setup that fails during velbus start task, should result in no entries."""
|
||||
controller.return_value.start.side_effect = ConnectionError()
|
||||
await init_integration(hass, config_entry)
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
assert (
|
||||
er.async_entries_for_config_entry(entity_registry, config_entry.entry_id) == []
|
||||
)
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
) -> None:
|
||||
"""Test being able to unload an entry."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@ -29,9 +60,10 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> N
|
||||
assert not hass.data.get(DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("controller")
|
||||
async def test_device_identifier_migration(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, device_registry: dr.DeviceRegistry
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test being able to unload an entry."""
|
||||
original_identifiers = {(DOMAIN, "module_address", "module_serial")}
|
||||
@ -64,8 +96,10 @@ async def test_device_identifier_migration(
|
||||
assert device_entry.sw_version == "module_sw_version"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("controller")
|
||||
async def test_migrate_config_entry(hass: HomeAssistant) -> None:
|
||||
async def test_migrate_config_entry(
|
||||
hass: HomeAssistant,
|
||||
controller: MagicMock,
|
||||
) -> None:
|
||||
"""Test successful migration of entry data."""
|
||||
legacy_config = {CONF_NAME: "fake_name", CONF_PORT: "1.2.3.4:5678"}
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id="my own id", data=legacy_config)
|
||||
|
Loading…
x
Reference in New Issue
Block a user