mirror of
https://github.com/home-assistant/core.git
synced 2026-11-06 05:32:45 -04:00
data grand lyon: implement reconfiguration flow (#170210)
This commit is contained in:
@@ -193,6 +193,81 @@ async def test_form_already_configured(
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_reconfigure_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_get_tcl_passages: AsyncMock,
|
||||
) -> None:
|
||||
"""Test the reconfigure flow updates credentials and preserves subentries."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
original_subentries = dict(mock_config_entry.subentries)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reconfigure"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_PASSWORD: "new-pass"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data == {
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "new-pass",
|
||||
}
|
||||
assert dict(mock_config_entry.subentries) == original_subentries
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "error"),
|
||||
[
|
||||
(ClientConnectionError(), "cannot_connect"),
|
||||
(ClientResponseError(None, None, status=401), "invalid_auth"),
|
||||
(ClientResponseError(None, None, status=500), "cannot_connect"),
|
||||
(RuntimeError("unexpected"), "unknown"),
|
||||
],
|
||||
ids=["connection-error", "auth-401", "http-500", "unknown"],
|
||||
)
|
||||
async def test_reconfigure_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_get_tcl_passages: AsyncMock,
|
||||
side_effect: Exception,
|
||||
error: str,
|
||||
) -> None:
|
||||
"""Test the reconfigure flow shows errors and recovers."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
mock_get_tcl_passages.side_effect = side_effect
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_PASSWORD: "new-pass"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reconfigure"
|
||||
assert result["errors"] == {"base": error}
|
||||
|
||||
mock_get_tcl_passages.side_effect = None
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_PASSWORD: "new-pass"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data == {
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "new-pass",
|
||||
}
|
||||
|
||||
|
||||
# Stop subentry tests
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user