mock_setup_entry

Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
Daniel Hjelseth Høyer 2025-01-05 13:38:17 +01:00
parent 5b7f5fef88
commit f8e88a0855
2 changed files with 35 additions and 8 deletions

View File

@ -0,0 +1,15 @@
"""Common fixtures for the mill tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.mill.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry

View File

@ -1,6 +1,8 @@
"""Tests for Mill config flow."""
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
import pytest
from homeassistant import config_entries
from homeassistant.components.mill.const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
@ -11,8 +13,12 @@ from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_show_config_form(recorder_mock: Recorder, hass: HomeAssistant) -> None:
async def test_show_config_form(
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test show configuration form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -22,7 +28,9 @@ async def test_show_config_form(recorder_mock: Recorder, hass: HomeAssistant) ->
assert result["step_id"] == "user"
async def test_create_entry(recorder_mock: Recorder, hass: HomeAssistant) -> None:
async def test_create_entry(
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test create entry from user input."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -58,7 +66,7 @@ async def test_create_entry(recorder_mock: Recorder, hass: HomeAssistant) -> Non
async def test_flow_entry_already_exists(
recorder_mock: Recorder, hass: HomeAssistant
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test user input for config_entry that already exists."""
@ -99,7 +107,9 @@ async def test_flow_entry_already_exists(
assert result["reason"] == "already_configured"
async def test_connection_error(recorder_mock: Recorder, hass: HomeAssistant) -> None:
async def test_connection_error(
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test connection error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -128,7 +138,9 @@ async def test_connection_error(recorder_mock: Recorder, hass: HomeAssistant) ->
assert result["errors"] == {"base": "cannot_connect"}
async def test_local_create_entry(recorder_mock: Recorder, hass: HomeAssistant) -> None:
async def test_local_create_entry(
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test create entry from user input."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -169,7 +181,7 @@ async def test_local_create_entry(recorder_mock: Recorder, hass: HomeAssistant)
async def test_local_flow_entry_already_exists(
recorder_mock: Recorder, hass: HomeAssistant
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test user input for config_entry that already exists."""
@ -221,7 +233,7 @@ async def test_local_flow_entry_already_exists(
async def test_local_connection_error(
recorder_mock: Recorder, hass: HomeAssistant
recorder_mock: Recorder, hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test connection error."""