mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
* Add event loop to the core * Add block_till_done to HA core object * Fix some tests * Linting core * Fix statemachine tests * Core test fixes * fix block_till_done to wait for loop and queue to empty * fix test_core for passing, and correct start/stop/block_till_done * Fix remote tests * Fix tests: block_till_done * Fix linting * Fix more tests * Fix final linting * Fix remote test * remove unnecessary import * reduce sleep to avoid slowing down the tests excessively * fix remaining tests to wait for non-threadsafe operations * Add async_ doc strings for event loop / coroutine info * Fix command line test to block for the right timeout * Fix py3.4.2 loop var access * Fix SERVICE_CALL_LIMIT being in effect for other tests * Fix lint errors * Fix lint error with proper placement * Fix slave start to not start a timer * Add asyncio compatible listeners. * Increase min Python version to 3.4.2 * Move async backports to util * Add backported async tests * Fix linting * Simplify Python version check * Fix lint * Remove unneeded try/except and queue listener appproriately. * Fix tuple vs. list unorderable error on version compare. * Fix version tests
83 lines
3.0 KiB
Python
83 lines
3.0 KiB
Python
"""The tests for the notify.group platform."""
|
|
import unittest
|
|
|
|
import homeassistant.components.notify as notify
|
|
from homeassistant.components.notify import group
|
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
|
class TestNotifyGroup(unittest.TestCase):
|
|
"""Test the notify.group platform."""
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
|
"""Setup things to be run when tests are started."""
|
|
self.hass = get_test_home_assistant()
|
|
self.events = []
|
|
self.assertTrue(notify.setup(self.hass, {
|
|
'notify': {
|
|
'name': 'demo1',
|
|
'platform': 'demo'
|
|
}
|
|
}))
|
|
self.assertTrue(notify.setup(self.hass, {
|
|
'notify': {
|
|
'name': 'demo2',
|
|
'platform': 'demo'
|
|
}
|
|
}))
|
|
|
|
self.service = group.get_service(self.hass, {'services': [
|
|
{'service': 'demo1'},
|
|
{'service': 'demo2',
|
|
'data': {'target': 'unnamed device',
|
|
'data': {'test': 'message'}}}]})
|
|
|
|
assert self.service is not None
|
|
|
|
def record_event(event):
|
|
"""Record event to send notification."""
|
|
self.events.append(event)
|
|
|
|
self.hass.bus.listen("notify", record_event)
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
""""Stop everything that was started."""
|
|
self.hass.stop()
|
|
|
|
def test_send_message_to_group(self):
|
|
"""Test sending a message to a notify group."""
|
|
self.service.send_message('Hello', title='Test notification')
|
|
self.hass.block_till_done()
|
|
self.assertTrue(len(self.events) == 2)
|
|
last_event = self.events[-1]
|
|
self.assertEqual(last_event.data[notify.ATTR_TITLE],
|
|
'Test notification')
|
|
self.assertEqual(last_event.data[notify.ATTR_MESSAGE], 'Hello')
|
|
|
|
def test_send_message_with_data(self):
|
|
"""Test sending a message with to a notify group."""
|
|
notify_data = {'hello': 'world'}
|
|
self.service.send_message('Hello', title='Test notification',
|
|
data=notify_data)
|
|
self.hass.block_till_done()
|
|
last_event = self.events[-1]
|
|
self.assertEqual(last_event.data[notify.ATTR_TITLE],
|
|
'Test notification')
|
|
self.assertEqual(last_event.data[notify.ATTR_MESSAGE], 'Hello')
|
|
self.assertEqual(last_event.data[notify.ATTR_DATA], notify_data)
|
|
|
|
def test_entity_data_passes_through(self):
|
|
"""Test sending a message with data to merge to a notify group."""
|
|
notify_data = {'hello': 'world'}
|
|
self.service.send_message('Hello', title='Test notification',
|
|
data=notify_data)
|
|
self.hass.block_till_done()
|
|
data = self.events[-1].data
|
|
assert {
|
|
'message': 'Hello',
|
|
'target': 'unnamed device',
|
|
'title': 'Test notification',
|
|
'data': {'hello': 'world', 'test': 'message'}
|
|
} == data
|