Add missing mock in buienradar config flow tests (#89420)

This commit is contained in:
epenet 2023-03-09 13:05:04 +01:00 committed by GitHub
parent 86ad8261d8
commit 9faf251321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View File

@ -0,0 +1,14 @@
"""Test fixtures for buienradar2."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.buienradar.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry

View File

@ -1,5 +1,6 @@
"""Test the buienradar2 config flow."""
from unittest.mock import patch
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant.components.buienradar.const import DOMAIN
@ -11,6 +12,8 @@ from tests.common import MockConfigEntry
TEST_LATITUDE = 51.5288504
TEST_LONGITUDE = 5.4002156
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_config_flow_setup_(hass: HomeAssistant) -> None:
"""Test setup of camera."""
@ -22,13 +25,10 @@ async def test_config_flow_setup_(hass: HomeAssistant) -> None:
assert result["step_id"] == "user"
assert result["errors"] == {}
with patch(
"homeassistant.components.buienradar.async_setup_entry", return_value=True
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
)
assert result["type"] == "create_entry"
assert result["title"] == f"{TEST_LATITUDE},{TEST_LONGITUDE}"
@ -92,13 +92,8 @@ async def test_options_flow(hass: HomeAssistant) -> None:
user_input={"country_code": "BE", "delta": 450, "timeframe": 30},
)
with patch(
"homeassistant.components.buienradar.async_setup_entry", return_value=True
), patch(
"homeassistant.components.buienradar.async_unload_entry", return_value=True
):
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
await hass.async_block_till_done()
await hass.async_block_till_done()
assert entry.options == {"country_code": "BE", "delta": 450, "timeframe": 30}