1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Make Axis integration use config entry unique id (#30461)

* Make Axis integration use config entry unique id
This commit is contained in:
Robert Svensson
2020-01-04 08:58:18 +01:00
committed by GitHub
parent 075d3f6e32
commit 63347ebeb5
11 changed files with 87 additions and 133 deletions

View File

@@ -4,6 +4,8 @@ from unittest.mock import Mock, patch
from homeassistant.components import axis
from homeassistant.setup import async_setup_component
from .test_device import MAC, setup_axis_integration
from tests.common import MockConfigEntry, mock_coro
@@ -28,22 +30,9 @@ async def test_setup_no_config(hass):
async def test_setup_entry(hass):
"""Test successful setup of entry."""
entry = MockConfigEntry(domain=axis.DOMAIN, data={axis.device.CONF_MAC: "0123"})
mock_device = axis.AxisNetworkDevice(hass, entry)
mock_device.async_setup = Mock(return_value=mock_coro(True))
mock_device.async_update_device_registry = Mock(return_value=mock_coro(True))
mock_device.async_reset = Mock(return_value=mock_coro(True))
with patch.object(axis, "AxisNetworkDevice") as mock_device_class, patch.object(
axis, "async_populate_options", return_value=mock_coro(True)
):
mock_device_class.return_value = mock_device
assert await axis.async_setup_entry(hass, entry)
await setup_axis_integration(hass)
assert len(hass.data[axis.DOMAIN]) == 1
assert "0123" in hass.data[axis.DOMAIN]
assert MAC in hass.data[axis.DOMAIN]
async def test_setup_entry_fails(hass):
@@ -65,21 +54,10 @@ async def test_setup_entry_fails(hass):
async def test_unload_entry(hass):
"""Test successful unload of entry."""
entry = MockConfigEntry(domain=axis.DOMAIN, data={axis.device.CONF_MAC: "0123"})
device = await setup_axis_integration(hass)
assert hass.data[axis.DOMAIN]
mock_device = axis.AxisNetworkDevice(hass, entry)
mock_device.async_setup = Mock(return_value=mock_coro(True))
mock_device.async_update_device_registry = Mock(return_value=mock_coro(True))
mock_device.async_reset = Mock(return_value=mock_coro(True))
with patch.object(axis, "AxisNetworkDevice") as mock_device_class, patch.object(
axis, "async_populate_options", return_value=mock_coro(True)
):
mock_device_class.return_value = mock_device
assert await axis.async_setup_entry(hass, entry)
assert await axis.async_unload_entry(hass, entry)
assert await axis.async_unload_entry(hass, device.config_entry)
assert not hass.data[axis.DOMAIN]