Skip to content

Commit

Permalink
Use reauth_confirm in azure_devops (home-assistant#128349)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 14, 2024
1 parent 7df9736 commit c4e2e9c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
48 changes: 24 additions & 24 deletions homeassistant/components/azure_devops/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ async def _show_setup_form(
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] = {}
Expand Down Expand Up @@ -106,22 +95,33 @@ async def async_step_reauth(
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}")

errors = await self._check_setup()
if errors is not None:
return await self._show_reauth_form(errors)

self.hass.config_entries.async_update_entry(
self._get_reauth_entry(),
data={
CONF_ORG: self._organization,
CONF_PROJECT: self._project,
CONF_PAT: self._pat,
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 None:
self.hass.config_entries.async_update_entry(
self._get_reauth_entry(),
data={
CONF_ORG: self._organization,
CONF_PROJECT: self._project,
CONF_PAT: self._pat,
},
)
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 {},
)
return self.async_abort(reason="reauth_successful")

def _async_create_entry(self) -> ConfigFlowResult:
"""Handle create entry."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/azure_devops/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]"
},
Expand Down
15 changes: 7 additions & 8 deletions tests/components/azure_devops/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"}


Expand Down Expand Up @@ -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"],
Expand All @@ -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"}


Expand Down Expand Up @@ -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"],
Expand All @@ -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"}


Expand All @@ -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
Expand Down

0 comments on commit c4e2e9c

Please sign in to comment.