From 2b461073ff6b24cf162d6a266758e92b8b0f3b3c Mon Sep 17 00:00:00 2001 From: Rob Bierbooms Date: Wed, 5 May 2021 09:05:46 +0200 Subject: [PATCH] Improve buienradar tests (#50101) --- tests/components/buienradar/test_init.py | 8 +++--- tests/components/buienradar/test_sensor.py | 30 +++++++++++++-------- tests/components/buienradar/test_weather.py | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/components/buienradar/test_init.py b/tests/components/buienradar/test_init.py index e3ac8c025e1..ea91291a3de 100644 --- a/tests/components/buienradar/test_init.py +++ b/tests/components/buienradar/test_init.py @@ -1,7 +1,7 @@ """Tests for the buienradar component.""" from unittest.mock import patch -from homeassistant.components.buienradar import async_setup +from homeassistant import setup from homeassistant.components.buienradar.const import DOMAIN from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE from homeassistant.helpers.entity_registry import async_get_registry @@ -30,7 +30,7 @@ async def test_import_all(hass): with patch( "homeassistant.components.buienradar.async_setup_entry", return_value=True ): - await async_setup(hass, config) + await setup.async_setup_component(hass, DOMAIN, config) await hass.async_block_till_done() conf_entries = hass.config_entries.async_entries(DOMAIN) @@ -68,7 +68,7 @@ async def test_import_camera(hass): with patch( "homeassistant.components.buienradar.async_setup_entry", return_value=True ): - await async_setup(hass, config) + await setup.async_setup_component(hass, DOMAIN, config) await hass.async_block_till_done() conf_entries = hass.config_entries.async_entries(DOMAIN) @@ -97,7 +97,7 @@ async def test_import_camera(hass): assert entity.original_name == "test_name" -async def test_load_unload(hass): +async def test_load_unload(aioclient_mock, hass): """Test options flow.""" entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/buienradar/test_sensor.py b/tests/components/buienradar/test_sensor.py index f0a24b6beb3..2b381f980d7 100644 --- a/tests/components/buienradar/test_sensor.py +++ b/tests/components/buienradar/test_sensor.py @@ -1,29 +1,37 @@ """The tests for the Buienradar sensor platform.""" -from unittest.mock import patch - from homeassistant.components.buienradar.const import DOMAIN from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE +from homeassistant.helpers.entity_registry import async_get from tests.common import MockConfigEntry +TEST_LONGITUDE = 51.5288504 +TEST_LATITUDE = 5.4002156 + CONDITIONS = ["stationname", "temperature"] -TEST_CFG_DATA = {CONF_LATITUDE: 51.5288504, CONF_LONGITUDE: 5.4002156} +TEST_CFG_DATA = {CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE} -async def test_smoke_test_setup_component(hass): +async def test_smoke_test_setup_component(aioclient_mock, hass): """Smoke test for successfully set-up with default config.""" mock_entry = MockConfigEntry(domain=DOMAIN, unique_id="TEST_ID", data=TEST_CFG_DATA) mock_entry.add_to_hass(hass) - with patch( - "homeassistant.components.buienradar.sensor.BrSensor.entity_registry_enabled_default" - ) as enabled_by_default_mock: - enabled_by_default_mock.return_value = True + entity_registry = async_get(hass) + for cond in CONDITIONS: + entity_registry.async_get_or_create( + domain="sensor", + platform="buienradar", + unique_id=f"{TEST_LATITUDE:2.6f}{TEST_LONGITUDE:2.6f}{cond}", + config_entry=mock_entry, + original_name=f"Buienradar {cond}", + ) + await hass.async_block_till_done() - await hass.config_entries.async_setup(mock_entry.entry_id) - await hass.async_block_till_done() + await hass.config_entries.async_setup(mock_entry.entry_id) + await hass.async_block_till_done() for cond in CONDITIONS: - state = hass.states.get(f"sensor.buienradar_{cond}") + state = hass.states.get(f"sensor.buienradar_5_40021651_528850{cond}") assert state.state == "unknown" diff --git a/tests/components/buienradar/test_weather.py b/tests/components/buienradar/test_weather.py index 9d16b531ad0..81fd3f4fcb4 100644 --- a/tests/components/buienradar/test_weather.py +++ b/tests/components/buienradar/test_weather.py @@ -7,7 +7,7 @@ from tests.common import MockConfigEntry TEST_CFG_DATA = {CONF_LATITUDE: 51.5288504, CONF_LONGITUDE: 5.4002156} -async def test_smoke_test_setup_component(hass): +async def test_smoke_test_setup_component(aioclient_mock, hass): """Smoke test for successfully set-up with default config.""" mock_entry = MockConfigEntry(domain=DOMAIN, unique_id="TEST_ID", data=TEST_CFG_DATA)