diff --git a/tests/components/coronavirus/conftest.py b/tests/components/coronavirus/conftest.py new file mode 100644 index 00000000000..45d2a00e69d --- /dev/null +++ b/tests/components/coronavirus/conftest.py @@ -0,0 +1,17 @@ +"""Test helpers.""" + +from asynctest import Mock, patch +import pytest + + +@pytest.fixture(autouse=True) +def mock_cases(): + """Mock coronavirus cases.""" + with patch( + "coronavirus.get_cases", + return_value=[ + Mock(country="Netherlands", confirmed=10, recovered=8, deaths=1, current=1), + Mock(country="Germany", confirmed=1, recovered=0, deaths=0, current=0), + ], + ) as mock_get_cases: + yield mock_get_cases diff --git a/tests/components/coronavirus/test_config_flow.py b/tests/components/coronavirus/test_config_flow.py index ef04d0df07a..b7af2e343b2 100644 --- a/tests/components/coronavirus/test_config_flow.py +++ b/tests/components/coronavirus/test_config_flow.py @@ -1,6 +1,4 @@ """Test the Coronavirus config flow.""" -from asynctest import patch - from homeassistant import config_entries, setup from homeassistant.components.coronavirus.const import DOMAIN, OPTION_WORLDWIDE @@ -14,14 +12,9 @@ async def test_form(hass): assert result["type"] == "form" assert result["errors"] == {} - with patch("coronavirus.get_cases", return_value=[],), patch( - "homeassistant.components.coronavirus.async_setup", return_value=True - ) as mock_setup, patch( - "homeassistant.components.coronavirus.async_setup_entry", return_value=True, - ) as mock_setup_entry: - result2 = await hass.config_entries.flow.async_configure( - result["flow_id"], {"country": OPTION_WORLDWIDE}, - ) + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], {"country": OPTION_WORLDWIDE}, + ) assert result2["type"] == "create_entry" assert result2["title"] == "Worldwide" assert result2["result"].unique_id == OPTION_WORLDWIDE @@ -29,5 +22,4 @@ async def test_form(hass): "country": OPTION_WORLDWIDE, } await hass.async_block_till_done() - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 + assert len(hass.states.async_all()) == 4 diff --git a/tests/components/coronavirus/test_init.py b/tests/components/coronavirus/test_init.py index 57293635570..483fabab9f9 100644 --- a/tests/components/coronavirus/test_init.py +++ b/tests/components/coronavirus/test_init.py @@ -1,6 +1,4 @@ """Test init of Coronavirus integration.""" -from asynctest import Mock, patch - from homeassistant.components.coronavirus.const import DOMAIN, OPTION_WORLDWIDE from homeassistant.helpers import entity_registry from homeassistant.setup import async_setup_component @@ -33,15 +31,8 @@ async def test_migration(hass): ), }, ) - with patch( - "coronavirus.get_cases", - return_value=[ - Mock(country="Netherlands", confirmed=10, recovered=8, deaths=1, current=1), - Mock(country="Germany", confirmed=1, recovered=0, deaths=0, current=0), - ], - ): - assert await async_setup_component(hass, DOMAIN, {}) - await hass.async_block_till_done() + assert await async_setup_component(hass, DOMAIN, {}) + await hass.async_block_till_done() ent_reg = await entity_registry.async_get_registry(hass)