mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Adjust async_setup_entry in config_flow scaffold (#88319)
This commit is contained in:
parent
273d289e03
commit
5dda1de5bd
@ -1,5 +1,8 @@
|
|||||||
"""Test the NEW_NAME config flow."""
|
"""Test the NEW_NAME config flow."""
|
||||||
from unittest.mock import patch
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.NEW_DOMAIN.config_flow import CannotConnect, InvalidAuth
|
from homeassistant.components.NEW_DOMAIN.config_flow import CannotConnect, InvalidAuth
|
||||||
@ -8,7 +11,16 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass: HomeAssistant) -> None:
|
@pytest.fixture(autouse=True, name="mock_setup_entry")
|
||||||
|
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||||
|
"""Override async_setup_entry."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
|
||||||
|
) as mock_setup_entry:
|
||||||
|
yield mock_setup_entry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
@ -19,10 +31,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate",
|
"homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
), patch(
|
):
|
||||||
"homeassistant.components.NEW_DOMAIN.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry:
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Test the NEW_NAME config flow."""
|
"""Test the NEW_NAME config flow."""
|
||||||
from unittest.mock import patch
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -11,8 +12,19 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True, name="mock_setup_entry")
|
||||||
|
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||||
|
"""Override async_setup_entry."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
|
||||||
|
) as mock_setup_entry:
|
||||||
|
yield mock_setup_entry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("platform", ("sensor",))
|
@pytest.mark.parametrize("platform", ("sensor",))
|
||||||
async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
async def test_config_flow(
|
||||||
|
hass: HomeAssistant, mock_setup_entry: AsyncMock, platform
|
||||||
|
) -> None:
|
||||||
"""Test the config flow."""
|
"""Test the config flow."""
|
||||||
input_sensor_entity_id = "sensor.input"
|
input_sensor_entity_id = "sensor.input"
|
||||||
|
|
||||||
@ -22,15 +34,11 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||||||
assert result["type"] == FlowResultType.FORM
|
assert result["type"] == FlowResultType.FORM
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
"homeassistant.components.NEW_DOMAIN.async_setup_entry",
|
result["flow_id"],
|
||||||
return_value=True,
|
{"name": "My NEW_DOMAIN", "entity_id": input_sensor_entity_id},
|
||||||
) as mock_setup_entry:
|
)
|
||||||
result = await hass.config_entries.flow.async_configure(
|
await hass.async_block_till_done()
|
||||||
result["flow_id"],
|
|
||||||
{"name": "My NEW_DOMAIN", "entity_id": input_sensor_entity_id},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "My NEW_DOMAIN"
|
assert result["title"] == "My NEW_DOMAIN"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user