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
|
|
|
|
|
2023-01-14 12:18:18 +00:00
|
|
|
import pytest
|
|
|
|
|
2019-03-24 15:16:50 +00:00
|
|
|
from homeassistant.components import axis
|
2023-01-25 20:15:03 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
2023-02-10 15:05:26 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
2023-02-10 15:05:26 +00:00
|
|
|
async def test_setup_entry(hass: HomeAssistant, setup_config_entry) -> None:
|
2019-03-24 15:16:50 +00:00
|
|
|
"""Test successful setup of entry."""
|
2023-01-25 20:15:03 +00:00
|
|
|
assert setup_config_entry.state == ConfigEntryState.LOADED
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
2023-02-10 15:05:26 +00:00
|
|
|
async def test_setup_entry_fails(hass: HomeAssistant, config_entry) -> None:
|
2019-03-24 15:16:50 +00:00
|
|
|
"""Test successful setup of entry."""
|
|
|
|
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
|
|
|
|
2024-03-02 16:32:51 +00:00
|
|
|
with patch.object(axis, "AxisHub") 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
|
|
|
|
2023-01-25 20:15:03 +00:00
|
|
|
assert config_entry.state == ConfigEntryState.SETUP_ERROR
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
2023-02-10 15:05:26 +00:00
|
|
|
async def test_unload_entry(hass: HomeAssistant, setup_config_entry) -> None:
|
2019-04-15 22:06:45 +00:00
|
|
|
"""Test successful unload of entry."""
|
2023-01-25 20:15:03 +00:00
|
|
|
assert setup_config_entry.state == ConfigEntryState.LOADED
|
2019-04-15 22:06:45 +00:00
|
|
|
|
2023-01-22 16:33:40 +00:00
|
|
|
assert await hass.config_entries.async_unload(setup_config_entry.entry_id)
|
2023-01-25 20:15:03 +00:00
|
|
|
assert setup_config_entry.state == ConfigEntryState.NOT_LOADED
|
2020-01-30 21:20:30 +00:00
|
|
|
|
|
|
|
|
2023-01-15 03:12:03 +00:00
|
|
|
@pytest.mark.parametrize("config_entry_version", [1])
|
2023-02-10 15:05:26 +00:00
|
|
|
async def test_migrate_entry(hass: HomeAssistant, config_entry) -> None:
|
2020-01-30 21:20:30 +00:00
|
|
|
"""Test successful migration of entry data."""
|
2023-01-13 16:12:51 +00: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
|
|
|
|
|
2023-01-25 20:15:03 +00:00
|
|
|
with patch("homeassistant.components.axis.async_setup_entry", return_value=True):
|
2023-01-13 16:12:51 +00:00
|
|
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
|
|
|
|
2023-01-25 20:15:03 +00:00
|
|
|
assert config_entry.state == ConfigEntryState.LOADED
|
2023-01-13 16:12:51 +00:00
|
|
|
assert config_entry.version == 3
|