mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve resource validation in scrape config flow (#82965)
* Improve resource validation in scrape * Coverage
This commit is contained in:
parent
cd2bb292ab
commit
92fef0f2ba
@ -123,9 +123,12 @@ async def validate_rest_setup(
|
|||||||
hass = async_get_hass()
|
hass = async_get_hass()
|
||||||
rest_config: dict[str, Any] = COMBINED_SCHEMA(user_input)
|
rest_config: dict[str, Any] = COMBINED_SCHEMA(user_input)
|
||||||
try:
|
try:
|
||||||
create_rest_data_from_config(hass, rest_config)
|
rest = create_rest_data_from_config(hass, rest_config)
|
||||||
|
await rest.async_update()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise SchemaFlowError("resource_error") from err
|
raise SchemaFlowError("resource_error") from err
|
||||||
|
if rest.data is None:
|
||||||
|
raise SchemaFlowError("resource_error")
|
||||||
return user_input
|
return user_input
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,6 +115,22 @@ async def test_flow_fails(hass: HomeAssistant, get_data: MockRestData) -> None:
|
|||||||
|
|
||||||
assert result2["errors"] == {"base": "resource_error"}
|
assert result2["errors"] == {"base": "resource_error"}
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.rest.RestData",
|
||||||
|
return_value=MockRestData("test_scrape_sensor_no_data"),
|
||||||
|
):
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={
|
||||||
|
CONF_RESOURCE: "https://www.home-assistant.io",
|
||||||
|
CONF_METHOD: "GET",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
|
CONF_TIMEOUT: 10.0,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result2["errors"] == {"base": "resource_error"}
|
||||||
|
|
||||||
with patch("homeassistant.components.rest.RestData", return_value=get_data,), patch(
|
with patch("homeassistant.components.rest.RestData", return_value=get_data,), patch(
|
||||||
"homeassistant.components.scrape.async_setup_entry",
|
"homeassistant.components.scrape.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user