Refactor bond integration to be completely async (#38066)

This commit is contained in:
Eugene Prystupa authored and GitHub committed 2020-07-22 20:22:25 -05:00
1 parent 15fe727f2c
commit 3480fb6996
16 files changed
+251 -259

No files matched your search

+9 -10
View File
@@ -1,13 +1,12 @@
"""Test the Bond config flow."""
from json import JSONDecodeError
from requests.exceptions import ConnectionError
from aiohttp import ClientConnectionError, ClientResponseError
from homeassistant import config_entries, core, setup
from homeassistant.components.bond.const import DOMAIN
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST
from tests.async_mock import patch
from tests.async_mock import Mock, patch
async def test_form(hass: core.HomeAssistant):
@@ -20,7 +19,7 @@ async def test_form(hass: core.HomeAssistant):
assert result["errors"] == {}
with patch(
"homeassistant.components.bond.config_flow.Bond.getDeviceIds", return_value=[],
"homeassistant.components.bond.config_flow.Bond.devices", return_value=[],
), patch(
"homeassistant.components.bond.async_setup", return_value=True
) as mock_setup, patch(
@@ -48,8 +47,8 @@ async def test_form_invalid_auth(hass: core.HomeAssistant):
)
with patch(
"homeassistant.components.bond.config_flow.Bond.getDeviceIds",
side_effect=JSONDecodeError("test-message", "test-doc", 0),
"homeassistant.components.bond.config_flow.Bond.devices",
side_effect=ClientResponseError(Mock(), Mock(), status=401),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},
@@ -66,8 +65,8 @@ async def test_form_cannot_connect(hass: core.HomeAssistant):
)
with patch(
"homeassistant.components.bond.config_flow.Bond.getDeviceIds",
side_effect=ConnectionError,
"homeassistant.components.bond.config_flow.Bond.devices",
side_effect=ClientConnectionError(),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},
@@ -84,8 +83,8 @@ async def test_form_unexpected_error(hass: core.HomeAssistant):
)
with patch(
"homeassistant.components.bond.config_flow.Bond.getDeviceIds",
side_effect=Exception,
"homeassistant.components.bond.config_flow.Bond.devices",
side_effect=ClientResponseError(Mock(), Mock(), status=500),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},