mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Add uuid as unique_id to config entries for Cookidoo (#134831)
This commit is contained in:
@@ -200,7 +200,12 @@ async def test_flow_reconfigure_success(
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={**MOCK_DATA_USER_STEP, CONF_COUNTRY: "DE"},
|
||||
user_input={
|
||||
**MOCK_DATA_USER_STEP,
|
||||
CONF_EMAIL: "new-email",
|
||||
CONF_PASSWORD: "new-password",
|
||||
CONF_COUNTRY: "DE",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
@@ -215,6 +220,8 @@ async def test_flow_reconfigure_success(
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert cookidoo_config_entry.data == {
|
||||
**MOCK_DATA_USER_STEP,
|
||||
CONF_EMAIL: "new-email",
|
||||
CONF_PASSWORD: "new-password",
|
||||
CONF_COUNTRY: "DE",
|
||||
CONF_LANGUAGE: "de-DE",
|
||||
}
|
||||
@@ -340,6 +347,35 @@ async def test_flow_reconfigure_init_data_unknown_error_and_recover_on_step_2(
|
||||
assert len(hass.config_entries.async_entries()) == 1
|
||||
|
||||
|
||||
async def test_flow_reconfigure_id_mismatch(
|
||||
hass: HomeAssistant,
|
||||
mock_cookidoo_client: AsyncMock,
|
||||
cookidoo_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test we abort when the new config is not for the same user."""
|
||||
|
||||
cookidoo_config_entry.add_to_hass(hass)
|
||||
hass.config_entries.async_update_entry(
|
||||
cookidoo_config_entry, unique_id="some_other_uuid"
|
||||
)
|
||||
|
||||
result = await cookidoo_config_entry.start_reconfigure_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
**MOCK_DATA_USER_STEP,
|
||||
CONF_EMAIL: "new-email",
|
||||
CONF_PASSWORD: "new-password",
|
||||
CONF_COUNTRY: "DE",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "unique_id_mismatch"
|
||||
|
||||
|
||||
async def test_flow_reauth(
|
||||
hass: HomeAssistant,
|
||||
mock_cookidoo_client: AsyncMock,
|
||||
@@ -419,46 +455,26 @@ async def test_flow_reauth_error_and_recover(
|
||||
assert len(hass.config_entries.async_entries()) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("new_email", "saved_email", "result_reason"),
|
||||
[
|
||||
(EMAIL, EMAIL, "reauth_successful"),
|
||||
("another-email", EMAIL, "already_configured"),
|
||||
],
|
||||
)
|
||||
async def test_flow_reauth_init_data_already_configured(
|
||||
async def test_flow_reauth_id_mismatch(
|
||||
hass: HomeAssistant,
|
||||
mock_cookidoo_client: AsyncMock,
|
||||
cookidoo_config_entry: MockConfigEntry,
|
||||
new_email: str,
|
||||
saved_email: str,
|
||||
result_reason: str,
|
||||
) -> None:
|
||||
"""Test we abort user data set when entry is already configured."""
|
||||
"""Test we abort when the new auth is not for the same user."""
|
||||
|
||||
cookidoo_config_entry.add_to_hass(hass)
|
||||
|
||||
another_cookidoo_config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_EMAIL: "another-email",
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_COUNTRY: COUNTRY,
|
||||
CONF_LANGUAGE: LANGUAGE,
|
||||
},
|
||||
hass.config_entries.async_update_entry(
|
||||
cookidoo_config_entry, unique_id="some_other_uuid"
|
||||
)
|
||||
|
||||
another_cookidoo_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await cookidoo_config_entry.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_EMAIL: new_email, CONF_PASSWORD: PASSWORD},
|
||||
{CONF_EMAIL: "new-email", CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == result_reason
|
||||
assert cookidoo_config_entry.data[CONF_EMAIL] == saved_email
|
||||
assert result["reason"] == "unique_id_mismatch"
|
||||
|
||||
Reference in New Issue
Block a user