mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 14:29:21 -04:00
Split user flow init and data submission in iqvia config flow tests (#183745)
This commit is contained in:
@@ -14,20 +14,44 @@ from homeassistant.data_entry_flow import FlowResultType
|
||||
async def test_duplicate_error(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=config
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert not result["errors"]
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_iqvia")
|
||||
async def test_invalid_zip_code(hass: HomeAssistant) -> None:
|
||||
"""Test that an invalid ZIP code key throws an error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_ZIP_CODE: "bad"}
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert not result["errors"]
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_ZIP_CODE: "bad"}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {CONF_ZIP_CODE: "invalid_zip_code"}
|
||||
|
||||
# recover
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_ZIP_CODE: "12345"}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "12345"
|
||||
assert result["data"] == {CONF_ZIP_CODE: "12345"}
|
||||
|
||||
|
||||
async def test_show_form(hass: HomeAssistant) -> None:
|
||||
"""Test that the form is served with no input."""
|
||||
@@ -42,7 +66,14 @@ async def test_show_form(hass: HomeAssistant) -> None:
|
||||
async def test_step_user(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||
"""Test that the user step works (without MFA)."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=config
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert not result["errors"]
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "12345"
|
||||
|
||||
Reference in New Issue
Block a user