Fix homematicip_cloud tests that have uncaught exceptions (#33371)

This commit is contained in:
SukramJ authored and GitHub committed 2020-03-28 21:01:53 -07:00
1 parent 42cb5a5239
commit 3c2df7f8f2
5 files changed
+38 -24

No files matched your search

+13 -1
View File
@@ -3,6 +3,7 @@ from asynctest import CoroutineMock, MagicMock, Mock, patch
from homematicip.aio.auth import AsyncAuth
from homematicip.aio.connection import AsyncConnection
from homematicip.aio.home import AsyncHome
from homematicip.base.enums import WeatherCondition, WeatherDayTime
import pytest
from homeassistant import config_entries
@@ -115,10 +116,21 @@ def simple_mock_home_fixture():
devices=[],
groups=[],
location=Mock(),
weather=Mock(create=True),
weather=Mock(
temperature=0.0,
weatherCondition=WeatherCondition.UNKNOWN,
weatherDayTime=WeatherDayTime.DAY,
minTemperature=0.0,
maxTemperature=0.0,
humidity=0,
windSpeed=0.0,
windDirection=0,
vaporAmount=0.0,
),
id=42,
dutyCycle=88,
connected=True,
currentAPVersion="2.0.36",
)
with patch(
@@ -52,6 +52,8 @@ async def test_flow_works(hass, simple_mock_home):
), patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_register",
return_value=True,
), patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
@@ -151,6 +153,8 @@ async def test_import_config(hass, simple_mock_home):
), patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_register",
return_value=True,
), patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
):
result = await hass.config_entries.flow.async_init(
HMIPC_DOMAIN, context={"source": "import"}, data=IMPORT_CONFIG
@@ -39,7 +39,12 @@ async def test_config_with_accesspoint_passed_to_config_entry(
# no acccesspoint exists
assert not hass.data.get(HMIPC_DOMAIN)
assert await async_setup_component(hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config})
with patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
):
assert await async_setup_component(
hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config}
)
# config_entry created for access point
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
@@ -77,7 +82,13 @@ async def test_config_already_registered_not_passed_to_config_entry(
CONF_AUTHTOKEN: "123",
CONF_NAME: "name",
}
assert await async_setup_component(hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config})
with patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
):
assert await async_setup_component(
hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config}
)
# no new config_entry created / still one config_entry
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
@@ -107,16 +118,14 @@ async def test_load_entry_fails_due_to_connection_error(
assert hmip_config_entry.state == ENTRY_STATE_SETUP_RETRY
async def test_load_entry_fails_due_to_generic_exception(
hass, hmip_config_entry, simple_mock_home
):
async def test_load_entry_fails_due_to_generic_exception(hass, hmip_config_entry):
"""Test load entry fails due to generic exception."""
hmip_config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
side_effect=Exception,
):
), patch("homematicip.aio.connection.AsyncConnection.init",):
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id]