mirror of
https://github.com/home-assistant/core.git
synced 2026-06-02 21:54:27 +01:00
9db1aa7629
* Add mysensors notify platform * Make add_devices optional in platform callback function. * Use new argument structure for all existing mysensors platforms. * Add notify platform. * Update mysensors gateway. * Refactor notify setup * Enable discovery of notify platforms. * Update and add tests for notify component and some platforms. * Continue setup of notify platforms if a platform fails setup. * Remove notify tests that check platform config. These tests are not needed when config validation is used. * Add config validation to APNS notify platform. * Use discovery to set up mysensors notify platform. * Add discovery_info to get_service and update tests * Add discovery_info as keyword argument to the get_service function signature and update all notify platforms. * Update existing notify tests to check config validation using test helper. * Add removed tests back in that checked config in apns, command_line and file platforms, but use config validation test helper to verify config. * Add a test for notify file to increase coverage. * Fix some PEP issues. * Fix comments and use more constants * Move apns notify service under notify domain
69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
"""The tests for the notify.group platform."""
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from homeassistant.bootstrap import setup_component
|
|
import homeassistant.components.notify as notify
|
|
from homeassistant.components.notify import group, demo
|
|
|
|
from tests.common import assert_setup_component, 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.service1 = MagicMock()
|
|
self.service2 = MagicMock()
|
|
|
|
def mock_get_service(hass, config, discovery_info=None):
|
|
if config['name'] == 'demo1':
|
|
return self.service1
|
|
else:
|
|
return self.service2
|
|
|
|
with assert_setup_component(2), \
|
|
patch.object(demo, 'get_service', mock_get_service):
|
|
setup_component(self.hass, notify.DOMAIN, {
|
|
'notify': [{
|
|
'name': 'demo1',
|
|
'platform': 'demo'
|
|
}, {
|
|
'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 tearDown(self): # pylint: disable=invalid-name
|
|
""""Stop everything that was started."""
|
|
self.hass.stop()
|
|
|
|
def test_send_message_with_data(self):
|
|
"""Test sending a message with to a notify group."""
|
|
self.service.send_message('Hello', title='Test notification',
|
|
data={'hello': 'world'})
|
|
self.hass.block_till_done()
|
|
|
|
assert self.service1.send_message.mock_calls[0][2] == {
|
|
'message': 'Hello',
|
|
'title': 'Test notification',
|
|
'data': {'hello': 'world'}
|
|
}
|
|
assert self.service2.send_message.mock_calls[0][2] == {
|
|
'message': 'Hello',
|
|
'target': ['unnamed device'],
|
|
'title': 'Test notification',
|
|
'data': {'hello': 'world', 'test': 'message'}
|
|
}
|