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
pull/33742/head
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."""
websocket_unique_id = harmony.hub_config.info.get("activeRemoteId")
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
return harmony.config["global"]["timeStampHash"].split(";")[-1]

View File

@ -1,6 +1,8 @@
"""Test Group config panel."""
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.components import config
@ -50,7 +52,7 @@ async def test_update_device_config(hass, hass_client):
"""Mock writing data."""
written.append(data)
mock_call = MagicMock()
mock_call = CoroutineMock()
with patch("homeassistant.components.config._read", mock_read), patch(
"homeassistant.components.config._write", mock_write

View File

@ -15,4 +15,4 @@ def recorder_url_mock():
async def test_setup(hass):
"""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_list_config"),
("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.discovery.test_init", "test_discover_config_flow"),
("tests.components.dyson.test_air_quality", "test_purecool_aiq_attributes"),
@ -58,7 +56,4 @@ IGNORE_UNCAUGHT_JSON_EXCEPTIONS = [
"tests.components.smartthings.test_init",
"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"),
]