Add reconfigure step to holiday (#114057)
This commit is contained in:
@@ -219,3 +219,114 @@ async def test_form_babel_replace_dash_with_underscore(hass: HomeAssistant) -> N
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
}
|
||||
|
||||
|
||||
async def test_reconfigure(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||
"""Test reconfigure flow."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Germany, BW",
|
||||
data={"country": "DE", "province": "BW"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": config_entries.SOURCE_RECONFIGURE,
|
||||
"entry_id": entry.entry_id,
|
||||
},
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_PROVINCE: "NW",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
entry = hass.config_entries.async_get_entry(entry.entry_id)
|
||||
assert entry.title == "Germany, NW"
|
||||
assert entry.data == {"country": "DE", "province": "NW"}
|
||||
|
||||
|
||||
async def test_reconfigure_incorrect_language(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test reconfigure flow default to English."""
|
||||
hass.config.language = "en-XX"
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Germany, BW",
|
||||
data={"country": "DE", "province": "BW"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": config_entries.SOURCE_RECONFIGURE,
|
||||
"entry_id": entry.entry_id,
|
||||
},
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_PROVINCE: "NW",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
entry = hass.config_entries.async_get_entry(entry.entry_id)
|
||||
assert entry.title == "Germany, NW"
|
||||
assert entry.data == {"country": "DE", "province": "NW"}
|
||||
|
||||
|
||||
async def test_reconfigure_entry_exists(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test reconfigure flow stops if other entry already exist."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Germany, BW",
|
||||
data={"country": "DE", "province": "BW"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
entry2 = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Germany, NW",
|
||||
data={"country": "DE", "province": "NW"},
|
||||
)
|
||||
entry2.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": config_entries.SOURCE_RECONFIGURE,
|
||||
"entry_id": entry.entry_id,
|
||||
},
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_PROVINCE: "NW",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
entry = hass.config_entries.async_get_entry(entry.entry_id)
|
||||
assert entry.title == "Germany, BW"
|
||||
assert entry.data == {"country": "DE", "province": "BW"}
|
||||
|
||||
Reference in New Issue
Block a user