2019-03-24 16:16:50 +01:00
|
|
|
"""Test Axis component setup process."""
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import AsyncMock, Mock, patch
|
|
|
|
|
2023-01-14 13:18:18 +01:00
|
|
|
import pytest
|
|
|
|
|
2019-03-24 16:16:50 +01:00
|
|
|
from homeassistant.components import axis
|
2022-03-29 11:11:58 +02:00
|
|
|
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
2019-12-08 15:44:04 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2023-01-13 22:21:40 +01:00
|
|
|
from .test_device import setup_axis_integration
|
2020-01-04 08:58:18 +01:00
|
|
|
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
async def test_setup_no_config(hass):
|
|
|
|
"""Test setup without configuration."""
|
2020-05-14 10:49:27 +02:00
|
|
|
assert await async_setup_component(hass, AXIS_DOMAIN, {})
|
|
|
|
assert AXIS_DOMAIN not in hass.data
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
2023-01-14 13:18:18 +01:00
|
|
|
async def test_setup_entry(hass, config_entry):
|
2019-03-24 16:16:50 +01:00
|
|
|
"""Test successful setup of entry."""
|
2023-01-14 13:18:18 +01:00
|
|
|
await setup_axis_integration(hass, config_entry)
|
2020-05-14 10:49:27 +02:00
|
|
|
assert len(hass.data[AXIS_DOMAIN]) == 1
|
2023-01-13 22:21:40 +01:00
|
|
|
assert config_entry.entry_id in hass.data[AXIS_DOMAIN]
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
2023-01-14 13:18:18 +01:00
|
|
|
async def test_setup_entry_fails(hass, config_entry):
|
2019-03-24 16:16:50 +01:00
|
|
|
"""Test successful setup of entry."""
|
|
|
|
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
|
|
|
|
2020-05-14 10:49:27 +02:00
|
|
|
assert not hass.data[AXIS_DOMAIN]
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
2023-01-14 13:18:18 +01:00
|
|
|
async def test_unload_entry(hass, config_entry):
|
2019-04-16 00:06:45 +02:00
|
|
|
"""Test successful unload of entry."""
|
2023-01-14 13:18:18 +01:00
|
|
|
await setup_axis_integration(hass, config_entry)
|
2020-05-14 10:49:27 +02:00
|
|
|
assert hass.data[AXIS_DOMAIN]
|
2019-04-16 00:06:45 +02:00
|
|
|
|
2023-01-13 22:21:40 +01:00
|
|
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
2020-05-14 10:49:27 +02:00
|
|
|
assert not hass.data[AXIS_DOMAIN]
|
2020-01-30 22:20:30 +01:00
|
|
|
|
|
|
|
|
2023-01-15 04:12:03 +01:00
|
|
|
@pytest.mark.parametrize("config_entry_version", [1])
|
2023-01-14 13:18:18 +01:00
|
|
|
async def test_migrate_entry(hass, config_entry):
|
2020-01-30 22:20:30 +01:00
|
|
|
"""Test successful migration of entry data."""
|
2023-01-13 17:12:51 +01:00
|
|
|
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
|