Use start_reauth helper method in integration tests (u-z) (#124796)

This commit is contained in:
epenet 2024-08-28 16:51:16 +02:00 committed by GitHub
parent 9bcc31a9fe
commit edad766fd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 59 additions and 285 deletions

View File

@ -24,7 +24,6 @@ from homeassistant.components.unifi.const import (
CONF_TRACK_WIRED_CLIENTS,
DOMAIN as UNIFI_DOMAIN,
)
from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
@ -302,15 +301,7 @@ async def test_reauth_flow_update_configuration(
"""Verify reauth flow can update hub configuration."""
config_entry = config_entry_setup
result = await hass.config_entries.flow.async_init(
UNIFI_DOMAIN,
context={
"source": SOURCE_REAUTH,
"unique_id": config_entry.unique_id,
"entry_id": config_entry.entry_id,
},
data=config_entry.data,
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
@ -344,15 +335,7 @@ async def test_reauth_flow_update_configuration_on_not_loaded_entry(
with patch("aiounifi.Controller.login", side_effect=aiounifi.errors.RequestError):
config_entry = await config_entry_factory()
result = await hass.config_entries.flow.async_init(
UNIFI_DOMAIN,
context={
"source": SOURCE_REAUTH,
"unique_id": config_entry.unique_id,
"entry_id": config_entry.entry_id,
},
data=config_entry.data,
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

View File

@ -224,13 +224,7 @@ async def test_form_reauth_auth(
)
mock_config.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": mock_config.entry_id,
},
)
result = await mock_config.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert not result["errors"]
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)

View File

@ -168,15 +168,7 @@ async def test_reauthentication(
old_entry = MockConfigEntry(**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA)
old_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": old_entry.unique_id,
"entry_id": old_entry.entry_id,
},
data=old_entry.data,
)
result = await old_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] is None
@ -209,15 +201,7 @@ async def test_reauthentication_failure(
old_entry = MockConfigEntry(**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA)
old_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": old_entry.unique_id,
"entry_id": old_entry.entry_id,
},
data=old_entry.data,
)
result = await old_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] is None
@ -253,15 +237,7 @@ async def test_reauthentication_failure_no_existing_entry(
)
old_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": old_entry.unique_id,
"entry_id": old_entry.entry_id,
},
data=old_entry.data,
)
result = await old_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] is None
@ -294,15 +270,7 @@ async def test_reauthentication_failure_account_not_matching(
old_entry = MockConfigEntry(**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA)
old_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": old_entry.unique_id,
"entry_id": old_entry.entry_id,
},
data=old_entry.data,
)
result = await old_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] is None

View File

@ -352,15 +352,7 @@ async def test_reauth_flow(
"""Test a reauthentication flow."""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": mock_config_entry.unique_id,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reauth_flow(hass)
assert result.get("step_id") == "reauth_confirm"
assert result.get("type") is FlowResultType.FORM
assert result.get("errors") == {}
@ -395,15 +387,7 @@ async def test_reauth_flow_with_mfa(
"""Test a reauthentication flow."""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": mock_config_entry.unique_id,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reauth_flow(hass)
assert result.get("step_id") == "reauth_confirm"
assert result.get("type") is FlowResultType.FORM
assert result.get("errors") == {}
@ -466,15 +450,7 @@ async def test_reauth_flow_errors(
"""Test a reauthentication flow."""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": mock_config_entry.unique_id,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reauth_flow(hass)
mock_verisure_config_flow.login.side_effect = side_effect
result2 = await hass.config_entries.flow.async_configure(

View File

@ -11,7 +11,7 @@ from syrupy.assertion import SnapshotAssertion
from homeassistant.components import dhcp
from homeassistant.components.vicare.const import DOMAIN
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER
from homeassistant.const import CONF_CLIENT_ID, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -104,11 +104,7 @@ async def test_step_reauth(hass: HomeAssistant, mock_setup_entry: AsyncMock) ->
)
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": config_entry.entry_id},
data=VALID_CONFIG,
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -153,15 +153,7 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
entry = MockConfigEntry(domain=DOMAIN, data=entry_data)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
"unique_id": entry.unique_id,
},
data=entry_data,
)
result = await entry.start_reauth_flow(hass)
with (
patch("homeassistant.components.vlc_telnet.config_flow.Client.connect"),
@ -209,15 +201,7 @@ async def test_reauth_errors(
entry = MockConfigEntry(domain=DOMAIN, data=entry_data)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
"unique_id": entry.unique_id,
},
data=entry_data,
)
result = await entry.start_reauth_flow(hass)
with (
patch(

View File

@ -7,7 +7,7 @@ import pytest
from homeassistant.components.device_tracker import CONF_CONSIDER_HOME
from homeassistant.components.vodafone_station.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -124,6 +124,9 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
mock_config = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
mock_config.add_to_hass(hass)
result = await mock_config.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
with (
patch(
@ -136,15 +139,6 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
"homeassistant.components.vodafone_station.async_setup_entry",
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": mock_config.entry_id},
data=mock_config.data,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
@ -172,6 +166,10 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
mock_config = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
mock_config.add_to_hass(hass)
result = await mock_config.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
with (
patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
@ -184,15 +182,6 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
"homeassistant.components.vodafone_station.async_setup_entry",
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": mock_config.entry_id},
data=mock_config.data,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={

View File

@ -153,13 +153,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
)
first_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": first_entry.entry_id,
},
)
result = await first_entry.start_reauth_flow(hass)
# the first form is just the confirmation prompt
assert result["type"] is FlowResultType.FORM

View File

@ -137,14 +137,13 @@ async def test_config_flow_reauth_success(
mock_student.return_value = [
Student.load(load_fixture("fake_student_1.json", "vulcan"))
]
MockConfigEntry(
entry = MockConfigEntry(
domain=const.DOMAIN,
unique_id="0",
data={"student_id": "0"},
).add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
const.DOMAIN, context={"source": config_entries.SOURCE_REAUTH}
)
entry.add_to_hass(hass)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -176,14 +175,13 @@ async def test_config_flow_reauth_without_matching_entries(
mock_student.return_value = [
Student.load(load_fixture("fake_student_1.json", "vulcan"))
]
MockConfigEntry(
entry = MockConfigEntry(
domain=const.DOMAIN,
unique_id="0",
data={"student_id": "1"},
).add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
const.DOMAIN, context={"source": config_entries.SOURCE_REAUTH}
)
entry.add_to_hass(hass)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -206,9 +204,13 @@ async def test_config_flow_reauth_with_errors(
"""Test reauth config flow with errors."""
mock_keystore.return_value = fake_keystore
mock_account.return_value = fake_account
result = await hass.config_entries.flow.async_init(
const.DOMAIN, context={"source": config_entries.SOURCE_REAUTH}
entry = MockConfigEntry(
domain=const.DOMAIN,
unique_id="0",
data={"student_id": "0"},
)
entry.add_to_hass(hass)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
assert result["errors"] == {}

View File

@ -160,13 +160,7 @@ async def test_form_reauth(hass: HomeAssistant, entry: MockConfigEntry) -> None:
status_code=200,
)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
},
)
result = await entry.start_reauth_flow(hass)
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@ -201,13 +195,7 @@ async def test_form_reauth_invalid(hass: HomeAssistant, entry: MockConfigEntry)
status_code=200,
)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
},
)
result = await entry.start_reauth_flow(hass)
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],

View File

@ -25,6 +25,8 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
@pytest.mark.parametrize(
("exc", "error"),
@ -144,21 +146,16 @@ async def test_show_form_user(hass: HomeAssistant) -> None:
async def test_step_reauth(
hass: HomeAssistant, config_auth, config_coordinates, config_entry, setup_watttime
hass: HomeAssistant,
config_entry: MockConfigEntry,
setup_watttime,
) -> None:
"""Test a full reauth flow."""
result = await config_entry.start_reauth_flow(hass)
with patch(
"homeassistant.components.watttime.async_setup_entry",
return_value=True,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH},
data={
**config_auth,
**config_coordinates,
},
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_PASSWORD: "password"},

View File

@ -4,7 +4,7 @@ import pytest
from homeassistant import config_entries
from homeassistant.components.weatherflow_cloud.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_API_TOKEN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -111,11 +111,7 @@ async def test_reauth(hass: HomeAssistant, mock_get_stations_401_error) -> None:
assert not await hass.config_entries.async_setup(entry.entry_id)
assert entry.state is ConfigEntryState.SETUP_ERROR
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": entry.entry_id},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -302,11 +302,7 @@ async def test_reauth_successful(
entry = await setup_webostv(hass)
assert client
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH, "entry_id": entry.entry_id},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"])
@ -339,11 +335,7 @@ async def test_reauth_errors(
entry = await setup_webostv(hass)
assert client
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH, "entry_id": entry.entry_id},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"])

View File

@ -235,15 +235,7 @@ async def test_reauth_flow(hass: HomeAssistant, region, brand) -> None:
)
mock_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": mock_entry.unique_id,
"entry_id": mock_entry.entry_id,
},
data=CONFIG_INPUT | {"region": region[0], "brand": brand[0]},
)
result = await mock_entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
@ -294,21 +286,7 @@ async def test_reauth_flow_auth_error(hass: HomeAssistant, region, brand) -> Non
)
mock_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": mock_entry.unique_id,
"entry_id": mock_entry.entry_id,
},
data={
CONF_USERNAME: "test-username",
CONF_PASSWORD: "new-password",
"region": region[0],
"brand": brand[0],
},
)
result = await mock_entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}
@ -345,15 +323,7 @@ async def test_reauth_flow_connnection_error(
)
mock_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": mock_entry.unique_id,
"entry_id": mock_entry.entry_id,
},
data=CONFIG_INPUT | {"region": region[0], "brand": brand[0]},
)
result = await mock_entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM

View File

@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, patch
import pytest
from homeassistant.components.withings.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import config_entry_oauth2_flow
@ -145,14 +145,7 @@ async def test_config_reauth_profile(
"""Test reauth an existing profile reauthenticates the config entry."""
await setup_integration(hass, polling_config_entry)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"entry_id": polling_config_entry.entry_id,
},
data=polling_config_entry.data,
)
result = await polling_config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -207,14 +200,7 @@ async def test_config_reauth_wrong_account(
"""Test reauth with wrong account."""
await setup_integration(hass, polling_config_entry)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"entry_id": polling_config_entry.entry_id,
},
data=polling_config_entry.data,
)
result = await polling_config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -1083,16 +1083,7 @@ async def test_async_step_reauth_abort_early(hass: HomeAssistant) -> None:
device = DeviceData()
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
"title_placeholders": {"name": entry.title},
"unique_id": entry.unique_id,
},
data=entry.data | {"device": device},
)
result = await entry.start_reauth_flow(hass, data={"device": device})
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"

View File

@ -976,11 +976,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.flow.async_init(
const.DOMAIN,
context={"source": config_entries.SOURCE_REAUTH},
data=config_entry.data,
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -132,15 +132,7 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": entry.unique_id,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}
@ -202,15 +194,7 @@ async def test_reauth_flow_error(
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": entry.unique_id,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
with patch(
"homeassistant.components.yale_smart_alarm.config_flow.YaleSmartAlarmClient",

View File

@ -945,11 +945,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
unique_id=YALE_ACCESS_LOCK_DISCOVERY_INFO.address,
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH, "entry_id": entry.entry_id},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_validate"

View File

@ -172,15 +172,7 @@ async def test_reauthentication(
)
old_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": old_entry.unique_id,
"entry_id": old_entry.entry_id,
},
data=old_entry.data,
)
result = await old_entry.start_reauth_flow(hass)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1