mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add test to stop action (#95376)
This commit is contained in:
parent
8b25fd8563
commit
243abf32c0
@ -1690,7 +1690,11 @@ _SCRIPT_STOP_SCHEMA = vol.Schema(
|
|||||||
**SCRIPT_ACTION_BASE_SCHEMA,
|
**SCRIPT_ACTION_BASE_SCHEMA,
|
||||||
vol.Required(CONF_STOP): vol.Any(None, string),
|
vol.Required(CONF_STOP): vol.Any(None, string),
|
||||||
vol.Exclusive(CONF_ERROR, "error_or_response"): boolean,
|
vol.Exclusive(CONF_ERROR, "error_or_response"): boolean,
|
||||||
vol.Exclusive(CONF_RESPONSE_VARIABLE, "error_or_response"): str,
|
vol.Exclusive(
|
||||||
|
CONF_RESPONSE_VARIABLE,
|
||||||
|
"error_or_response",
|
||||||
|
msg="not allowed to add a response to an error stop action",
|
||||||
|
): str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1350,9 +1350,9 @@ def test_key_value_schemas_with_default() -> None:
|
|||||||
schema({"mode": "{{ 1 + 1}}"})
|
schema({"mode": "{{ 1 + 1}}"})
|
||||||
|
|
||||||
|
|
||||||
def test_script(caplog: pytest.LogCaptureFixture) -> None:
|
@pytest.mark.parametrize(
|
||||||
"""Test script validation is user friendly."""
|
("config", "error"),
|
||||||
for data, msg in (
|
(
|
||||||
({"delay": "{{ invalid"}, "should be format 'HH:MM'"),
|
({"delay": "{{ invalid"}, "should be format 'HH:MM'"),
|
||||||
({"wait_template": "{{ invalid"}, "invalid template"),
|
({"wait_template": "{{ invalid"}, "invalid template"),
|
||||||
({"condition": "invalid"}, "Unexpected value for condition: 'invalid'"),
|
({"condition": "invalid"}, "Unexpected value for condition: 'invalid'"),
|
||||||
@ -1366,20 +1366,33 @@ def test_script(caplog: pytest.LogCaptureFixture) -> None:
|
|||||||
{"condition": "not", "conditions": "not a dynamic template"},
|
{"condition": "not", "conditions": "not a dynamic template"},
|
||||||
"Expected a dictionary",
|
"Expected a dictionary",
|
||||||
),
|
),
|
||||||
({"event": None}, "string value is None for dictionary value @ data['event']"),
|
(
|
||||||
|
{"event": None},
|
||||||
|
r"string value is None for dictionary value @ data\['event'\]",
|
||||||
|
),
|
||||||
(
|
(
|
||||||
{"device_id": None},
|
{"device_id": None},
|
||||||
"string value is None for dictionary value @ data['device_id']",
|
r"string value is None for dictionary value @ data\['device_id'\]",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{"scene": "light.kitchen"},
|
{"scene": "light.kitchen"},
|
||||||
"Entity ID 'light.kitchen' does not belong to domain 'scene'",
|
"Entity ID 'light.kitchen' does not belong to domain 'scene'",
|
||||||
),
|
),
|
||||||
):
|
(
|
||||||
with pytest.raises(vol.Invalid) as excinfo:
|
{
|
||||||
cv.script_action(data)
|
"alias": "stop step",
|
||||||
|
"stop": "In the name of love",
|
||||||
assert msg in str(excinfo.value)
|
"error": True,
|
||||||
|
"response_variable": "response-value",
|
||||||
|
},
|
||||||
|
"not allowed to add a response to an error stop action",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_script(caplog: pytest.LogCaptureFixture, config: dict, error: str) -> None:
|
||||||
|
"""Test script validation is user friendly."""
|
||||||
|
with pytest.raises(vol.Invalid, match=error):
|
||||||
|
cv.script_action(config)
|
||||||
|
|
||||||
|
|
||||||
def test_whitespace() -> None:
|
def test_whitespace() -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user