From 806242093d2f5d12f8b897f683204a4998be0524 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Thu, 28 Oct 2021 14:55:14 -0600 Subject: [PATCH] Add missing SimpliSafe config flow test (#58563) --- .../components/simplisafe/test_config_flow.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/components/simplisafe/test_config_flow.py b/tests/components/simplisafe/test_config_flow.py index 4546b7d3383..99943497556 100644 --- a/tests/components/simplisafe/test_config_flow.py +++ b/tests/components/simplisafe/test_config_flow.py @@ -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(