Mock all invocations of coronavirus.get_cases (#32487)

pull/32676/head
Paulus Schoutsen 2020-03-04 21:42:07 -08:00 committed by GitHub
parent 81810dd920
commit 81f99efda1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -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)