mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Refactor deprecated RESULT_TYPE_* (#97367)
This commit is contained in:
@@ -9,7 +9,7 @@ import httpx
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.camera import async_get_image
|
||||
from homeassistant.components.generic.config_flow import slug
|
||||
from homeassistant.components.generic.const import (
|
||||
@@ -35,6 +35,7 @@ from homeassistant.const import (
|
||||
HTTP_BASIC_AUTHENTICATION,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@@ -79,7 +80,7 @@ async def test_form(
|
||||
user_flow["flow_id"],
|
||||
TESTDATA,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
client = await hass_client()
|
||||
preview_id = result1["flow_id"]
|
||||
@@ -92,7 +93,7 @@ async def test_form(
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "127_0_0_1"
|
||||
assert result2["options"] == {
|
||||
CONF_STILL_IMAGE_URL: "http://127.0.0.1/testurl/1",
|
||||
@@ -133,13 +134,13 @@ async def test_form_only_stillimage(
|
||||
data,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result1["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "127_0_0_1"
|
||||
assert result2["options"] == {
|
||||
CONF_STILL_IMAGE_URL: "http://127.0.0.1/testurl/1",
|
||||
@@ -166,13 +167,13 @@ async def test_form_reject_still_preview(
|
||||
user_flow["flow_id"],
|
||||
TESTDATA,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: False},
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["step_id"] == "user"
|
||||
|
||||
|
||||
@@ -193,7 +194,7 @@ async def test_form_still_preview_cam_off(
|
||||
user_flow["flow_id"],
|
||||
TESTDATA,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
preview_id = result1["flow_id"]
|
||||
# Try to view the image, should be unavailable.
|
||||
@@ -214,14 +215,14 @@ async def test_form_only_stillimage_gif(
|
||||
user_flow["flow_id"],
|
||||
data,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result2["options"][CONF_CONTENT_TYPE] == "image/gif"
|
||||
|
||||
|
||||
@@ -239,14 +240,14 @@ async def test_form_only_svg_whitespace(
|
||||
user_flow["flow_id"],
|
||||
data,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
@respx.mock
|
||||
@@ -274,14 +275,14 @@ async def test_form_only_still_sample(
|
||||
user_flow["flow_id"],
|
||||
data,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
@respx.mock
|
||||
@@ -362,13 +363,13 @@ async def test_form_rtsp_mode(
|
||||
result1 = await hass.config_entries.flow.async_configure(
|
||||
user_flow["flow_id"], data
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "127_0_0_1"
|
||||
assert result2["options"] == {
|
||||
CONF_STILL_IMAGE_URL: "http://127.0.0.1/testurl/1",
|
||||
@@ -399,14 +400,14 @@ async def test_form_only_stream(
|
||||
user_flow["flow_id"],
|
||||
data,
|
||||
)
|
||||
assert result1["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result1["type"] == FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result1["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result3["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result3["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "127_0_0_1"
|
||||
assert result3["options"] == {
|
||||
CONF_AUTHENTICATION: HTTP_BASIC_AUTHENTICATION,
|
||||
@@ -442,7 +443,7 @@ async def test_form_still_and_stream_not_provided(
|
||||
CONF_VERIFY_SSL: False,
|
||||
},
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "no_still_image_or_stream_url"}
|
||||
|
||||
|
||||
@@ -638,7 +639,7 @@ async def test_options_template_error(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(mock_entry.entry_id)
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
# try updating the still image url
|
||||
@@ -649,16 +650,16 @@ async def test_options_template_error(
|
||||
result["flow_id"],
|
||||
user_input=data,
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["step_id"] == "confirm_still"
|
||||
|
||||
result2a = await hass.config_entries.options.async_configure(
|
||||
result2["flow_id"], user_input={CONF_CONFIRMED_OK: True}
|
||||
)
|
||||
assert result2a["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result2a["type"] == FlowResultType.CREATE_ENTRY
|
||||
|
||||
result3 = await hass.config_entries.options.async_init(mock_entry.entry_id)
|
||||
assert result3["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result3["type"] == FlowResultType.FORM
|
||||
assert result3["step_id"] == "init"
|
||||
|
||||
# verify that an invalid template reports the correct UI error.
|
||||
@@ -667,7 +668,7 @@ async def test_options_template_error(
|
||||
result3["flow_id"],
|
||||
user_input=data,
|
||||
)
|
||||
assert result4.get("type") == data_entry_flow.FlowResultType.FORM
|
||||
assert result4.get("type") == FlowResultType.FORM
|
||||
assert result4["errors"] == {"still_image_url": "template_error"}
|
||||
|
||||
# verify that an invalid template reports the correct UI error.
|
||||
@@ -678,7 +679,7 @@ async def test_options_template_error(
|
||||
user_input=data,
|
||||
)
|
||||
|
||||
assert result5.get("type") == data_entry_flow.FlowResultType.FORM
|
||||
assert result5.get("type") == FlowResultType.FORM
|
||||
assert result5["errors"] == {"stream_source": "template_error"}
|
||||
|
||||
# verify that an relative stream url is rejected.
|
||||
@@ -688,7 +689,7 @@ async def test_options_template_error(
|
||||
result5["flow_id"],
|
||||
user_input=data,
|
||||
)
|
||||
assert result6.get("type") == data_entry_flow.FlowResultType.FORM
|
||||
assert result6.get("type") == FlowResultType.FORM
|
||||
assert result6["errors"] == {"stream_source": "relative_url"}
|
||||
|
||||
# verify that an malformed stream url is rejected.
|
||||
@@ -698,7 +699,7 @@ async def test_options_template_error(
|
||||
result6["flow_id"],
|
||||
user_input=data,
|
||||
)
|
||||
assert result7.get("type") == data_entry_flow.FlowResultType.FORM
|
||||
assert result7.get("type") == FlowResultType.FORM
|
||||
assert result7["errors"] == {"stream_source": "malformed_url"}
|
||||
|
||||
|
||||
@@ -736,7 +737,7 @@ async def test_options_only_stream(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(mock_entry.entry_id)
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
# try updating the config options
|
||||
@@ -745,13 +746,13 @@ async def test_options_only_stream(
|
||||
result["flow_id"],
|
||||
user_input=data,
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["step_id"] == "confirm_still"
|
||||
|
||||
result3 = await hass.config_entries.options.async_configure(
|
||||
result2["flow_id"], user_input={CONF_CONFIRMED_OK: True}
|
||||
)
|
||||
assert result3["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result3["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result3["data"][CONF_CONTENT_TYPE] == "image/jpeg"
|
||||
|
||||
|
||||
@@ -766,7 +767,7 @@ async def test_import(hass: HomeAssistant, fakeimg_png) -> None:
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=TESTDATA_YAML
|
||||
)
|
||||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Yaml Defined Name"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -778,7 +779,7 @@ async def test_import(hass: HomeAssistant, fakeimg_png) -> None:
|
||||
|
||||
# Any name defined in yaml should end up as the entity id.
|
||||
assert hass.states.get("camera.yaml_defined_name")
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.ABORT
|
||||
assert result2["type"] == FlowResultType.ABORT
|
||||
|
||||
|
||||
# These above can be deleted after deprecation period is finished.
|
||||
@@ -873,7 +874,7 @@ async def test_use_wallclock_as_timestamps_option(
|
||||
result = await hass.config_entries.options.async_init(
|
||||
mock_entry.entry_id, context={"show_advanced_options": True}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
with patch(
|
||||
"homeassistant.components.generic.async_setup_entry", return_value=True
|
||||
@@ -882,12 +883,12 @@ async def test_use_wallclock_as_timestamps_option(
|
||||
result["flow_id"],
|
||||
user_input={CONF_USE_WALLCLOCK_AS_TIMESTAMPS: True, **TESTDATA},
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
# Test what happens if user rejects the preview
|
||||
result3 = await hass.config_entries.options.async_configure(
|
||||
result2["flow_id"], user_input={CONF_CONFIRMED_OK: False}
|
||||
)
|
||||
assert result3["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result3["type"] == FlowResultType.FORM
|
||||
assert result3["step_id"] == "init"
|
||||
with patch(
|
||||
"homeassistant.components.generic.async_setup_entry", return_value=True
|
||||
@@ -896,10 +897,10 @@ async def test_use_wallclock_as_timestamps_option(
|
||||
result3["flow_id"],
|
||||
user_input={CONF_USE_WALLCLOCK_AS_TIMESTAMPS: True, **TESTDATA},
|
||||
)
|
||||
assert result4["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result4["type"] == FlowResultType.FORM
|
||||
assert result4["step_id"] == "confirm_still"
|
||||
result5 = await hass.config_entries.options.async_configure(
|
||||
result4["flow_id"],
|
||||
user_input={CONF_CONFIRMED_OK: True},
|
||||
)
|
||||
assert result5["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result5["type"] == FlowResultType.CREATE_ENTRY
|
||||
|
||||
Reference in New Issue
Block a user