Add missing mock in lacrosse_view config flow tests (#89512)

This commit is contained in:
epenet 2023-03-10 16:05:13 +01:00 committed by GitHub
parent f674559a71
commit 401273dcff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 27 deletions

View File

@ -0,0 +1,14 @@
"""Define fixtures for LaCrosse View tests."""
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.lacrosse_view.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry

View File

@ -1,7 +1,8 @@
"""Test the LaCrosse View config flow."""
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
from lacrosse_view import Location, LoginError
import pytest
from homeassistant import config_entries
from homeassistant.components.lacrosse_view.const import DOMAIN
@ -10,8 +11,10 @@ from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_form(hass: HomeAssistant) -> None:
async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -25,8 +28,6 @@ async def test_form(hass: HomeAssistant) -> None:
), patch(
"lacrosse_view.LaCrosse.get_locations",
return_value=[Location(id=1, name="Test")],
), patch(
"homeassistant.components.lacrosse_view.async_setup_entry", return_value=True
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@ -41,17 +42,13 @@ async def test_form(hass: HomeAssistant) -> None:
assert result2["step_id"] == "location"
assert result2["errors"] is None
with patch(
"homeassistant.components.lacrosse_view.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{
"location": "1",
},
)
await hass.async_block_till_done()
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{
"location": "1",
},
)
await hass.async_block_till_done()
assert result3["type"] == FlowResultType.CREATE_ENTRY
assert result3["title"] == "Test"
@ -170,7 +167,9 @@ async def test_form_unexpected_error(hass: HomeAssistant) -> None:
assert result2["errors"] == {"base": "unknown"}
async def test_already_configured_device(hass: HomeAssistant) -> None:
async def test_already_configured_device(
hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test we handle invalid auth."""
mock_config_entry = MockConfigEntry(
domain=DOMAIN,
@ -212,17 +211,13 @@ async def test_already_configured_device(hass: HomeAssistant) -> None:
assert result2["step_id"] == "location"
assert result2["errors"] is None
with patch(
"homeassistant.components.lacrosse_view.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{
"location": "1",
},
)
await hass.async_block_till_done()
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{
"location": "1",
},
)
await hass.async_block_till_done()
assert result3["type"] == FlowResultType.ABORT
assert result3["reason"] == "already_configured"