2019-03-24 15:16:50 +00:00
|
|
|
"""Test Axis component setup process."""
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import AsyncMock, Mock, patch
|
|
|
|
|
2019-03-24 15:16:50 +00:00
|
|
|
from homeassistant.components import axis
|
2022-03-29 09:11:58 +00:00
|
|
|
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
2023-01-13 16:12:51 +00:00
|
|
|
from homeassistant.const import CONF_MAC
|
2021-01-16 00:01:14 +00:00
|
|
|
from homeassistant.helpers.device_registry import format_mac
|
2019-12-08 14:44:04 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2019-03-24 15:16:50 +00:00
|
|
|
|
2020-01-31 19:23:51 +00:00
|
|
|
from .test_device import MAC, setup_axis_integration
|
2020-01-04 07:58:18 +00:00
|
|
|
|
2020-04-30 20:29:50 +00:00
|
|
|
from tests.common import MockConfigEntry
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_no_config(hass):
|
|
|
|
"""Test setup without configuration."""
|
2020-05-14 08:49:27 +00:00
|
|
|
assert await async_setup_component(hass, AXIS_DOMAIN, {})
|
|
|
|
assert AXIS_DOMAIN not in hass.data
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_entry(hass):
|
|
|
|
"""Test successful setup of entry."""
|
2020-01-04 07:58:18 +00:00
|
|
|
await setup_axis_integration(hass)
|
2020-05-14 08:49:27 +00:00
|
|
|
assert len(hass.data[AXIS_DOMAIN]) == 1
|
2021-01-16 00:01:14 +00:00
|
|
|
assert format_mac(MAC) in hass.data[AXIS_DOMAIN]
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_entry_fails(hass):
|
|
|
|
"""Test successful setup of entry."""
|
2023-01-13 16:12:51 +00:00
|
|
|
config_entry = MockConfigEntry(domain=AXIS_DOMAIN, data={CONF_MAC: "0123"})
|
2020-01-31 19:23:51 +00:00
|
|
|
config_entry.add_to_hass(hass)
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
mock_device = Mock()
|
2020-04-30 20:29:50 +00:00
|
|
|
mock_device.async_setup = AsyncMock(return_value=False)
|
2019-03-24 15:16:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch.object(axis, "AxisNetworkDevice") as mock_device_class:
|
2019-03-24 15:16:50 +00:00
|
|
|
mock_device_class.return_value = mock_device
|
|
|
|
|
2020-01-31 19:23:51 +00:00
|
|
|
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
2019-03-24 15:16:50 +00:00
|
|
|
|
2020-05-14 08:49:27 +00:00
|
|
|
assert not hass.data[AXIS_DOMAIN]
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
2019-04-15 22:06:45 +00:00
|
|
|
async def test_unload_entry(hass):
|
|
|
|
"""Test successful unload of entry."""
|
2020-10-22 07:29:53 +00:00
|
|
|
config_entry = await setup_axis_integration(hass)
|
|
|
|
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
2020-05-14 08:49:27 +00:00
|
|
|
assert hass.data[AXIS_DOMAIN]
|
2019-04-15 22:06:45 +00:00
|
|
|
|
2020-01-31 19:23:51 +00:00
|
|
|
assert await hass.config_entries.async_unload(device.config_entry.entry_id)
|
2020-05-14 08:49:27 +00:00
|
|
|
assert not hass.data[AXIS_DOMAIN]
|
2020-01-30 21:20:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_migrate_entry(hass):
|
|
|
|
"""Test successful migration of entry data."""
|
2023-01-13 16:12:51 +00:00
|
|
|
config_entry = MockConfigEntry(domain=AXIS_DOMAIN, version=1)
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
assert config_entry.version == 1
|
|
|
|
|
|
|
|
mock_device = Mock()
|
|
|
|
mock_device.async_setup = AsyncMock()
|
|
|
|
mock_device.async_update_device_registry = AsyncMock()
|
|
|
|
mock_device.api.vapix.light_control = None
|
|
|
|
mock_device.api.vapix.params.image_format = None
|
|
|
|
|
|
|
|
with patch.object(axis, "get_axis_device"), patch.object(
|
|
|
|
axis, "AxisNetworkDevice"
|
|
|
|
) as mock_device_class:
|
|
|
|
mock_device_class.return_value = mock_device
|
|
|
|
|
|
|
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
|
|
|
|
|
|
assert hass.data[AXIS_DOMAIN]
|
|
|
|
assert config_entry.version == 3
|