Add missing SimpliSafe config flow test (#58563)

This commit is contained in:
Aaron Bach 2021-10-28 14:55:14 -06:00 committed by GitHub
parent f619a8e4a0
commit 806242093d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -180,6 +180,45 @@ async def test_step_reauth_new_format(hass, mock_async_from_auth):
assert config_entry.data == {CONF_USER_ID: "12345", CONF_TOKEN: "token123"}
async def test_step_reauth_wrong_account(hass, api, mock_async_from_auth):
"""Test the re-auth step returning a different account from this one."""
MockConfigEntry(
domain=DOMAIN,
unique_id="12345",
data={
CONF_USER_ID: "12345",
CONF_TOKEN: "token123",
},
).add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH},
data={CONF_USER_ID: "12345", CONF_TOKEN: "token123"},
)
assert result["step_id"] == "user"
# Simulate the next auth call returning a different user ID than the one we've
# identified as this entry's unique ID:
api.user_id = "67890"
with patch(
"homeassistant.components.simplisafe.async_setup_entry", return_value=True
), patch("homeassistant.config_entries.ConfigEntries.async_reload"):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_AUTH_CODE: "code123"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "wrong_account"
assert len(hass.config_entries.async_entries()) == 1
[config_entry] = hass.config_entries.async_entries(DOMAIN)
assert config_entry.unique_id == "12345"
async def test_step_user(hass, mock_async_from_auth):
"""Test the user step."""
result = await hass.config_entries.flow.async_init(