Adjust async_setup_entry in config_flow scaffold (#88319)

This commit is contained in:
epenet 2023-02-17 13:43:56 +01:00 committed by GitHub
parent 273d289e03
commit 5dda1de5bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 17 deletions

View file

@ -1,5 +1,8 @@
"""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.components.NEW_DOMAIN.config_flow import CannotConnect, InvalidAuth
@ -8,7 +11,16 @@ from homeassistant.core import HomeAssistant
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."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -19,10 +31,7 @@ async def test_form(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate",
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(
result["flow_id"],
{