From 3eb6a68d123195ee4577221751ed69bbdc7cbb6a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 3 Jul 2020 13:14:19 -0500 Subject: [PATCH] Ensure async_setup is mocked in geonetnz intergration tests (#37426) * Ensure async_setup is mocked in geonetnz intergration tests * s/asynctest/tests.async_mock/g --- .../geonetnz_quakes/test_config_flow.py | 20 +++++++++++++------ .../geonetnz_volcano/test_config_flow.py | 16 +++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/components/geonetnz_quakes/test_config_flow.py b/tests/components/geonetnz_quakes/test_config_flow.py index 051873f5360..a4b1d9c792b 100644 --- a/tests/components/geonetnz_quakes/test_config_flow.py +++ b/tests/components/geonetnz_quakes/test_config_flow.py @@ -15,6 +15,8 @@ from homeassistant.const import ( CONF_UNIT_SYSTEM, ) +from tests.async_mock import patch + async def test_duplicate_error(hass, config_entry): """Test that errors are shown when duplicates are added.""" @@ -49,9 +51,12 @@ async def test_step_import(hass): CONF_MINIMUM_MAGNITUDE: 2.5, } - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=conf - ) + with patch( + "homeassistant.components.geonetnz_quakes.async_setup_entry", return_value=True + ), patch("homeassistant.components.geonetnz_quakes.async_setup", return_value=True): + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": "import"}, data=conf + ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" assert result["data"] == { @@ -71,9 +76,12 @@ async def test_step_user(hass): hass.config.longitude = 174.7 conf = {CONF_RADIUS: 25, CONF_MMI: 4} - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=conf - ) + with patch( + "homeassistant.components.geonetnz_quakes.async_setup_entry", return_value=True + ), patch("homeassistant.components.geonetnz_quakes.async_setup", return_value=True): + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": "user"}, data=conf + ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" assert result["data"] == { diff --git a/tests/components/geonetnz_volcano/test_config_flow.py b/tests/components/geonetnz_volcano/test_config_flow.py index 8f589aded90..91ca7a1f553 100644 --- a/tests/components/geonetnz_volcano/test_config_flow.py +++ b/tests/components/geonetnz_volcano/test_config_flow.py @@ -11,6 +11,8 @@ from homeassistant.const import ( CONF_UNIT_SYSTEM, ) +from tests.async_mock import patch + async def test_duplicate_error(hass, config_entry): """Test that errors are shown when duplicates are added.""" @@ -48,7 +50,12 @@ async def test_step_import(hass): flow = config_flow.GeonetnzVolcanoFlowHandler() flow.hass = hass - result = await flow.async_step_import(import_config=conf) + with patch( + "homeassistant.components.geonetnz_volcano.async_setup_entry", return_value=True + ), patch( + "homeassistant.components.geonetnz_volcano.async_setup", return_value=True + ): + result = await flow.async_step_import(import_config=conf) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" assert result["data"] == { @@ -69,7 +76,12 @@ async def test_step_user(hass): flow = config_flow.GeonetnzVolcanoFlowHandler() flow.hass = hass - result = await flow.async_step_user(user_input=conf) + with patch( + "homeassistant.components.geonetnz_volcano.async_setup_entry", return_value=True + ), patch( + "homeassistant.components.geonetnz_volcano.async_setup", return_value=True + ): + result = await flow.async_step_user(user_input=conf) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" assert result["data"] == {