Add support for complex template structures to data_template (#3255)

This commit is contained in:
Pascal Vizeli authored and Johann Kellerman committed 2016-09-08 18:19:47 +02:00
1 parent 94e3986d54
commit 267cda447e
4 files changed
+55 -5

No files matched your search

+19 -3
View File
@@ -299,9 +299,7 @@ def test_template():
"""Test template validator."""
schema = vol.Schema(cv.template)
for value in (
None, '{{ partial_print }', '{% if True %}Hello', {'dict': 'isbad'}
):
for value in (None, '{{ partial_print }', '{% if True %}Hello', ['test']):
with pytest.raises(vol.MultipleInvalid):
schema(value)
@@ -313,6 +311,24 @@ def test_template():
schema(value)
def test_template_complex():
"""Test template_complex validator."""
schema = vol.Schema(cv.template_complex)
for value in (None, '{{ partial_print }', '{% if True %}Hello'):
with pytest.raises(vol.MultipleInvalid):
schema(value)
for value in (
1, 'Hello',
'{{ beer }}',
'{% if 1 == 1 %}Hello{% else %}World{% endif %}',
{'test': 1, 'test': '{{ beer }}'},
['{{ beer }}', 1]
):
schema(value)
def test_time_zone():
"""Test time zone validation."""
schema = vol.Schema(cv.time_zone)
+8
View File
@@ -43,6 +43,11 @@ class TestServiceHelpers(unittest.TestCase):
'entity_id': 'hello.world',
'data_template': {
'hello': '{{ \'goodbye\' }}',
'data': {
'value': '{{ \'complex\' }}',
'simple': 'simple'
},
'list': ['{{ \'list\' }}', '2'],
},
}
runs = []
@@ -54,6 +59,9 @@ class TestServiceHelpers(unittest.TestCase):
self.hass.pool.block_till_done()
self.assertEqual('goodbye', runs[0].data['hello'])
self.assertEqual('complex', runs[0].data['data']['value'])
self.assertEqual('simple', runs[0].data['data']['simple'])
self.assertEqual('list', runs[0].data['list'][0])
def test_passing_variables_to_templates(self):
"""Test passing variables to templates."""