Cherry pick single file from #134020 to fix generic component tests (#134569)

This commit is contained in:
Robert Resch 2025-01-03 18:24:46 +01:00 committed by GitHub
parent 46b2830699
commit 03fd6a901b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,7 +30,6 @@ from homeassistant.components.stream import (
CONF_RTSP_TRANSPORT, CONF_RTSP_TRANSPORT,
CONF_USE_WALLCLOCK_AS_TIMESTAMPS, CONF_USE_WALLCLOCK_AS_TIMESTAMPS,
) )
from homeassistant.components.stream.worker import StreamWorkerError
from homeassistant.config_entries import ConfigEntryState, ConfigFlowResult from homeassistant.config_entries import ConfigEntryState, ConfigFlowResult
from homeassistant.const import ( from homeassistant.const import (
CONF_AUTHENTICATION, CONF_AUTHENTICATION,
@ -661,25 +660,6 @@ async def test_form_stream_other_error(hass: HomeAssistant, user_flow) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
@respx.mock
@pytest.mark.usefixtures("fakeimg_png")
async def test_form_stream_worker_error(
hass: HomeAssistant, user_flow: ConfigFlowResult
) -> None:
"""Test we handle a StreamWorkerError and pass the message through."""
with patch(
"homeassistant.components.generic.config_flow.create_stream",
side_effect=StreamWorkerError("Some message"),
):
result2 = await hass.config_entries.flow.async_configure(
user_flow["flow_id"],
TESTDATA,
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"stream_source": "unknown_with_details"}
assert result2["description_placeholders"] == {"error": "Some message"}
@respx.mock @respx.mock
async def test_form_stream_permission_error( async def test_form_stream_permission_error(
hass: HomeAssistant, fakeimgbytes_png: bytes, user_flow: ConfigFlowResult hass: HomeAssistant, fakeimgbytes_png: bytes, user_flow: ConfigFlowResult
@ -949,23 +929,22 @@ async def test_options_still_and_stream_not_provided(
@respx.mock @respx.mock
@pytest.mark.usefixtures("fakeimg_png") @pytest.mark.usefixtures("fakeimg_png")
async def test_form_options_stream_worker_error( async def test_form_options_permission_error(
hass: HomeAssistant, config_entry: MockConfigEntry hass: HomeAssistant, config_entry: MockConfigEntry
) -> None: ) -> None:
"""Test we handle a StreamWorkerError and pass the message through.""" """Test we handle a PermissionError and pass the message through."""
result = await hass.config_entries.options.async_init(config_entry.entry_id) result = await hass.config_entries.options.async_init(config_entry.entry_id)
with patch( with patch(
"homeassistant.components.generic.config_flow.create_stream", "homeassistant.components.generic.config_flow.create_stream",
side_effect=StreamWorkerError("Some message"), side_effect=PermissionError("Some message"),
): ):
result2 = await hass.config_entries.options.async_configure( result2 = await hass.config_entries.options.async_configure(
result["flow_id"], result["flow_id"],
TESTDATA, TESTDATA,
) )
assert result2["type"] is FlowResultType.FORM assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"stream_source": "unknown_with_details"} assert result2["errors"] == {"stream_source": "stream_not_permitted"}
assert result2["description_placeholders"] == {"error": "Some message"}
@pytest.mark.usefixtures("fakeimg_png") @pytest.mark.usefixtures("fakeimg_png")