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

Fix some ESPHome race conditions (#19772)

* Fix some ESPHome race conditions

* Remove debug

* Update requirements_all.txt

* 🚑 Fix IDE line length settings
This commit is contained in:
Otto Winter
2019-01-04 22:10:52 +01:00
committed by Fabian Affolter
parent ed8f89df74
commit c7700ad11c
4 changed files with 38 additions and 72 deletions

View File

@@ -31,10 +31,8 @@ def mock_client():
return mock_client
mock_client.side_effect = mock_constructor
mock_client.start.return_value = mock_coro()
mock_client.connect.return_value = mock_coro()
mock_client.stop.return_value = mock_coro()
mock_client.login.return_value = mock_coro()
mock_client.disconnect.return_value = mock_coro()
yield mock_client
@@ -69,10 +67,9 @@ async def test_user_connection_works(hass, mock_client):
'password': ''
}
assert result['title'] == 'test'
assert len(mock_client.start.mock_calls) == 1
assert len(mock_client.connect.mock_calls) == 1
assert len(mock_client.device_info.mock_calls) == 1
assert len(mock_client.stop.mock_calls) == 1
assert len(mock_client.disconnect.mock_calls) == 1
assert mock_client.host == '127.0.0.1'
assert mock_client.port == 80
assert mock_client.password == ''
@@ -106,10 +103,9 @@ async def test_user_resolve_error(hass, mock_api_connection_error,
assert result['errors'] == {
'base': 'resolve_error'
}
assert len(mock_client.start.mock_calls) == 1
assert len(mock_client.connect.mock_calls) == 1
assert len(mock_client.device_info.mock_calls) == 1
assert len(mock_client.stop.mock_calls) == 1
assert len(mock_client.disconnect.mock_calls) == 1
async def test_user_connection_error(hass, mock_api_connection_error,
@@ -131,10 +127,9 @@ async def test_user_connection_error(hass, mock_api_connection_error,
assert result['errors'] == {
'base': 'connection_error'
}
assert len(mock_client.start.mock_calls) == 1
assert len(mock_client.connect.mock_calls) == 1
assert len(mock_client.device_info.mock_calls) == 1
assert len(mock_client.stop.mock_calls) == 1
assert len(mock_client.disconnect.mock_calls) == 1
async def test_user_with_password(hass, mock_client):
@@ -176,12 +171,12 @@ async def test_user_invalid_password(hass, mock_api_connection_error,
mock_client.device_info.return_value = mock_coro(
MockDeviceInfo(True, "test"))
mock_client.login.side_effect = mock_api_connection_error
await flow.async_step_user(user_input={
'host': '127.0.0.1',
'port': 6053,
})
mock_client.connect.side_effect = mock_api_connection_error
result = await flow.async_step_authenticate(user_input={
'password': 'invalid'
})
@@ -191,30 +186,3 @@ async def test_user_invalid_password(hass, mock_api_connection_error,
assert result['errors'] == {
'base': 'invalid_password'
}
async def test_user_login_connection_error(hass, mock_api_connection_error,
mock_client):
"""Test user step with connection error during login phase."""
flow = config_flow.EsphomeFlowHandler()
flow.hass = hass
await flow.async_step_user(user_input=None)
mock_client.device_info.return_value = mock_coro(
MockDeviceInfo(True, "test"))
await flow.async_step_user(user_input={
'host': '127.0.0.1',
'port': 6053,
})
mock_client.connect.side_effect = mock_api_connection_error
result = await flow.async_step_authenticate(user_input={
'password': 'invalid'
})
assert result['type'] == 'form'
assert result['step_id'] == 'authenticate'
assert result['errors'] == {
'base': 'connection_error'
}