Axis - Use core to start component tests (#31328)

* Fix test according to Martins comment in 31286

* Use core features rather than integration specific

* Fix populate options test
This commit is contained in:
Robert Svensson 2020-01-31 20:23:51 +01:00 committed by GitHub
parent 958a867c11
commit 44f0728c60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,7 @@ from unittest.mock import Mock, patch
from homeassistant.components import axis
from homeassistant.setup import async_setup_component
from .test_device import ENTRY_CONFIG, MAC, setup_axis_integration
from .test_device import MAC, setup_axis_integration
from tests.common import MockConfigEntry, mock_coro
@ -37,9 +37,10 @@ async def test_setup_entry(hass):
async def test_setup_entry_fails(hass):
"""Test successful setup of entry."""
entry = MockConfigEntry(
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, options=True
config_entry = MockConfigEntry(
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, options=True, version=2
)
config_entry.add_to_hass(hass)
mock_device = Mock()
mock_device.async_setup.return_value = mock_coro(False)
@ -47,7 +48,7 @@ async def test_setup_entry_fails(hass):
with patch.object(axis, "AxisNetworkDevice") as mock_device_class:
mock_device_class.return_value = mock_device
assert not await axis.async_setup_entry(hass, entry)
assert not await hass.config_entries.async_setup(config_entry.entry_id)
assert not hass.data[axis.DOMAIN]
@ -57,20 +58,15 @@ async def test_unload_entry(hass):
device = await setup_axis_integration(hass)
assert hass.data[axis.DOMAIN]
assert await axis.async_unload_entry(hass, device.config_entry)
assert await hass.config_entries.async_unload(device.config_entry.entry_id)
assert not hass.data[axis.DOMAIN]
async def test_populate_options(hass):
"""Test successful populate options."""
entry = MockConfigEntry(domain=axis.DOMAIN, data=ENTRY_CONFIG)
entry.add_to_hass(hass)
device = await setup_axis_integration(hass, options=None)
with patch.object(axis, "get_device", return_value=mock_coro(Mock())):
await axis.async_populate_options(hass, entry)
assert entry.options == {
assert device.config_entry.options == {
axis.CONF_CAMERA: True,
axis.CONF_EVENTS: True,
axis.CONF_TRIGGER_TIME: axis.DEFAULT_TRIGGER_TIME,
@ -95,7 +91,7 @@ async def test_migrate_entry(hass):
assert entry.data == legacy_config
assert entry.version == 1
await axis.async_migrate_entry(hass, entry)
await entry.async_migrate(hass)
assert entry.data == {
axis.CONF_DEVICE: {