Update UpCloud config entry data on successful reconfig (#68718)
* Update UpCloud config entry data on successful reconfig * Add already configured test * Improve success case request mocking So that the data fetch that might happen in the background after success won't trash the test log with misleading errors. * Simplify already configured test Thanks-to: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
ae7930c0ad
commit
0c51de25a2
3 changed files with 33 additions and 1 deletions
|
@ -55,6 +55,9 @@ class UpCloudConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="user", user_input=user_input, errors=errors
|
||||
)
|
||||
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_PASSWORD: user_input[CONF_PASSWORD]}
|
||||
)
|
||||
return self.async_create_entry(title=user_input[CONF_USERNAME], data=user_input)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
"password": "[%key:common::config_flow::data::password%]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
|
|
|
@ -72,7 +72,8 @@ async def test_success(
|
|||
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
||||
) -> None:
|
||||
"""Test successful flow provides entry creation data."""
|
||||
requests_mock.request(ANY, ANY, text='{"account":{"username":"user"}}')
|
||||
requests_mock.request(ANY, "/1.3/account", text='{"account":{"username":"user"}}')
|
||||
requests_mock.request(ANY, "/1.3/server", text='{"servers": {"server":[]}}')
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=FIXTURE_USER_INPUT
|
||||
)
|
||||
|
@ -105,3 +106,28 @@ async def test_options(hass: HomeAssistant) -> None:
|
|||
assert result["data"][CONF_SCAN_INTERVAL] == int(
|
||||
FIXTURE_USER_INPUT_OPTIONS[CONF_SCAN_INTERVAL]
|
||||
)
|
||||
|
||||
|
||||
async def test_already_configured(hass, requests_mock):
|
||||
"""Test duplicate entry aborts and updates data."""
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=FIXTURE_USER_INPUT[CONF_USERNAME],
|
||||
data=FIXTURE_USER_INPUT,
|
||||
options=FIXTURE_USER_INPUT_OPTIONS,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
new_user_input = FIXTURE_USER_INPUT.copy()
|
||||
new_user_input[CONF_PASSWORD] += "_changed"
|
||||
|
||||
requests_mock.request(ANY, "/1.3/account", text='{"account":{"username":"user"}}')
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=new_user_input
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert config_entry.data[CONF_USERNAME] == new_user_input[CONF_USERNAME]
|
||||
assert config_entry.data[CONF_PASSWORD] == new_user_input[CONF_PASSWORD]
|
||||
|
|
Loading…
Add table
Reference in a new issue