mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add missing mock in lacrosse_view config flow tests (#89512)
This commit is contained in:
parent
f674559a71
commit
401273dcff
14
tests/components/lacrosse_view/conftest.py
Normal file
14
tests/components/lacrosse_view/conftest.py
Normal 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
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user