From 40ecec15c51f07a49894ef5124987bac7afe34e1 Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Wed, 15 Apr 2020 20:05:52 +0000 Subject: [PATCH 1/5] verify that the config in hass is not empty --- tests/components/ios/test_init.py | 6 ++++-- tests/ignore_uncaught_exceptions.py | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/components/ios/test_init.py b/tests/components/ios/test_init.py index 31eb43fc611b86..5d4aff4f9647c9 100644 --- a/tests/components/ios/test_init.py +++ b/tests/components/ios/test_init.py @@ -3,7 +3,7 @@ import pytest -from homeassistant import config_entries, data_entry_flow +from homeassistant import bootstrap, config_entries, data_entry_flow from homeassistant.components import ios from homeassistant.setup import async_setup_component @@ -26,6 +26,8 @@ def mock_dependencies(hass): async def test_creating_entry_sets_up_sensor(hass): """Test setting up iOS loads the sensor component.""" + # so it will not have an empty config + await bootstrap.async_from_config_dict({"foo": "bar"}, hass) with patch( "homeassistant.components.ios.sensor.async_setup_entry", return_value=mock_coro(True), @@ -61,7 +63,7 @@ async def test_not_configuring_ios_not_creates_entry(hass): with patch( "homeassistant.components.ios.async_setup_entry", return_value=mock_coro(True) ) as mock_setup: - await async_setup_component(hass, ios.DOMAIN, {}) + await async_setup_component(hass, ios.DOMAIN, {"foo": "bar"}) await hass.async_block_till_done() assert len(mock_setup.mock_calls) == 0 diff --git a/tests/ignore_uncaught_exceptions.py b/tests/ignore_uncaught_exceptions.py index 8e6004d362e11c..d8734ab7316309 100644 --- a/tests/ignore_uncaught_exceptions.py +++ b/tests/ignore_uncaught_exceptions.py @@ -1,7 +1,5 @@ """List of modules that have uncaught exceptions today. Will be shrunk over time.""" IGNORE_UNCAUGHT_EXCEPTIONS = [ - ("tests.components.ios.test_init", "test_creating_entry_sets_up_sensor"), - ("tests.components.ios.test_init", "test_not_configuring_ios_not_creates_entry"), ("tests.components.local_file.test_camera", "test_file_not_readable"), ] From 8a0ee572b26b7fba52df59778ba56337510f8212 Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Thu, 16 Apr 2020 12:01:30 +0000 Subject: [PATCH 2/5] changed to use MockConfigEntry --- tests/components/ios/test_init.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/components/ios/test_init.py b/tests/components/ios/test_init.py index 5d4aff4f9647c9..c1a2b19f504626 100644 --- a/tests/components/ios/test_init.py +++ b/tests/components/ios/test_init.py @@ -3,11 +3,11 @@ import pytest -from homeassistant import bootstrap, config_entries, data_entry_flow +from homeassistant import bootstrap from homeassistant.components import ios from homeassistant.setup import async_setup_component -from tests.common import mock_component, mock_coro +from tests.common import MockConfigEntry, mock_component, mock_coro @pytest.fixture(autouse=True) @@ -28,20 +28,13 @@ async def test_creating_entry_sets_up_sensor(hass): """Test setting up iOS loads the sensor component.""" # so it will not have an empty config await bootstrap.async_from_config_dict({"foo": "bar"}, hass) + entry = MockConfigEntry(domain=ios.DOMAIN, data={},) + entry.add_to_hass(hass) with patch( "homeassistant.components.ios.sensor.async_setup_entry", return_value=mock_coro(True), ) as mock_setup: - result = await hass.config_entries.flow.async_init( - ios.DOMAIN, context={"source": config_entries.SOURCE_USER} - ) - - # Confirmation form - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - - result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - + assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert len(mock_setup.mock_calls) == 1 From 7a7299bce76d32850a73c0df090aeee4e97e4d46 Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Thu, 16 Apr 2020 21:30:02 +0300 Subject: [PATCH 3/5] Update tests/components/ios/test_init.py Co-Authored-By: Martin Hjelmare --- tests/components/ios/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/ios/test_init.py b/tests/components/ios/test_init.py index c1a2b19f504626..044ad7b7414d2d 100644 --- a/tests/components/ios/test_init.py +++ b/tests/components/ios/test_init.py @@ -34,7 +34,7 @@ async def test_creating_entry_sets_up_sensor(hass): "homeassistant.components.ios.sensor.async_setup_entry", return_value=mock_coro(True), ) as mock_setup: - assert await hass.config_entries.async_setup(entry.entry_id) + assert await async_setup_component(hass, ios.DOMAIN, {ios.DOMAIN: {}}) await hass.async_block_till_done() assert len(mock_setup.mock_calls) == 1 From 6bf208aea08b19136636895531ec773e6ce8f2c4 Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Thu, 16 Apr 2020 21:30:11 +0300 Subject: [PATCH 4/5] Update tests/components/ios/test_init.py Co-Authored-By: Martin Hjelmare --- tests/components/ios/test_init.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/components/ios/test_init.py b/tests/components/ios/test_init.py index 044ad7b7414d2d..235d82b048cbc8 100644 --- a/tests/components/ios/test_init.py +++ b/tests/components/ios/test_init.py @@ -27,7 +27,6 @@ def mock_dependencies(hass): async def test_creating_entry_sets_up_sensor(hass): """Test setting up iOS loads the sensor component.""" # so it will not have an empty config - await bootstrap.async_from_config_dict({"foo": "bar"}, hass) entry = MockConfigEntry(domain=ios.DOMAIN, data={},) entry.add_to_hass(hass) with patch( From 0b1c28ff6952a95d1e0235f68d84154ce421b128 Mon Sep 17 00:00:00 2001 From: Ziv <16467659+ziv1234@users.noreply.github.com> Date: Thu, 16 Apr 2020 18:32:49 +0000 Subject: [PATCH 5/5] changed the test per suggestions --- tests/components/ios/test_init.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/components/ios/test_init.py b/tests/components/ios/test_init.py index 235d82b048cbc8..5fe796bae20e84 100644 --- a/tests/components/ios/test_init.py +++ b/tests/components/ios/test_init.py @@ -3,11 +3,10 @@ import pytest -from homeassistant import bootstrap from homeassistant.components import ios from homeassistant.setup import async_setup_component -from tests.common import MockConfigEntry, mock_component, mock_coro +from tests.common import mock_component, mock_coro @pytest.fixture(autouse=True) @@ -26,9 +25,6 @@ def mock_dependencies(hass): async def test_creating_entry_sets_up_sensor(hass): """Test setting up iOS loads the sensor component.""" - # so it will not have an empty config - entry = MockConfigEntry(domain=ios.DOMAIN, data={},) - entry.add_to_hass(hass) with patch( "homeassistant.components.ios.sensor.async_setup_entry", return_value=mock_coro(True),