Skip to content

Commit

Permalink
Use is in FlowResultType enum comparison in tests (home-assistant#114917
Browse files Browse the repository at this point in the history
)

* Use is in FlowResultType enum comparison in tests

* Adjust auth

* Adjust systemmonitor

* Once more

* Add comment
  • Loading branch information
epenet authored Apr 5, 2024
1 parent 04e5086 commit 24f83c5
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 147 deletions.
4 changes: 2 additions & 2 deletions tests/components/abode/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Exception as AbodeException,
)

from homeassistant import data_entry_flow
from homeassistant.components.abode import (
DOMAIN as ABODE_DOMAIN,
SERVICE_CAPTURE_IMAGE,
Expand All @@ -19,6 +18,7 @@
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

from .common import setup_platform

Expand Down Expand Up @@ -82,7 +82,7 @@ async def test_invalid_credentials(hass: HomeAssistant) -> None:
patch(
"homeassistant.components.abode.config_flow.AbodeFlowHandler.async_step_reauth",
return_value={
"type": data_entry_flow.FlowResultType.FORM,
"type": FlowResultType.FORM,
"flow_id": "mock_flow",
"step_id": "reauth_confirm",
},
Expand Down
25 changes: 13 additions & 12 deletions tests/components/application_credentials/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CONF_NAME,
)
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.setup import async_setup_component

Expand Down Expand Up @@ -163,7 +164,7 @@ async def complete_external_step(
)

result = await self.hass.config_entries.flow.async_configure(result["flow_id"])
assert result.get("type") == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result.get("type") is FlowResultType.CREATE_ENTRY
assert result.get("title") == self.title
assert "data" in result
assert "token" in result["data"]
Expand Down Expand Up @@ -420,7 +421,7 @@ async def test_config_flow_no_credentials(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.ABORT
assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "missing_credentials"


Expand All @@ -447,7 +448,7 @@ async def test_config_flow_other_domain(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.ABORT
assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "missing_credentials"


Expand All @@ -470,7 +471,7 @@ async def test_config_flow(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.EXTERNAL_STEP
assert result.get("type") is FlowResultType.EXTERNAL_STEP
result = await oauth_fixture.complete_external_step(result)
assert (
result["data"].get("auth_implementation") == "fake_integration_some_client_id"
Expand Down Expand Up @@ -535,14 +536,14 @@ async def test_config_flow_multiple_entries(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.FORM
assert result.get("type") is FlowResultType.FORM
assert result.get("step_id") == "pick_implementation"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={"implementation": "fake_integration_some_client_id2"},
)
assert result.get("type") == data_entry_flow.FlowResultType.EXTERNAL_STEP
assert result.get("type") is FlowResultType.EXTERNAL_STEP
oauth_fixture.client_id = CLIENT_ID + "2"
oauth_fixture.title = CLIENT_ID + "2"
result = await oauth_fixture.complete_external_step(result)
Expand Down Expand Up @@ -572,7 +573,7 @@ async def test_config_flow_create_delete_credential(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.ABORT
assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "missing_credentials"


Expand All @@ -589,7 +590,7 @@ async def test_config_flow_with_config_credential(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.EXTERNAL_STEP
assert result.get("type") is FlowResultType.EXTERNAL_STEP
oauth_fixture.title = DEFAULT_IMPORT_NAME
result = await oauth_fixture.complete_external_step(result)
# Uses the imported auth domain for compatibility
Expand All @@ -607,7 +608,7 @@ async def test_import_without_setup(hass: HomeAssistant, config_credential) -> N
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.ABORT
assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "missing_configuration"


Expand Down Expand Up @@ -636,7 +637,7 @@ async def test_websocket_without_platform(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.ABORT
assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "missing_configuration"


Expand Down Expand Up @@ -711,7 +712,7 @@ async def get_auth_impl(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.EXTERNAL_STEP
assert result.get("type") is FlowResultType.EXTERNAL_STEP
oauth_fixture.title = DEFAULT_IMPORT_NAME
result = await oauth_fixture.complete_external_step(result)
# Uses the imported auth domain for compatibility
Expand Down Expand Up @@ -769,7 +770,7 @@ async def test_name(
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result.get("type") == data_entry_flow.FlowResultType.EXTERNAL_STEP
assert result.get("type") is FlowResultType.EXTERNAL_STEP
oauth_fixture.title = NAME
result = await oauth_fixture.complete_external_step(result)
assert (
Expand Down
4 changes: 2 additions & 2 deletions tests/components/aussie_broadband/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from aiohttp import ClientConnectionError
from aussiebb.exceptions import AuthenticationException, UnrecognisedServiceType

from homeassistant import data_entry_flow
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

from .common import setup_platform

Expand All @@ -25,7 +25,7 @@ async def test_auth_failure(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.aussie_broadband.config_flow.AussieBroadbandConfigFlow.async_step_reauth",
return_value={
"type": data_entry_flow.FlowResultType.FORM,
"type": FlowResultType.FORM,
"flow_id": "mock_flow",
"step_id": "reauth_confirm",
},
Expand Down
8 changes: 5 additions & 3 deletions tests/components/auth/test_mfa_setup_flow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests for the mfa setup flow."""

from homeassistant import data_entry_flow
from homeassistant.auth import auth_manager_from_config
from homeassistant.components.auth import mfa_setup_flow
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.setup import async_setup_component

from tests.common import CLIENT_ID, MockUser, ensure_auth_manager_loaded
Expand Down Expand Up @@ -75,7 +75,8 @@ async def test_ws_setup_depose_mfa(
assert result["success"]

flow = result["result"]
assert flow["type"] == data_entry_flow.FlowResultType.FORM
# Cannot use identity `is` check here as the value is parsed from JSON
assert flow["type"] == FlowResultType.FORM.value
assert flow["handler"] == "example_module"
assert flow["step_id"] == "init"
assert flow["data_schema"][0] == {"type": "string", "name": "pin", "required": True}
Expand All @@ -94,7 +95,8 @@ async def test_ws_setup_depose_mfa(
assert result["success"]

flow = result["result"]
assert flow["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
# Cannot use identity `is` check here as the value is parsed from JSON
assert flow["type"] == FlowResultType.CREATE_ENTRY.value
assert flow["handler"] == "example_module"
assert flow["data"]["result"] is None

Expand Down
5 changes: 3 additions & 2 deletions tests/components/cloud/test_account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import pytest

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components.cloud import account_link
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.util.dt import utcnow

Expand Down Expand Up @@ -203,7 +204,7 @@ async def test_implementation(
TEST_DOMAIN, context={"source": config_entries.SOURCE_USER}
)

assert result["type"] == data_entry_flow.FlowResultType.EXTERNAL_STEP
assert result["type"] is FlowResultType.EXTERNAL_STEP
assert result["url"] == "http://example.com/auth"

flow_finished.set_result(
Expand Down
3 changes: 2 additions & 1 deletion tests/components/config/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from homeassistant.config_entries import HANDLERS, ConfigFlow
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import config_entry_flow, config_validation as cv
from homeassistant.loader import IntegrationNotFound
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -1305,7 +1306,7 @@ async def async_step_account(self, user_input=None):
result = await hass.config_entries.flow.async_init(
"test", context={"source": core_ce.SOURCE_USER}
)
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["type"] is FlowResultType.FORM

await ws_client.send_json(
{
Expand Down
7 changes: 4 additions & 3 deletions tests/components/dialogflow/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import pytest

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components import dialogflow, intent_script
from homeassistant.config import async_process_ha_core_config
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.setup import async_setup_component

SESSION_ID = "a9b84cec-46b6-484e-8f31-f65dba03ae6d"
Expand Down Expand Up @@ -88,10 +89,10 @@ async def fixture(hass, hass_client_no_auth):
result = await hass.config_entries.flow.async_init(
"dialogflow", context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == data_entry_flow.FlowResultType.FORM, result
assert result["type"] is FlowResultType.FORM, result

result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] is FlowResultType.CREATE_ENTRY
webhook_id = result["result"].data["webhook_id"]

return await hass_client_no_auth(), webhook_id
Expand Down
2 changes: 1 addition & 1 deletion tests/components/esphome/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def test_new_dashboard_fix_reauth(
"unique_id": mock_config_entry.unique_id,
},
)
assert result["type"] == FlowResultType.FORM
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
assert len(mock_get_encryption_key.mock_calls) == 0

Expand Down
2 changes: 1 addition & 1 deletion tests/components/esphome/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def async_disconnect(*args, **kwargs) -> None:
"esphome", context={"source": config_entries.SOURCE_DHCP}, data=service_info
)

assert result["type"] == FlowResultType.ABORT
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.data[CONF_HOST] == "192.168.43.184"
await hass.async_block_till_done()
Expand Down
2 changes: 1 addition & 1 deletion tests/components/flexit_bacnet/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def flow_id(hass: HomeAssistant) -> str:
DOMAIN, context={"source": config_entries.SOURCE_USER}
)

assert result["type"] == FlowResultType.FORM
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}

return result["flow_id"]
Expand Down
7 changes: 4 additions & 3 deletions tests/components/geofency/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components import zone
from homeassistant.components.geofency import CONF_MOBILE_BEACONS, DOMAIN
from homeassistant.config import async_process_ha_core_config
Expand All @@ -16,6 +16,7 @@
STATE_NOT_HOME,
)
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component
from homeassistant.util import slugify
Expand Down Expand Up @@ -157,10 +158,10 @@ async def webhook_id(hass, geofency_client):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == data_entry_flow.FlowResultType.FORM, result
assert result["type"] is FlowResultType.FORM, result

result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] is FlowResultType.CREATE_ENTRY

await hass.async_block_till_done()
return result["result"].data["webhook_id"]
Expand Down
7 changes: 4 additions & 3 deletions tests/components/gpslogger/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import pytest

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components import gpslogger, zone
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
from homeassistant.components.gpslogger import DOMAIN, TRACKER_UPDATE
from homeassistant.config import async_process_ha_core_config
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -65,10 +66,10 @@ async def webhook_id(hass, gpslogger_client):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == data_entry_flow.FlowResultType.FORM, result
assert result["type"] is FlowResultType.FORM, result

result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] is FlowResultType.CREATE_ENTRY

await hass.async_block_till_done()
return result["result"].data["webhook_id"]
Expand Down
7 changes: 4 additions & 3 deletions tests/components/hisense_aehw4a1/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

from pyaehw4a1 import exceptions

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components import hisense_aehw4a1
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.setup import async_setup_component


Expand All @@ -27,10 +28,10 @@ async def test_creating_entry_sets_up_climate_discovery(hass: HomeAssistant) ->
)

# Confirmation form
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["type"] is FlowResultType.FORM

result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] is FlowResultType.CREATE_ENTRY

await hass.async_block_till_done()

Expand Down
Loading

0 comments on commit 24f83c5

Please sign in to comment.