Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use start_reconfigure_flow in config flow tests #127191

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 5 additions & 37 deletions tests/components/brother/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

from homeassistant.components import zeroconf
from homeassistant.components.brother.const import DOMAIN
from homeassistant.config_entries import (
SOURCE_RECONFIGURE,
SOURCE_USER,
SOURCE_ZEROCONF,
)
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST, CONF_TYPE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -262,14 +258,7 @@ async def test_reconfigure_successful(
"""Test starting a reconfigure flow."""
await init_integration(hass, mock_config_entry)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
Expand Down Expand Up @@ -305,14 +294,7 @@ async def test_reconfigure_not_successful(
"""Test starting a reconfigure flow but no connection found."""
await init_integration(hass, mock_config_entry)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
Expand Down Expand Up @@ -351,14 +333,7 @@ async def test_reconfigure_invalid_hostname(
"""Test starting a reconfigure flow but no connection found."""
await init_integration(hass, mock_config_entry)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
Expand All @@ -381,14 +356,7 @@ async def test_reconfigure_not_the_same_device(
"""Test starting the reconfiguration process, but with a different printer."""
await init_integration(hass, mock_config_entry)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": mock_config_entry.entry_id,
},
data=mock_config_entry.data,
)
result = await mock_config_entry.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
Expand Down
8 changes: 1 addition & 7 deletions tests/components/bryant_evolution/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ async def test_reconfigure(
"""Test that reconfigure discovers additional systems and zones."""

# Reconfigure with additional systems and zones.
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_RECONFIGURE,
"entry_id": mock_evolution_entry.entry_id,
},
)
result = await mock_evolution_entry.start_reconfigure_flow(hass)
with (
patch.object(
BryantEvolutionLocalClient,
Expand Down
46 changes: 6 additions & 40 deletions tests/components/enphase_envoy/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
OPTION_DIAGNOSTICS_INCLUDE_FIXTURES,
OPTION_DIAGNOSTICS_INCLUDE_FIXTURES_DEFAULT_VALUE,
)
from homeassistant.config_entries import (
SOURCE_RECONFIGURE,
SOURCE_USER,
SOURCE_ZEROCONF,
)
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -698,13 +694,7 @@ async def test_reconfigure(
) -> None:
"""Test we can reconfiger the entry."""
await setup_integration(hass, config_entry)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["errors"] == {}
Expand Down Expand Up @@ -740,13 +730,7 @@ async def test_reconfigure_nochange(
) -> None:
"""Test we get the reconfigure form and apply nochange."""
await setup_integration(hass, config_entry)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["errors"] == {}
Expand Down Expand Up @@ -782,13 +766,7 @@ async def test_reconfigure_otherenvoy(
) -> None:
"""Test entering ip of other envoy and prevent changing it based on serial."""
await setup_integration(hass, config_entry)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["errors"] == {}
Expand Down Expand Up @@ -853,13 +831,7 @@ async def test_reconfigure_auth_failure(
"""Test changing credentials for existing host with auth failure."""
await setup_integration(hass, config_entry)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}

Expand Down Expand Up @@ -928,13 +900,7 @@ async def test_reconfigure_change_ip_to_existing(
assert other_entry.data[CONF_USERNAME] == "other-username"
assert other_entry.data[CONF_PASSWORD] == "other-password"

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": config_entry.entry_id,
},
)
result = await config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["errors"] == {}
Expand Down
20 changes: 3 additions & 17 deletions tests/components/feedreader/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DEFAULT_MAX_ENTRIES,
DOMAIN,
)
from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_URL
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -162,14 +162,7 @@ async def test_reconfigure(hass: HomeAssistant, feedparser) -> None:
await hass.async_block_till_done()

# init user flow
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"

Expand Down Expand Up @@ -201,14 +194,7 @@ async def test_reconfigure_errors(
entry.add_to_hass(hass)

# init user flow
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"

Expand Down
19 changes: 5 additions & 14 deletions tests/components/fritz/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
FRITZ_AUTH_EXCEPTIONS,
)
from homeassistant.components.ssdp import ATTR_UPNP_UDN
from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_SSDP, SOURCE_USER
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
Expand Down Expand Up @@ -452,14 +452,9 @@ async def test_reconfigure_successful(
mock_request_post.return_value.status_code = 200
mock_request_post.return_value.text = MOCK_REQUEST

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_RECONFIGURE,
"entry_id": mock_config.entry_id,
"show_advanced_options": show_advanced_options,
},
data=mock_config.data,
result = await mock_config.start_reconfigure_flow(
hass,
context={"show_advanced_options": show_advanced_options},
)

assert result["type"] is FlowResultType.FORM
Expand Down Expand Up @@ -514,11 +509,7 @@ async def test_reconfigure_not_successful(
mock_request_post.return_value.status_code = 200
mock_request_post.return_value.text = MOCK_REQUEST

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_RECONFIGURE, "entry_id": mock_config.entry_id},
data=mock_config.data,
)
result = await mock_config.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
Expand Down
14 changes: 3 additions & 11 deletions tests/components/fritzbox/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.components import ssdp
from homeassistant.components.fritzbox.const import DOMAIN
from homeassistant.components.ssdp import ATTR_UPNP_FRIENDLY_NAME, ATTR_UPNP_UDN
from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_SSDP, SOURCE_USER
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
from homeassistant.const import CONF_DEVICES, CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -196,11 +196,7 @@ async def test_reconfigure_success(hass: HomeAssistant, fritz: Mock) -> None:
assert mock_config.data[CONF_USERNAME] == "fake_user"
assert mock_config.data[CONF_PASSWORD] == "fake_pass"

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_RECONFIGURE, "entry_id": mock_config.entry_id},
data=mock_config.data,
)
result = await mock_config.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"

Expand Down Expand Up @@ -229,11 +225,7 @@ async def test_reconfigure_failed(hass: HomeAssistant, fritz: Mock) -> None:
assert mock_config.data[CONF_USERNAME] == "fake_user"
assert mock_config.data[CONF_PASSWORD] == "fake_pass"

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_RECONFIGURE, "entry_id": mock_config.entry_id},
data=mock_config.data,
)
result = await mock_config.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"

Expand Down
45 changes: 5 additions & 40 deletions tests/components/fronius/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,7 @@ async def test_reconfigure(hass: HomeAssistant) -> None:
)
entry.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure"

Expand Down Expand Up @@ -406,14 +399,7 @@ async def test_reconfigure_cannot_connect(hass: HomeAssistant) -> None:
)
entry.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)

with (
patch(
Expand Down Expand Up @@ -448,14 +434,7 @@ async def test_reconfigure_unexpected(hass: HomeAssistant) -> None:
)
entry.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)

with patch(
"pyfronius.Fronius.current_logger_info",
Expand Down Expand Up @@ -484,14 +463,7 @@ async def test_reconfigure_already_configured(hass: HomeAssistant) -> None:
)
entry.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure"

Expand Down Expand Up @@ -545,14 +517,7 @@ async def test_reconfigure_already_existing(hass: HomeAssistant) -> None:
)
entry_2.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_RECONFIGURE,
"entry_id": entry.entry_id,
},
data=entry.data,
)
result = await entry.start_reconfigure_flow(hass)
with patch(
"pyfronius.Fronius.current_logger_info",
return_value={"unique_identifier": {"value": entry_2_uid}},
Expand Down
Loading
Loading