2019-03-24 15:16:50 +00:00
|
|
|
"""Test Axis component setup process."""
|
2024-03-08 13:50:25 +00:00
|
|
|
|
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
|
2024-07-26 07:48:37 +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
|
|
|
|
2024-07-26 07:48:37 +00:00
|
|
|
from tests.common import MockConfigEntry
|
2019-03-24 15:16:50 +00:00
|
|
|
|
2024-07-26 07:48:37 +00:00
|
|
|
|
|
|
|
async def test_setup_entry(config_entry_setup: MockConfigEntry) -> None:
|
2019-03-24 15:16:50 +00:00
|
|
|
"""Test successful setup of entry."""
|
2024-06-30 12:52:20 +00:00
|
|
|
assert config_entry_setup.state is ConfigEntryState.LOADED
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
2024-06-10 06:49:43 +00:00
|
|
|
async def test_setup_entry_fails(
|
2024-07-26 07:48:37 +00:00
|
|
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
2024-06-10 06:49:43 +00:00
|
|
|
) -> None:
|
2019-03-24 15:16:50 +00:00
|
|
|
"""Test successful setup of entry."""
|
2024-07-23 17:27:38 +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
|
|
|
|
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
|
|
|
|
2024-04-05 15:16:55 +00:00
|
|
|
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
|
2024-06-10 06:49:43 +00:00
|
|
|
async def test_unload_entry(
|
2024-07-26 07:48:37 +00:00
|
|
|
hass: HomeAssistant, config_entry_setup: MockConfigEntry
|
2024-06-10 06:49:43 +00:00
|
|
|
) -> None:
|
2019-04-15 22:06:45 +00:00
|
|
|
"""Test successful unload of entry."""
|
2024-06-30 12:52:20 +00:00
|
|
|
assert config_entry_setup.state is ConfigEntryState.LOADED
|
2019-04-15 22:06:45 +00:00
|
|
|
|
2024-06-30 12:52:20 +00:00
|
|
|
assert await hass.config_entries.async_unload(config_entry_setup.entry_id)
|
|
|
|
assert config_entry_setup.state is 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])
|
2024-07-26 07:48:37 +00:00
|
|
|
async def test_migrate_entry(
|
|
|
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
|
|
|
) -> None:
|
2020-01-30 21:20:30 +00:00
|
|
|
"""Test successful migration of entry data."""
|
2024-07-23 17:27:38 +00:00
|
|
|
config_entry.add_to_hass(hass)
|
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)
|
|
|
|
|
2024-04-05 15:16:55 +00:00
|
|
|
assert config_entry.state is ConfigEntryState.LOADED
|
2023-01-13 16:12:51 +00:00
|
|
|
assert config_entry.version == 3
|