mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 18:39:30 +00:00
Improve script validation (#32461)
This commit is contained in:
@@ -1008,7 +1008,10 @@ def test_key_value_schemas():
|
||||
for mode in None, "invalid":
|
||||
with pytest.raises(vol.Invalid) as excinfo:
|
||||
schema({"mode": mode})
|
||||
assert str(excinfo.value) == f"Unexpected key {mode}. Expected number, string"
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== f"Unexpected value for mode: '{mode}'. Expected number, string"
|
||||
)
|
||||
|
||||
with pytest.raises(vol.Invalid) as excinfo:
|
||||
schema({"mode": "number", "data": "string-value"})
|
||||
@@ -1020,3 +1023,25 @@ def test_key_value_schemas():
|
||||
|
||||
for mode, data in (("number", 1), ("string", "hello")):
|
||||
schema({"mode": mode, "data": data})
|
||||
|
||||
|
||||
def test_script(caplog):
|
||||
"""Test script validation is user friendly."""
|
||||
for data, msg in (
|
||||
({"delay": "{{ invalid"}, "should be format 'HH:MM'"),
|
||||
({"wait_template": "{{ invalid"}, "invalid template"),
|
||||
({"condition": "invalid"}, "Unexpected value for condition: 'invalid'"),
|
||||
({"event": None}, "string value is None for dictionary value @ data['event']"),
|
||||
(
|
||||
{"device_id": None},
|
||||
"string value is None for dictionary value @ data['device_id']",
|
||||
),
|
||||
(
|
||||
{"scene": "light.kitchen"},
|
||||
"Entity ID 'light.kitchen' does not belong to domain 'scene'",
|
||||
),
|
||||
):
|
||||
with pytest.raises(vol.Invalid) as excinfo:
|
||||
cv.script_action(data)
|
||||
|
||||
assert msg in str(excinfo.value)
|
||||
|
||||
Reference in New Issue
Block a user