2019-03-24 16:16:50 +01:00
|
|
|
"""Test Axis component setup process."""
|
|
|
|
from homeassistant.components import axis
|
2019-12-08 15:44:04 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2020-01-31 20:23:51 +01:00
|
|
|
from .test_device import MAC, setup_axis_integration
|
2020-01-04 08:58:18 +01:00
|
|
|
|
2020-05-03 11:27:19 -07:00
|
|
|
from tests.async_mock import AsyncMock, Mock, patch
|
2020-04-30 13:29:50 -07:00
|
|
|
from tests.common import MockConfigEntry
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_no_config(hass):
|
|
|
|
"""Test setup without configuration."""
|
|
|
|
assert await async_setup_component(hass, axis.DOMAIN, {})
|
|
|
|
assert axis.DOMAIN not in hass.data
|
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_entry(hass):
|
|
|
|
"""Test successful setup of entry."""
|
2020-01-04 08:58:18 +01:00
|
|
|
await setup_axis_integration(hass)
|
2019-03-24 16:16:50 +01:00
|
|
|
assert len(hass.data[axis.DOMAIN]) == 1
|
2020-01-04 08:58:18 +01:00
|
|
|
assert MAC in hass.data[axis.DOMAIN]
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_entry_fails(hass):
|
|
|
|
"""Test successful setup of entry."""
|
2020-01-31 20:23:51 +01:00
|
|
|
config_entry = MockConfigEntry(
|
2020-03-09 14:07:50 -07:00
|
|
|
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, version=2
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2020-01-31 20:23:51 +01:00
|
|
|
config_entry.add_to_hass(hass)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
mock_device = Mock()
|
2020-04-30 13:29:50 -07:00
|
|
|
mock_device.async_setup = AsyncMock(return_value=False)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
with patch.object(axis, "AxisNetworkDevice") as mock_device_class:
|
2019-03-24 16:16:50 +01:00
|
|
|
mock_device_class.return_value = mock_device
|
|
|
|
|
2020-01-31 20:23:51 +01:00
|
|
|
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
assert not hass.data[axis.DOMAIN]
|
|
|
|
|
|
|
|
|
2019-04-16 00:06:45 +02:00
|
|
|
async def test_unload_entry(hass):
|
|
|
|
"""Test successful unload of entry."""
|
2020-01-04 08:58:18 +01:00
|
|
|
device = await setup_axis_integration(hass)
|
|
|
|
assert hass.data[axis.DOMAIN]
|
2019-04-16 00:06:45 +02:00
|
|
|
|
2020-01-31 20:23:51 +01:00
|
|
|
assert await hass.config_entries.async_unload(device.config_entry.entry_id)
|
2019-04-16 00:06:45 +02:00
|
|
|
assert not hass.data[axis.DOMAIN]
|
|
|
|
|
|
|
|
|
2019-03-24 16:16:50 +01:00
|
|
|
async def test_populate_options(hass):
|
|
|
|
"""Test successful populate options."""
|
2020-01-31 20:23:51 +01:00
|
|
|
device = await setup_axis_integration(hass, options=None)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2020-01-31 20:23:51 +01:00
|
|
|
assert device.config_entry.options == {
|
2019-03-24 16:16:50 +01:00
|
|
|
axis.CONF_CAMERA: True,
|
|
|
|
axis.CONF_EVENTS: True,
|
2019-07-31 12:25:30 -07:00
|
|
|
axis.CONF_TRIGGER_TIME: axis.DEFAULT_TRIGGER_TIME,
|
2019-03-24 16:16:50 +01:00
|
|
|
}
|
2020-01-30 22:20:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_migrate_entry(hass):
|
|
|
|
"""Test successful migration of entry data."""
|
|
|
|
legacy_config = {
|
|
|
|
axis.CONF_DEVICE: {
|
|
|
|
axis.CONF_HOST: "1.2.3.4",
|
|
|
|
axis.CONF_USERNAME: "username",
|
|
|
|
axis.CONF_PASSWORD: "password",
|
|
|
|
axis.CONF_PORT: 80,
|
|
|
|
},
|
|
|
|
axis.CONF_MAC: "mac",
|
|
|
|
axis.device.CONF_MODEL: "model",
|
|
|
|
axis.device.CONF_NAME: "name",
|
|
|
|
}
|
|
|
|
entry = MockConfigEntry(domain=axis.DOMAIN, data=legacy_config)
|
|
|
|
|
|
|
|
assert entry.data == legacy_config
|
|
|
|
assert entry.version == 1
|
|
|
|
|
2020-01-31 20:23:51 +01:00
|
|
|
await entry.async_migrate(hass)
|
2020-01-30 22:20:30 +01:00
|
|
|
|
|
|
|
assert entry.data == {
|
|
|
|
axis.CONF_DEVICE: {
|
|
|
|
axis.CONF_HOST: "1.2.3.4",
|
|
|
|
axis.CONF_USERNAME: "username",
|
|
|
|
axis.CONF_PASSWORD: "password",
|
|
|
|
axis.CONF_PORT: 80,
|
|
|
|
},
|
|
|
|
axis.CONF_HOST: "1.2.3.4",
|
|
|
|
axis.CONF_USERNAME: "username",
|
|
|
|
axis.CONF_PASSWORD: "password",
|
|
|
|
axis.CONF_PORT: 80,
|
|
|
|
axis.CONF_MAC: "mac",
|
|
|
|
axis.device.CONF_MODEL: "model",
|
|
|
|
axis.device.CONF_NAME: "name",
|
|
|
|
}
|
|
|
|
assert entry.version == 2
|