Fix unhandled exceptions for config, default_config, harmony (#33731)

* replaced MagicMock with CoroutineMock to avoid exception

* added conversion to str so mock returns unique-id that doesn't throw json exception

* added non-empty config since hass throws exception when config is empty
This commit is contained in:
Ziv 2020-04-06 14:36:49 +03:00 committed by GitHub
parent 98a2efcbab
commit cedf7e3945
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 9 deletions

View file

@ -11,7 +11,7 @@ def find_unique_id_for_remote(harmony: HarmonyAPI):
"""Find the unique id for both websocket and xmpp clients.""" """Find the unique id for both websocket and xmpp clients."""
websocket_unique_id = harmony.hub_config.info.get("activeRemoteId") websocket_unique_id = harmony.hub_config.info.get("activeRemoteId")
if websocket_unique_id is not None: if websocket_unique_id is not None:
return websocket_unique_id return str(websocket_unique_id)
# fallback to the xmpp unique id if websocket is not available # fallback to the xmpp unique id if websocket is not available
return harmony.config["global"]["timeStampHash"].split(";")[-1] return harmony.config["global"]["timeStampHash"].split(";")[-1]

View file

@ -1,6 +1,8 @@
"""Test Group config panel.""" """Test Group config panel."""
import json import json
from unittest.mock import MagicMock, patch from unittest.mock import patch
from asynctest import CoroutineMock
from homeassistant.bootstrap import async_setup_component from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config from homeassistant.components import config
@ -50,7 +52,7 @@ async def test_update_device_config(hass, hass_client):
"""Mock writing data.""" """Mock writing data."""
written.append(data) written.append(data)
mock_call = MagicMock() mock_call = CoroutineMock()
with patch("homeassistant.components.config._read", mock_read), patch( with patch("homeassistant.components.config._read", mock_read), patch(
"homeassistant.components.config._write", mock_write "homeassistant.components.config._write", mock_write

View file

@ -15,4 +15,4 @@ def recorder_url_mock():
async def test_setup(hass): async def test_setup(hass):
"""Test setup.""" """Test setup."""
assert await async_setup_component(hass, "default_config", {}) assert await async_setup_component(hass, "default_config", {"foo": "bar"})

View file

@ -4,8 +4,6 @@ IGNORE_UNCAUGHT_EXCEPTIONS = [
("tests.components.cast.test_media_player", "test_entry_setup_single_config"), ("tests.components.cast.test_media_player", "test_entry_setup_single_config"),
("tests.components.cast.test_media_player", "test_entry_setup_list_config"), ("tests.components.cast.test_media_player", "test_entry_setup_list_config"),
("tests.components.cast.test_media_player", "test_entry_setup_platform_not_ready"), ("tests.components.cast.test_media_player", "test_entry_setup_platform_not_ready"),
("tests.components.config.test_group", "test_update_device_config"),
("tests.components.default_config.test_init", "test_setup"),
("tests.components.demo.test_init", "test_setting_up_demo"), ("tests.components.demo.test_init", "test_setting_up_demo"),
("tests.components.discovery.test_init", "test_discover_config_flow"), ("tests.components.discovery.test_init", "test_discover_config_flow"),
("tests.components.dyson.test_air_quality", "test_purecool_aiq_attributes"), ("tests.components.dyson.test_air_quality", "test_purecool_aiq_attributes"),
@ -58,7 +56,4 @@ IGNORE_UNCAUGHT_JSON_EXCEPTIONS = [
"tests.components.smartthings.test_init", "tests.components.smartthings.test_init",
"test_config_entry_loads_unconnected_cloud", "test_config_entry_loads_unconnected_cloud",
), ),
("tests.components.harmony.test_config_flow", "test_form_import"),
("tests.components.harmony.test_config_flow", "test_form_ssdp"),
("tests.components.harmony.test_config_flow", "test_user_form"),
] ]