Mock out all default onboarding integrations in test (#68776)

Co-authored-by: Erik Montnemery <erik@montnemery.com>
pull/68528/head^2
Franck Nijhof 2022-03-28 10:33:43 +02:00 committed by GitHub
parent 6cec53bea1
commit 6f567afc0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 33 deletions

View File

@ -14,12 +14,6 @@ from homeassistant.setup import async_setup_component
from . import mock_storage from . import mock_storage
from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI, register_auth_provider from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI, register_auth_provider
from tests.components.met.conftest import mock_weather # noqa: F401
@pytest.fixture(autouse=True)
def always_mock_weather(mock_weather): # noqa: F811
"""Mock the Met weather provider."""
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -90,6 +84,21 @@ async def mock_supervisor_fixture(hass, aioclient_mock):
yield yield
@pytest.fixture
def mock_default_integrations():
"""Mock the default integrations set up during onboarding."""
with patch(
"homeassistant.components.rpi_power.config_flow.new_under_voltage"
), patch(
"homeassistant.components.rpi_power.binary_sensor.new_under_voltage"
), patch(
"homeassistant.components.met.async_setup_entry", return_value=True
), patch(
"homeassistant.components.radio_browser.async_setup_entry", return_value=True
):
yield
async def test_onboarding_progress(hass, hass_storage, hass_client_no_auth): async def test_onboarding_progress(hass, hass_storage, hass_client_no_auth):
"""Test fetching progress.""" """Test fetching progress."""
mock_storage(hass_storage, {"done": ["hello"]}) mock_storage(hass_storage, {"done": ["hello"]})
@ -364,7 +373,9 @@ async def test_onboarding_integration_requires_auth(
assert resp.status == 401 assert resp.status == 401
async def test_onboarding_core_sets_up_met(hass, hass_storage, hass_client): async def test_onboarding_core_sets_up_met(
hass, hass_storage, hass_client, mock_default_integrations
):
"""Test finishing the core step.""" """Test finishing the core step."""
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
@ -372,19 +383,17 @@ async def test_onboarding_core_sets_up_met(hass, hass_storage, hass_client):
await hass.async_block_till_done() await hass.async_block_till_done()
client = await hass_client() client = await hass_client()
with patch( resp = await client.post("/api/onboarding/core_config")
"homeassistant.components.met.async_setup_entry", return_value=True
) as mock_setup:
resp = await client.post("/api/onboarding/core_config")
assert resp.status == 200 assert resp.status == 200
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.config_entries.async_entries("met")) == 1 assert len(hass.config_entries.async_entries("met")) == 1
assert len(mock_setup.mock_calls) == 1
async def test_onboarding_core_sets_up_radio_browser(hass, hass_storage, hass_client): async def test_onboarding_core_sets_up_radio_browser(
hass, hass_storage, hass_client, mock_default_integrations
):
"""Test finishing the core step set up the radio browser.""" """Test finishing the core step set up the radio browser."""
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
@ -392,21 +401,16 @@ async def test_onboarding_core_sets_up_radio_browser(hass, hass_storage, hass_cl
await hass.async_block_till_done() await hass.async_block_till_done()
client = await hass_client() client = await hass_client()
resp = await client.post("/api/onboarding/core_config")
with patch(
"homeassistant.components.radio_browser.async_setup_entry", return_value=True
) as mock_setup:
resp = await client.post("/api/onboarding/core_config")
assert resp.status == 200 assert resp.status == 200
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.config_entries.async_entries("radio_browser")) == 1 assert len(hass.config_entries.async_entries("radio_browser")) == 1
assert len(mock_setup.mock_calls) == 1
async def test_onboarding_core_sets_up_rpi_power( async def test_onboarding_core_sets_up_rpi_power(
hass, hass_storage, hass_client, aioclient_mock, rpi hass, hass_storage, hass_client, aioclient_mock, rpi, mock_default_integrations
): ):
"""Test that the core step sets up rpi_power on RPi.""" """Test that the core step sets up rpi_power on RPi."""
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
@ -416,21 +420,18 @@ async def test_onboarding_core_sets_up_rpi_power(
client = await hass_client() client = await hass_client()
with patch( resp = await client.post("/api/onboarding/core_config")
"homeassistant.components.rpi_power.config_flow.new_under_voltage"
), patch("homeassistant.components.rpi_power.binary_sensor.new_under_voltage"):
resp = await client.post("/api/onboarding/core_config")
assert resp.status == 200 assert resp.status == 200
await hass.async_block_till_done() await hass.async_block_till_done()
rpi_power_state = hass.states.get("binary_sensor.rpi_power_status") rpi_power_state = hass.states.get("binary_sensor.rpi_power_status")
assert rpi_power_state assert rpi_power_state
async def test_onboarding_core_no_rpi_power( async def test_onboarding_core_no_rpi_power(
hass, hass_storage, hass_client, aioclient_mock, no_rpi hass, hass_storage, hass_client, aioclient_mock, no_rpi, mock_default_integrations
): ):
"""Test that the core step do not set up rpi_power on non RPi.""" """Test that the core step do not set up rpi_power on non RPi."""
mock_storage(hass_storage, {"done": [const.STEP_USER]}) mock_storage(hass_storage, {"done": [const.STEP_USER]})
@ -440,14 +441,11 @@ async def test_onboarding_core_no_rpi_power(
client = await hass_client() client = await hass_client()
with patch( resp = await client.post("/api/onboarding/core_config")
"homeassistant.components.rpi_power.config_flow.new_under_voltage"
), patch("homeassistant.components.rpi_power.binary_sensor.new_under_voltage"):
resp = await client.post("/api/onboarding/core_config")
assert resp.status == 200 assert resp.status == 200
await hass.async_block_till_done() await hass.async_block_till_done()
rpi_power_state = hass.states.get("binary_sensor.rpi_power_status") rpi_power_state = hass.states.get("binary_sensor.rpi_power_status")
assert not rpi_power_state assert not rpi_power_state