Don't directly update config entries (#20877)
* Don't directly update config entries * Use ConfigEntryNotReady * Fix tests * Remove old test * Lint
This commit is contained in:
1 parent
161c368c9d
commit
882f5ed079
11 files changed
+54
-169
No files matched your search
@@ -1,6 +1,9 @@
|
||||
"""Test deCONZ gateway."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.components.deconz import gateway
|
||||
|
||||
from tests.common import mock_coro
|
||||
@@ -56,8 +59,10 @@ async def test_gateway_retry():
|
||||
|
||||
deconz_gateway = gateway.DeconzGateway(hass, entry)
|
||||
|
||||
with patch.object(gateway, 'get_gateway', return_value=mock_coro(False)):
|
||||
assert await deconz_gateway.async_setup() is False
|
||||
with patch.object(
|
||||
gateway, 'get_gateway', return_value=mock_coro(False)
|
||||
), pytest.raises(ConfigEntryNotReady):
|
||||
await deconz_gateway.async_setup()
|
||||
|
||||
|
||||
async def test_connection_status(hass):
|
||||
@@ -118,22 +123,6 @@ async def test_shutdown():
|
||||
assert len(deconz_gateway.api.close.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_reset_cancel_retry():
|
||||
"""Verify async reset can handle a scheduled retry."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = ENTRY_CONFIG
|
||||
|
||||
deconz_gateway = gateway.DeconzGateway(hass, entry)
|
||||
|
||||
with patch.object(gateway, 'get_gateway', return_value=mock_coro(False)):
|
||||
assert await deconz_gateway.async_setup() is False
|
||||
|
||||
assert deconz_gateway._cancel_retry_setup is not None
|
||||
|
||||
assert await deconz_gateway.async_reset() is True
|
||||
|
||||
|
||||
async def test_reset_after_successful_setup():
|
||||
"""Verify that reset works on a setup component."""
|
||||
hass = Mock()
|
||||
|
||||
@@ -4,6 +4,7 @@ from unittest.mock import Mock, patch
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import deconz
|
||||
|
||||
@@ -79,9 +80,11 @@ async def test_setup_entry_no_available_bridge(hass):
|
||||
"""Test setup entry fails if deCONZ is not available."""
|
||||
entry = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'}
|
||||
with patch('pydeconz.DeconzSession.async_load_parameters',
|
||||
return_value=mock_coro(False)):
|
||||
assert await deconz.async_setup_entry(hass, entry) is False
|
||||
with patch(
|
||||
'pydeconz.DeconzSession.async_load_parameters',
|
||||
return_value=mock_coro(False)
|
||||
), pytest.raises(ConfigEntryNotReady):
|
||||
await deconz.async_setup_entry(hass, entry)
|
||||
|
||||
|
||||
async def test_setup_entry_successful(hass):
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""Test HomematicIP Cloud accesspoint."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.components.homematicip_cloud import hap as hmipc
|
||||
from homeassistant.components.homematicip_cloud import const, errors
|
||||
from tests.common import mock_coro, mock_coro_func
|
||||
@@ -82,9 +85,10 @@ async def test_hap_setup_connection_error():
|
||||
hmipc.HMIPC_NAME: 'hmip',
|
||||
}
|
||||
hap = hmipc.HomematicipHAP(hass, entry)
|
||||
with patch.object(hap, 'get_hap',
|
||||
side_effect=errors.HmipcConnectionError):
|
||||
assert await hap.async_setup() is False
|
||||
with patch.object(
|
||||
hap, 'get_hap', side_effect=errors.HmipcConnectionError
|
||||
), pytest.raises(ConfigEntryNotReady):
|
||||
await hap.async_setup()
|
||||
|
||||
assert len(hass.async_add_job.mock_calls) == 0
|
||||
assert len(hass.config_entries.flow.async_init.mock_calls) == 0
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""Test Hue bridge."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.components.hue import bridge, errors
|
||||
|
||||
from tests.common import mock_coro
|
||||
@@ -48,32 +51,10 @@ async def test_bridge_setup_timeout(hass):
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
hue_bridge = bridge.HueBridge(hass, entry, False, False)
|
||||
|
||||
with patch.object(bridge, 'get_bridge', side_effect=errors.CannotConnect):
|
||||
assert await hue_bridge.async_setup() is False
|
||||
|
||||
assert len(hass.helpers.event.async_call_later.mock_calls) == 1
|
||||
# Assert we are going to wait 2 seconds
|
||||
assert hass.helpers.event.async_call_later.mock_calls[0][1][0] == 2
|
||||
|
||||
|
||||
async def test_reset_cancels_retry_setup():
|
||||
"""Test resetting a bridge while we're waiting to retry setup."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
hue_bridge = bridge.HueBridge(hass, entry, False, False)
|
||||
|
||||
with patch.object(bridge, 'get_bridge', side_effect=errors.CannotConnect):
|
||||
assert await hue_bridge.async_setup() is False
|
||||
|
||||
mock_call_later = hass.helpers.event.async_call_later
|
||||
|
||||
assert len(mock_call_later.mock_calls) == 1
|
||||
|
||||
assert await hue_bridge.async_reset()
|
||||
|
||||
assert len(mock_call_later.mock_calls) == 2
|
||||
assert len(mock_call_later.return_value.mock_calls) == 1
|
||||
with patch.object(
|
||||
bridge, 'get_bridge', side_effect=errors.CannotConnect
|
||||
), pytest.raises(ConfigEntryNotReady):
|
||||
await hue_bridge.async_setup()
|
||||
|
||||
|
||||
async def test_reset_if_entry_had_wrong_auth():
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""Test UniFi Controller."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi import controller, errors
|
||||
|
||||
@@ -103,13 +106,10 @@ async def test_controller_not_accessible():
|
||||
|
||||
unifi_controller = controller.UniFiController(hass, entry)
|
||||
|
||||
with patch.object(controller, 'get_controller',
|
||||
side_effect=errors.CannotConnect):
|
||||
assert await unifi_controller.async_setup() is False
|
||||
|
||||
assert len(hass.helpers.event.async_call_later.mock_calls) == 1
|
||||
# Assert we are going to wait 2 seconds
|
||||
assert hass.helpers.event.async_call_later.mock_calls[0][1][0] == 2
|
||||
with patch.object(
|
||||
controller, 'get_controller', side_effect=errors.CannotConnect
|
||||
), pytest.raises(ConfigEntryNotReady):
|
||||
await unifi_controller.async_setup()
|
||||
|
||||
|
||||
async def test_controller_unknown_error():
|
||||
@@ -128,28 +128,6 @@ async def test_controller_unknown_error():
|
||||
assert not hass.helpers.event.async_call_later.mock_calls
|
||||
|
||||
|
||||
async def test_reset_cancels_retry_setup():
|
||||
"""Resetting a controller while we're waiting to retry setup."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = ENTRY_CONFIG
|
||||
|
||||
unifi_controller = controller.UniFiController(hass, entry)
|
||||
|
||||
with patch.object(controller, 'get_controller',
|
||||
side_effect=errors.CannotConnect):
|
||||
assert await unifi_controller.async_setup() is False
|
||||
|
||||
mock_call_later = hass.helpers.event.async_call_later
|
||||
|
||||
assert len(mock_call_later.mock_calls) == 1
|
||||
|
||||
assert await unifi_controller.async_reset()
|
||||
|
||||
assert len(mock_call_later.mock_calls) == 2
|
||||
assert len(mock_call_later.return_value.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_reset_if_entry_had_wrong_auth():
|
||||
"""Calling reset when the entry contains wrong auth."""
|
||||
hass = Mock()
|
||||
|
||||
Reference in new issue
Block a user