Cleanup FlowResultType in tests (#78810)

This commit is contained in:
epenet 2022-09-21 09:17:20 +02:00 committed by GitHub
parent 7a6897c757
commit c88a874063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 35 deletions

View file

@ -5,10 +5,11 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components.escea.const import DOMAIN, ESCEA_FIREPLACE
from homeassistant.components.escea.discovery import DiscoveryServiceListener
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
@ -58,12 +59,12 @@ async def test_not_found(
)
# Confirmation form
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "no_devices_found"
assert discovery_service.return_value.close.call_count == 1
@ -90,12 +91,12 @@ async def test_found(
)
# Confirmation form
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert mock_setup.call_count == 1
@ -112,6 +113,6 @@ async def test_single_instance_allowed(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
assert discovery_service.call_count == 0

View file

@ -7,7 +7,7 @@ import serial.tools.list_ports
from homeassistant import config_entries
from homeassistant.components.landisgyr_heat_meter import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
from homeassistant.data_entry_flow import FlowResultType
def mock_serial_port():
@ -38,7 +38,7 @@ async def test_manual_entry(mock_heat_meter, hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
@ -46,7 +46,7 @@ async def test_manual_entry(mock_heat_meter, hass: HomeAssistant) -> None:
result["flow_id"], {"device": "Enter Manually"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "setup_serial_manual_path"
assert result["errors"] == {}
@ -58,7 +58,7 @@ async def test_manual_entry(mock_heat_meter, hass: HomeAssistant) -> None:
result["flow_id"], {"device": "/dev/ttyUSB0"}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "LUGCUH50"
assert result["data"] == {
"device": "/dev/ttyUSB0",
@ -78,14 +78,14 @@ async def test_list_entry(mock_port, mock_heat_meter, hass: HomeAssistant) -> No
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": port.device}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "LUGCUH50"
assert result["data"] == {
"device": port.device,
@ -103,7 +103,7 @@ async def test_manual_entry_fail(mock_heat_meter, hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
@ -111,7 +111,7 @@ async def test_manual_entry_fail(mock_heat_meter, hass: HomeAssistant) -> None:
result["flow_id"], {"device": "Enter Manually"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "setup_serial_manual_path"
assert result["errors"] == {}
@ -123,7 +123,7 @@ async def test_manual_entry_fail(mock_heat_meter, hass: HomeAssistant) -> None:
result["flow_id"], {"device": "/dev/ttyUSB0"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "setup_serial_manual_path"
assert result["errors"] == {"base": "cannot_connect"}
@ -139,14 +139,14 @@ async def test_list_entry_fail(mock_port, mock_heat_meter, hass: HomeAssistant)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": port.device}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"}
@ -164,7 +164,7 @@ async def test_get_serial_by_id_realpath(
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
@ -181,7 +181,7 @@ async def test_get_serial_by_id_realpath(
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": port.device}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "LUGCUH50"
assert result["data"] == {
"device": port.device,
@ -203,7 +203,7 @@ async def test_get_serial_by_id_dev_path(
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
@ -218,7 +218,7 @@ async def test_get_serial_by_id_dev_path(
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"device": port.device}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "LUGCUH50"
assert result["data"] == {
"device": port.device,

View file

@ -4,10 +4,11 @@ from unittest.mock import MagicMock, patch
from pushover_complete import BadAPIRequestError
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components.pushover.const import CONF_USER_KEY, DOMAIN
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from . import MOCK_CONFIG
@ -42,7 +43,7 @@ async def test_flow_user(hass: HomeAssistant) -> None:
result["flow_id"],
user_input=MOCK_CONFIG,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "Pushover"
assert result["data"] == MOCK_CONFIG
@ -65,7 +66,7 @@ async def test_flow_user_key_already_configured(hass: HomeAssistant) -> None:
result["flow_id"],
user_input=MOCK_CONFIG,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
@ -90,7 +91,7 @@ async def test_flow_name_already_configured(hass: HomeAssistant) -> None:
result["flow_id"],
user_input=new_config,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
@ -105,7 +106,7 @@ async def test_flow_invalid_user_key(
context={"source": config_entries.SOURCE_USER},
data=MOCK_CONFIG,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {CONF_USER_KEY: "invalid_user_key"}
@ -121,7 +122,7 @@ async def test_flow_invalid_api_key(
context={"source": config_entries.SOURCE_USER},
data=MOCK_CONFIG,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {CONF_API_KEY: "invalid_api_key"}
@ -135,7 +136,7 @@ async def test_flow_conn_err(hass: HomeAssistant, mock_pushover: MagicMock) -> N
context={"source": config_entries.SOURCE_USER},
data=MOCK_CONFIG,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"}
@ -148,7 +149,7 @@ async def test_import(hass: HomeAssistant) -> None:
data=MOCK_CONFIG,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "Pushover"
assert result["data"] == MOCK_CONFIG

View file

@ -5,7 +5,6 @@ from unittest.mock import patch
import pytest
from simplipy.errors import InvalidCredentialsError, SimplipyError
from homeassistant import data_entry_flow
from homeassistant.components.simplisafe import DOMAIN
from homeassistant.components.simplisafe.config_flow import CONF_AUTH_CODE
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
@ -29,7 +28,7 @@ async def test_duplicate_error(config_entry, hass, setup_simplisafe):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_AUTH_CODE: VALID_AUTH_CODE}
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
@ -83,7 +82,7 @@ async def test_options_flow(config_entry, hass):
result["flow_id"], user_input={CONF_CODE: "4321"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert config_entry.options == {CONF_CODE: "4321"}
@ -102,7 +101,7 @@ async def test_step_reauth(config_entry, hass, setup_simplisafe):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_AUTH_CODE: VALID_AUTH_CODE}
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert len(hass.config_entries.async_entries()) == 1
@ -126,7 +125,7 @@ async def test_step_reauth_wrong_account(config_entry, hass, setup_simplisafe):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_AUTH_CODE: VALID_AUTH_CODE}
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "wrong_account"
@ -158,7 +157,7 @@ async def test_step_user(auth_code, caplog, hass, log_statement, setup_simplisaf
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_AUTH_CODE: auth_code}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
if log_statement:
assert any(m for m in caplog.messages if log_statement in m)