Add notify test being called from a YAML/script combi

This commit is contained in:
Paulus Schoutsen 2016-08-09 21:03:06 -07:00
parent e773526714
commit 253628da11

View file

@ -1,8 +1,11 @@
"""The tests for the notify demo platform.""" """The tests for the notify demo platform."""
import tempfile
import unittest import unittest
import homeassistant.components.notify as notify import homeassistant.components.notify as notify
from homeassistant.components.notify import demo from homeassistant.components.notify import demo
from homeassistant.helpers import script
from homeassistant.util import yaml
from tests.common import get_test_home_assistant from tests.common import get_test_home_assistant
@ -59,3 +62,34 @@ class TestNotifyDemo(unittest.TestCase):
'title': 'my title', 'title': 'my title',
'data': {'hello': 'world'} 'data': {'hello': 'world'}
} == data } == data
def test_calling_notify_from_script_loaded_from_yaml(self):
"""Test if we can call a notify from a script."""
yaml_conf = """
service: notify.notify
data:
data:
push:
sound: US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav
data_template:
message: >
Test 123 {{ 2 + 2 }}
"""
with tempfile.NamedTemporaryFile() as fp:
fp.write(yaml_conf.encode('utf-8'))
fp.flush()
conf = yaml.load_yaml(fp.name)
script.call_from_config(self.hass, conf)
self.hass.pool.block_till_done()
self.assertTrue(len(self.events) == 1)
assert {
'message': 'Test 123 4',
'target': None,
'title': 'Home Assistant',
'data': {
'push': {
'sound':
'US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav'}}
} == self.events[0].data