mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use reauth_confirm in azure_devops (#128349)
This commit is contained in:
parent
7df973648c
commit
c4e2e9c4f0
@ -42,17 +42,6 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
errors=errors or {},
|
||||
)
|
||||
|
||||
async def _show_reauth_form(self, errors: dict[str, str]) -> ConfigFlowResult:
|
||||
"""Show the reauth form to the user."""
|
||||
return self.async_show_form(
|
||||
step_id="reauth",
|
||||
description_placeholders={
|
||||
"project_url": f"{self._organization}/{self._project}"
|
||||
},
|
||||
data_schema=vol.Schema({vol.Required(CONF_PAT): str}),
|
||||
errors=errors or {},
|
||||
)
|
||||
|
||||
async def _check_setup(self) -> dict[str, str] | None:
|
||||
"""Check the setup of the flow."""
|
||||
errors: dict[str, str] = {}
|
||||
@ -106,13 +95,16 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self.context["title_placeholders"] = {
|
||||
"project_url": f"{self._organization}/{self._project}",
|
||||
}
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
await self.async_set_unique_id(f"{self._organization}_{self._project}")
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
self, user_input: dict[str, str] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle configuration by re-auth."""
|
||||
errors: dict[str, str] | None = None
|
||||
if user_input is not None:
|
||||
errors = await self._check_setup()
|
||||
if errors is not None:
|
||||
return await self._show_reauth_form(errors)
|
||||
|
||||
if errors is None:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self._get_reauth_entry(),
|
||||
data={
|
||||
@ -122,6 +114,14 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
},
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
description_placeholders={
|
||||
"project_url": f"{self._organization}/{self._project}"
|
||||
},
|
||||
data_schema=vol.Schema({vol.Required(CONF_PAT): str}),
|
||||
errors=errors or {},
|
||||
)
|
||||
|
||||
def _async_create_entry(self) -> ConfigFlowResult:
|
||||
"""Handle create entry."""
|
||||
|
@ -16,7 +16,7 @@
|
||||
"description": "Set up an Azure DevOps instance to access your project. A Personal Access Token is only required for a private project.",
|
||||
"title": "Add Azure DevOps Project"
|
||||
},
|
||||
"reauth": {
|
||||
"reauth_confirm": {
|
||||
"data": {
|
||||
"personal_access_token": "[%key:component::azure_devops::config::step::user::data::personal_access_token%]"
|
||||
},
|
||||
|
@ -62,7 +62,7 @@ async def test_reauth_authorization_error(
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth"
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
@ -71,7 +71,7 @@ async def test_reauth_authorization_error(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "reauth"
|
||||
assert result2["step_id"] == "reauth_confirm"
|
||||
assert result2["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ async def test_reauth_connection_error(
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth"
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
@ -123,7 +123,7 @@ async def test_reauth_connection_error(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "reauth"
|
||||
assert result2["step_id"] == "reauth_confirm"
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ async def test_reauth_project_error(
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth"
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
@ -179,7 +179,7 @@ async def test_reauth_project_error(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "reauth"
|
||||
assert result2["step_id"] == "reauth_confirm"
|
||||
assert result2["errors"] == {"base": "project_error"}
|
||||
|
||||
|
||||
@ -197,8 +197,7 @@ async def test_reauth_flow(
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth"
|
||||
assert result["errors"] == {"base": "invalid_auth"}
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
mock_devops_client.authorize.return_value = True
|
||||
mock_devops_client.authorized = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user