Skip to content

Commit

Permalink
Improve imports
Browse files Browse the repository at this point in the history
  • Loading branch information
golles committed Jan 29, 2025
1 parent 5f64cc7 commit 4d00eac
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from unittest.mock import patch

from homeassistant import config_entries, data_entry_flow
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry

Expand Down Expand Up @@ -33,11 +34,11 @@ async def test_successful_config_flow(hass: HomeAssistant, bypass_get_data):
"""Test a successful config flow."""
# Initialize a config flow
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
DOMAIN, context={"source": SOURCE_USER}
)

# Check that the config flow shows the user form as the first step
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"

# If a user were to fill in all fields, it would result in this function call
Expand All @@ -47,7 +48,7 @@ async def test_successful_config_flow(hass: HomeAssistant, bypass_get_data):

# Check that the config flow is complete and a new entry is created with
# the input data
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == MOCK_CONFIG[CONF_PORT]
assert result["data"] == MOCK_CONFIG
assert result["result"]
Expand All @@ -61,17 +62,17 @@ async def test_successful_config_flow(hass: HomeAssistant, bypass_get_data):
async def test_failed_config_flow(hass: HomeAssistant, error_on_get_data):
"""Test a failed config flow due to credential validation failure."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
DOMAIN, context={"source": SOURCE_USER}
)

assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=MOCK_CONFIG
)

assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["type"] == FlowResultType.FORM
assert "base" in result["errors"]


Expand All @@ -87,7 +88,7 @@ async def test_options_flow(hass: HomeAssistant):
result = await hass.config_entries.options.async_init(entry.entry_id)

# Verify that the first options step is a user form
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"

# Enter some fake data into the form
Expand All @@ -97,7 +98,7 @@ async def test_options_flow(hass: HomeAssistant):
)

# Verify that the flow finishes
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == MOCK_CONFIG[CONF_PORT]

# Verify that the options were updated
Expand Down

0 comments on commit 4d00eac

Please sign in to comment.