Improve script validation (#32461)
This commit is contained in:
parent
da7c5518f3
commit
6a21afa2a8
5 changed files with 141 additions and 89 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue