mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Let the discovergy config flow test end with create entry (#100153)
This commit is contained in:
parent
851dc4cdf4
commit
4779cdf2ae
@ -11,6 +11,7 @@ from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.discovergy.const import GET_METERS
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant, mock_meters: Mock) -> None:
|
||||
@ -86,14 +87,24 @@ async def test_reauth(
|
||||
async def test_form_fail(hass: HomeAssistant, error: Exception, message: str) -> None:
|
||||
"""Test to handle exceptions."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"pydiscovergy.Discovergy.meters",
|
||||
side_effect=error,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
CONF_EMAIL: "test@example.com",
|
||||
CONF_PASSWORD: "test-password",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": message}
|
||||
|
||||
with patch("pydiscovergy.Discovergy.meters", return_value=GET_METERS):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
@ -102,5 +113,6 @@ async def test_form_fail(hass: HomeAssistant, error: Exception, message: str) ->
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["errors"] == {"base": message}
|
||||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "test@example.com"
|
||||
assert "errors" not in result
|
||||
|
Loading…
x
Reference in New Issue
Block a user