Use start_reauth helper method in integration tests (p-r) (#124792)

pull/124396/head^2
epenet 2024-08-28 16:20:47 +02:00 committed by GitHub
parent 5824d06fd7
commit ef4caa951c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 61 additions and 257 deletions

View File

@ -60,7 +60,7 @@ async def test_form(hass: HomeAssistant, mock_setup_entry) -> None:
async def test_reauth(
hass: HomeAssistant, mock_setup_entry, mock_config_entry, mock_tv
hass: HomeAssistant, mock_setup_entry, mock_config_entry: MockConfigEntry, mock_tv
) -> None:
"""Test we get the form."""
@ -69,15 +69,7 @@ async def test_reauth(
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert len(mock_setup_entry.mock_calls) == 1
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["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

View File

@ -170,16 +170,15 @@ async def test_step_reauth(hass: HomeAssistant, picnic_api) -> None:
# Create a mocked config entry
conf = {CONF_ACCESS_TOKEN: "a3p98fsen.a39p3fap", CONF_COUNTRY_CODE: "NL"}
MockConfigEntry(
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=picnic_api().get_user()["user_id"],
data=conf,
).add_to_hass(hass)
)
entry.add_to_hass(hass)
# Init a re-auth flow
result_init = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=conf
)
result_init = await entry.start_reauth_flow(hass)
assert result_init["type"] is FlowResultType.FORM
assert result_init["step_id"] == "user"
@ -210,16 +209,15 @@ async def test_step_reauth_failed(hass: HomeAssistant) -> None:
user_id = "f29-2a6-o32n"
conf = {CONF_ACCESS_TOKEN: "a3p98fsen.a39p3fap", CONF_COUNTRY_CODE: "NL"}
MockConfigEntry(
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=user_id,
data=conf,
).add_to_hass(hass)
)
entry.add_to_hass(hass)
# Init a re-auth flow
result_init = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=conf
)
result_init = await entry.start_reauth_flow(hass)
assert result_init["type"] is FlowResultType.FORM
assert result_init["step_id"] == "user"
@ -249,16 +247,15 @@ async def test_step_reauth_different_account(hass: HomeAssistant, picnic_api) ->
# Create a mocked config entry, unique_id should be different that the user id in the api response
conf = {CONF_ACCESS_TOKEN: "a3p98fsen.a39p3fap", CONF_COUNTRY_CODE: "NL"}
MockConfigEntry(
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="3fpawh-ues-af3ho",
data=conf,
).add_to_hass(hass)
)
entry.add_to_hass(hass)
# Init a re-auth flow
result_init = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=conf
)
result_init = await entry.start_reauth_flow(hass)
assert result_init["type"] is FlowResultType.FORM
assert result_init["step_id"] == "user"

View File

@ -26,7 +26,6 @@ from homeassistant.components.plex.const import (
)
from homeassistant.config_entries import (
SOURCE_INTEGRATION_DISCOVERY,
SOURCE_REAUTH,
SOURCE_USER,
ConfigEntryState,
)
@ -744,11 +743,7 @@ async def test_reauth(
"""Test setup and reauthorization of a Plex token."""
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
flow_id = result["flow_id"]
with (
@ -795,11 +790,7 @@ async def test_reauth_multiple_servers_available(
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
flow_id = result["flow_id"]

View File

@ -336,11 +336,7 @@ async def test_form_reauth(hass: HomeAssistant) -> None:
)
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["errors"] == {}

View File

@ -143,15 +143,7 @@ async def test_reauth_flow(hass: HomeAssistant, mock_list_contracts) -> 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"] == {}
@ -208,15 +200,7 @@ async def test_reauth_flow_error(hass: HomeAssistant, exception, base_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.prosegur.config_flow.Installation.list",

View File

@ -6,13 +6,15 @@ from aiopurpleair.errors import InvalidApiKeyError, PurpleAirError
import pytest
from homeassistant.components.purpleair 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 device_registry as dr
from .conftest import TEST_API_KEY, TEST_SENSOR_INDEX1, TEST_SENSOR_INDEX2
from tests.common import MockConfigEntry
TEST_LATITUDE = 51.5285582
TEST_LONGITUDE = -0.2416796
@ -127,19 +129,11 @@ async def test_reauth(
mock_aiopurpleair,
check_api_key_errors,
check_api_key_mock,
config_entry,
config_entry: MockConfigEntry,
setup_config_entry,
) -> None:
"""Test re-auth (including errors)."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"entry_id": config_entry.entry_id,
"unique_id": config_entry.unique_id,
},
data={"api_key": TEST_API_KEY},
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -149,14 +149,7 @@ async def test_reauth_success(hass: HomeAssistant) -> None:
)
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=MOCK_CONFIG,
)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -180,14 +173,7 @@ async def test_reauth_failed(hass: HomeAssistant, mock_pushover: MagicMock) -> N
)
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=MOCK_CONFIG,
)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -223,14 +209,7 @@ async def test_reauth_with_existing_config(hass: HomeAssistant) -> None:
)
entry2.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=MOCK_CONFIG,
)
result = await entry2.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, MagicMock
from pvo import PVOutputAuthenticationError, PVOutputConnectionError
from homeassistant.components.pvoutput.const import CONF_SYSTEM_ID, DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -150,15 +150,7 @@ async def test_reauth_flow(
"""Test the reauthentication configuration flow."""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": 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("type") is FlowResultType.FORM
assert result.get("step_id") == "reauth_confirm"
@ -192,15 +184,7 @@ async def test_reauth_with_authentication_error(
"""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": 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("type") is FlowResultType.FORM
assert result.get("step_id") == "reauth_confirm"
@ -244,15 +228,7 @@ async def test_reauth_api_error(
"""Test API error during reauthentication."""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": 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("type") is FlowResultType.FORM
assert result.get("step_id") == "reauth_confirm"

View File

@ -6,12 +6,7 @@ from pyloadapi.exceptions import CannotConnect, InvalidAuth, ParserError
import pytest
from homeassistant.components.pyload.const import DEFAULT_NAME, DOMAIN
from homeassistant.config_entries import (
SOURCE_IMPORT,
SOURCE_REAUTH,
SOURCE_RECONFIGURE,
SOURCE_USER,
)
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_RECONFIGURE, SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -180,14 +175,7 @@ async def test_reauth(
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,
"unique_id": config_entry.unique_id,
},
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -222,14 +210,7 @@ async def test_reauth_errors(
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,
"unique_id": config_entry.unique_id,
},
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -6,7 +6,7 @@ from aiopyarr import exceptions
import pytest
from homeassistant.components.radarr.const import DEFAULT_NAME, DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_SOURCE, CONF_URL, CONF_VERIFY_SSL
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -143,15 +143,7 @@ async def test_full_reauth_flow_implementation(
) -> None:
"""Test the manual reauth flow from start to finish."""
entry = await setup_integration(hass, aioclient_mock)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
CONF_SOURCE: SOURCE_REAUTH,
"entry_id": entry.entry_id,
"unique_id": entry.unique_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

@ -13,15 +13,12 @@ from homeassistant.components.renault.const import (
CONF_LOCALE,
DOMAIN,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import aiohttp_client
from .const import MOCK_CONFIG
from tests.common import load_fixture
from tests.common import MockConfigEntry, load_fixture
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@ -220,19 +217,11 @@ async def test_config_flow_duplicate(
assert len(mock_setup_entry.mock_calls) == 0
async def test_reauth(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
async def test_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Test the start of the config flow."""
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": config_entry.entry_id,
"unique_id": config_entry.unique_id,
},
data=MOCK_CONFIG,
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["description_placeholders"] == {CONF_USERNAME: "email@test.com"}

View File

@ -327,16 +327,7 @@ async def test_reauth(hass: HomeAssistant, mock_setup_entry: MagicMock) -> 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,
"entry_id": config_entry.entry_id,
"title_placeholders": {"name": TEST_NVR_NAME},
"unique_id": format_mac(TEST_MAC),
},
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

@ -13,6 +13,8 @@ from homeassistant.data_entry_flow import FlowResultType
from .conftest import TEST_PASSWORD, TEST_USERNAME
from tests.common import MockConfigEntry
@pytest.mark.parametrize(
("get_client_response", "errors"),
@ -65,12 +67,10 @@ async def test_duplicate_error(hass: HomeAssistant, config, setup_config_entry)
async def test_step_reauth(
hass: HomeAssistant, config, config_entry, setup_config_entry
hass: HomeAssistant, config, config_entry: MockConfigEntry, setup_config_entry
) -> None:
"""Test a full reauth flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=config
)
result = await config_entry.start_reauth_flow(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_PASSWORD: "new_password"},

View File

@ -154,14 +154,12 @@ async def test_form_cloud_already_exists(hass: HomeAssistant) -> None:
assert result3["reason"] == "already_configured"
async def test_form_reauth(hass: HomeAssistant, cloud_config_entry) -> None:
async def test_form_reauth(
hass: HomeAssistant, cloud_config_entry: MockConfigEntry
) -> None:
"""Test reauthenticate."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH},
data=cloud_config_entry.data,
)
result = await cloud_config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}
@ -194,15 +192,11 @@ async def test_form_reauth(hass: HomeAssistant, cloud_config_entry) -> None:
async def test_form_reauth_with_new_username(
hass: HomeAssistant, cloud_config_entry
hass: HomeAssistant, cloud_config_entry: MockConfigEntry
) -> None:
"""Test reauthenticate with new username."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH},
data=cloud_config_entry.data,
)
result = await cloud_config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}

View File

@ -83,15 +83,7 @@ async def test_form_user_reauth(hass: HomeAssistant) -> None:
entry = mock_config_entry()
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)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
@ -121,15 +113,7 @@ async def test_form_user_reauth_different_unique_id(hass: HomeAssistant) -> None
entry = mock_config_entry()
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)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
@ -161,15 +145,7 @@ async def test_form_user_reauth_invalid_auth(hass: HomeAssistant) -> None:
entry = mock_config_entry()
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)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
@ -201,15 +177,7 @@ async def test_form_user_reauth_cannot_connect(hass: HomeAssistant) -> None:
entry = mock_config_entry()
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)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
@ -241,15 +209,7 @@ async def test_form_user_reauth_general_exception(hass: HomeAssistant) -> None:
entry = mock_config_entry()
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)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1

View File

@ -160,17 +160,10 @@ async def test_form_already_exists(hass: HomeAssistant, config_entry) -> None:
assert result2["reason"] == "already_configured"
async def test_form_reauth(hass: HomeAssistant, config_entry) -> None:
async def test_form_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Test reauthentication."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"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["errors"] is None
@ -203,17 +196,12 @@ async def test_form_reauth(hass: HomeAssistant, config_entry) -> None:
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_reauth_with_new_account(hass: HomeAssistant, config_entry) -> None:
async def test_form_reauth_with_new_account(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test reauthentication with new account."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"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["errors"] is None