Use start_reauth helper method in config flow tests (a-d) (#124780)

* Use start_reauth helper method in integration tests (a-d)

* Revert broadlink

* Revert bthome
This commit is contained in:
epenet 2024-08-28 15:48:36 +02:00 committed by GitHub
parent 99335a07e5
commit bdd3aa8e39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 59 additions and 212 deletions

View File

@ -133,13 +133,7 @@ async def test_async_step_reauth_success(hass: HomeAssistant) -> None:
)
mock_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": mock_entry.entry_id,
},
)
result = await mock_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -179,13 +173,7 @@ async def test_async_step_reauth_exception(
)
mock_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": mock_entry.entry_id,
},
)
result = await mock_entry.start_reauth_flow(hass)
with patch(
"homeassistant.components.aseko_pool_live.config_flow.WebAccount.login",

View File

@ -173,14 +173,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
mock_entry.add_to_hass(hass)
# Test failed reauth
result5 = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": mock_entry.entry_id,
},
data=FAKE_DATA,
)
result5 = await mock_entry.start_reauth_flow(hass)
assert result5["step_id"] == "reauth_confirm"
with (

View File

@ -10,6 +10,8 @@ from homeassistant.components.blink import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form."""
@ -292,10 +294,11 @@ async def test_form_unknown_error(hass: HomeAssistant) -> None:
async def test_reauth_shows_user_step(hass: HomeAssistant) -> None:
"""Test reauth shows the user form."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH},
mock_entry = MockConfigEntry(
domain=DOMAIN,
data={"username": "blink@example.com", "password": "invalid_password"},
)
mock_entry.add_to_hass(hass)
result = await mock_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

View File

@ -129,6 +129,11 @@ async def test_reauth(
expected_api_token: str,
) -> None:
"""Test reauth flow."""
config_entry.add_to_hass(hass)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
with (
patch(
"homeassistant.components.blue_current.config_flow.Client.validate_api_token",
@ -146,20 +151,6 @@ async def test_reauth(
lambda self, on_data, on_open: hass.loop.create_future(),
),
):
config_entry.add_to_hass(hass)
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={"api_token": "123"},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={"api_token": "1234567890"},

View File

@ -188,15 +188,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
assert config_entry.data == config_entry_with_wrong_password["data"]
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"unique_id": config_entry.unique_id,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}

View File

@ -646,11 +646,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
title="shc012345",
)
mock_config.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_REAUTH},
data=mock_config.data,
)
result = await mock_config.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -17,7 +17,7 @@ from homeassistant.components.braviatv.const import (
DOMAIN,
NICKNAME_PREFIX,
)
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_SSDP, SOURCE_USER
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
from homeassistant.const import CONF_CLIENT_ID, CONF_HOST, CONF_MAC, CONF_PIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -405,6 +405,9 @@ async def test_reauth_successful(hass: HomeAssistant, use_psk, new_pin) -> None:
title="TV-Model",
)
config_entry.add_to_hass(hass)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "authorize"
with (
patch("pybravia.BraviaClient.connect"),
@ -421,15 +424,6 @@ async def test_reauth_successful(hass: HomeAssistant, use_psk, new_pin) -> None:
return_value={},
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": config_entry.entry_id},
data=config_entry.data,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "authorize"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_USE_PSK: use_psk}
)

View File

@ -10,7 +10,7 @@ from bring_api.exceptions import (
import pytest
from homeassistant.components.bring.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -123,15 +123,7 @@ async def test_flow_reauth(
bring_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"entry_id": bring_config_entry.entry_id,
"unique_id": bring_config_entry.unique_id,
},
)
result = await bring_config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -171,15 +163,7 @@ async def test_flow_reauth_error_and_recover(
bring_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"entry_id": bring_config_entry.entry_id,
"unique_id": bring_config_entry.unique_id,
},
)
result = await bring_config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -110,15 +110,7 @@ async def test_reauth(
unique_id="test-username",
)
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=None,
)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
with patch(

View File

@ -106,13 +106,7 @@ async def test_reauth_success(
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -147,13 +141,7 @@ async def test_reauth_failure(
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.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 MagicMock
import pycfdns
from homeassistant.components.cloudflare.const import CONF_RECORDS, DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_TOKEN, CONF_SOURCE, CONF_ZONE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -151,15 +151,7 @@ async def test_reauth_flow(hass: HomeAssistant, cfupdate_flow: MagicMock) -> Non
entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"unique_id": entry.unique_id,
"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

@ -7,7 +7,7 @@ from aiocomelit import CannotAuthenticate, CannotConnect
import pytest
from homeassistant.components.comelit.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_PIN, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -100,6 +100,9 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
mock_config = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_BRIDGE_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(
@ -113,15 +116,6 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
):
mock_request_get.return_value.status_code = 200
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={
@ -147,6 +141,9 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
mock_config = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_BRIDGE_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("aiocomelit.api.ComeliteSerialBridgeApi.login", side_effect=side_effect),
@ -155,15 +152,6 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
),
patch("homeassistant.components.comelit.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

@ -22,12 +22,7 @@ from homeassistant.components.deconz.const import (
)
from homeassistant.components.hassio import HassioServiceInfo
from homeassistant.components.ssdp import ATTR_UPNP_MANUFACTURER_URL, ATTR_UPNP_SERIAL
from homeassistant.config_entries import (
SOURCE_HASSIO,
SOURCE_REAUTH,
SOURCE_SSDP,
SOURCE_USER,
)
from homeassistant.config_entries import SOURCE_HASSIO, SOURCE_SSDP, SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -407,12 +402,7 @@ async def test_reauth_flow_update_configuration(
config_entry_setup: MockConfigEntry,
) -> None:
"""Verify reauth flow can update gateway API key."""
result = await hass.config_entries.flow.async_init(
DECONZ_DOMAIN,
data=config_entry_setup.data,
context={"source": SOURCE_REAUTH},
)
result = await config_entry_setup.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "link"

View File

@ -5,7 +5,7 @@ from unittest.mock import patch
import pytest
from homeassistant.components.deluge.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_SOURCE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -113,16 +113,7 @@ async def test_flow_reauth(hass: HomeAssistant, api) -> None:
entry.add_to_hass(hass)
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=CONF_DATA,
)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

View File

@ -164,21 +164,17 @@ async def test_zeroconf_wrong_device(hass: HomeAssistant) -> None:
async def test_form_reauth(hass: HomeAssistant) -> None:
"""Test that the reauth confirmation form is served."""
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
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,
},
mock_config = MockConfigEntry(
domain=DOMAIN,
unique_id="123456",
data={
"username": "test-username",
"password": "test-password",
"mydevolo_url": "https://test_mydevolo_url.test",
},
)
mock_config.add_to_hass(hass)
result = await mock_config.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
@ -205,20 +201,17 @@ async def test_form_reauth(hass: HomeAssistant) -> None:
@pytest.mark.parametrize("credentials_valid", [False])
async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None:
"""Test if we get the error message on invalid credentials."""
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
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,
},
mock_config = MockConfigEntry(
domain=DOMAIN,
unique_id="123456",
data={
"username": "test-username",
"password": "test-password",
"mydevolo_url": "https://test_mydevolo_url.test",
},
)
mock_config.add_to_hass(hass)
result = await mock_config.start_reauth_flow(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
@ -230,20 +223,17 @@ async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None:
async def test_form_uuid_change_reauth(hass: HomeAssistant) -> None:
"""Test that the reauth confirmation form is served."""
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
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,
},
mock_config = MockConfigEntry(
domain=DOMAIN,
unique_id="123456",
data={
"username": "test-username",
"password": "test-password",
"mydevolo_url": "https://test_mydevolo_url.test",
},
)
mock_config.add_to_hass(hass)
result = await mock_config.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM

View File

@ -179,18 +179,7 @@ async def test_form_reauth(hass: HomeAssistant) -> None:
entry = configure_integration(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
"title_placeholders": {
CONF_NAME: DISCOVERY_INFO.hostname.split(".")[0],
},
},
data=entry.data,
)
result = await entry.start_reauth_flow(hass)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM

View File

@ -5,7 +5,6 @@ from unittest.mock import AsyncMock, Mock, patch
import nextcord
from homeassistant.components.discord.const import DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_TOKEN, CONF_NAME
from homeassistant.core import HomeAssistant
@ -22,7 +21,7 @@ CONF_DATA = {
}
def create_entry(hass: HomeAssistant) -> ConfigEntry:
def create_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Add config entry in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,

View File

@ -4,7 +4,7 @@ import nextcord
from homeassistant import config_entries
from homeassistant.components.discord.const import DOMAIN
from homeassistant.const import CONF_API_TOKEN, CONF_SOURCE
from homeassistant.const import CONF_API_TOKEN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -123,16 +123,7 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
async def test_flow_reauth(hass: HomeAssistant) -> None:
"""Test a reauth flow."""
entry = create_entry(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
CONF_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)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"

View File

@ -310,11 +310,7 @@ async def test_reauth(hass: HomeAssistant) -> None:
data={"address": DKEY_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_confirm"