mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 14:31:13 +00:00
Black
This commit is contained in:
@@ -14,37 +14,34 @@ async def test_bridge_setup():
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
api = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
entry.data = {"host": "1.2.3.4", "username": "mock-username"}
|
||||
hue_bridge = bridge.HueBridge(hass, entry, False, False)
|
||||
|
||||
with patch.object(bridge, 'get_bridge', return_value=mock_coro(api)):
|
||||
with patch.object(bridge, "get_bridge", return_value=mock_coro(api)):
|
||||
assert await hue_bridge.async_setup() is True
|
||||
|
||||
assert hue_bridge.api is api
|
||||
forward_entries = set(
|
||||
c[1][1]
|
||||
for c in
|
||||
hass.config_entries.async_forward_entry_setup.mock_calls
|
||||
)
|
||||
c[1][1] for c in hass.config_entries.async_forward_entry_setup.mock_calls
|
||||
)
|
||||
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 3
|
||||
assert forward_entries == set(['light', 'binary_sensor', 'sensor'])
|
||||
assert forward_entries == set(["light", "binary_sensor", "sensor"])
|
||||
|
||||
|
||||
async def test_bridge_setup_invalid_username():
|
||||
"""Test we start config flow if username is no longer whitelisted."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
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.AuthenticationRequired):
|
||||
with patch.object(bridge, "get_bridge", side_effect=errors.AuthenticationRequired):
|
||||
assert await hue_bridge.async_setup() is False
|
||||
|
||||
assert len(hass.async_create_task.mock_calls) == 1
|
||||
assert len(hass.config_entries.flow.async_init.mock_calls) == 1
|
||||
assert hass.config_entries.flow.async_init.mock_calls[0][2]['data'] == {
|
||||
'host': '1.2.3.4'
|
||||
assert hass.config_entries.flow.async_init.mock_calls[0][2]["data"] == {
|
||||
"host": "1.2.3.4"
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +49,11 @@ async def test_bridge_setup_timeout(hass):
|
||||
"""Test we retry to connect if we cannot connect."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
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
|
||||
bridge, "get_bridge", side_effect=errors.CannotConnect
|
||||
), pytest.raises(ConfigEntryNotReady):
|
||||
await hue_bridge.async_setup()
|
||||
|
||||
@@ -65,11 +62,10 @@ async def test_reset_if_entry_had_wrong_auth():
|
||||
"""Test calling reset when the entry contained wrong auth."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
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.AuthenticationRequired):
|
||||
with patch.object(bridge, "get_bridge", side_effect=errors.AuthenticationRequired):
|
||||
assert await hue_bridge.async_setup() is False
|
||||
|
||||
assert len(hass.async_create_task.mock_calls) == 1
|
||||
@@ -81,17 +77,16 @@ async def test_reset_unloads_entry_if_setup():
|
||||
"""Test calling reset while the entry has been setup."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = {'host': '1.2.3.4', 'username': 'mock-username'}
|
||||
entry.data = {"host": "1.2.3.4", "username": "mock-username"}
|
||||
hue_bridge = bridge.HueBridge(hass, entry, False, False)
|
||||
|
||||
with patch.object(bridge, 'get_bridge', return_value=mock_coro(Mock())):
|
||||
with patch.object(bridge, "get_bridge", return_value=mock_coro(Mock())):
|
||||
assert await hue_bridge.async_setup() is True
|
||||
|
||||
assert len(hass.services.async_register.mock_calls) == 1
|
||||
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 3
|
||||
|
||||
hass.config_entries.async_forward_entry_unload.return_value = \
|
||||
mock_coro(True)
|
||||
hass.config_entries.async_forward_entry_unload.return_value = mock_coro(True)
|
||||
assert await hue_bridge.async_reset()
|
||||
|
||||
assert len(hass.config_entries.async_forward_entry_unload.mock_calls) == 3
|
||||
|
||||
Reference in New Issue
Block a user