Asyncio notify component migration (#5377)
* Async migrate notify/platform * convert group to async * fix unittest
This commit is contained in:
1 parent
f7ac644c11
commit
2a362fd1ff
6 files changed
+136
-88
No files matched your search
@@ -5,6 +5,7 @@ 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 homeassistant.util.async import run_coroutine_threadsafe
|
||||
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
|
||||
@@ -16,8 +17,11 @@ class TestNotifyGroup(unittest.TestCase):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.events = []
|
||||
self.service1 = MagicMock()
|
||||
self.service2 = MagicMock()
|
||||
self.service1 = demo.DemoNotificationService(self.hass)
|
||||
self.service2 = demo.DemoNotificationService(self.hass)
|
||||
|
||||
self.service1.send_message = MagicMock(autospec=True)
|
||||
self.service2.send_message = MagicMock(autospec=True)
|
||||
|
||||
def mock_get_service(hass, config, discovery_info=None):
|
||||
if config['name'] == 'demo1':
|
||||
@@ -37,11 +41,14 @@ class TestNotifyGroup(unittest.TestCase):
|
||||
}]
|
||||
})
|
||||
|
||||
self.service = group.get_service(self.hass, {'services': [
|
||||
{'service': 'demo1'},
|
||||
{'service': 'demo2',
|
||||
'data': {'target': 'unnamed device',
|
||||
'data': {'test': 'message'}}}]})
|
||||
self.service = run_coroutine_threadsafe(
|
||||
group.async_get_service(self.hass, {'services': [
|
||||
{'service': 'demo1'},
|
||||
{'service': 'demo2',
|
||||
'data': {'target': 'unnamed device',
|
||||
'data': {'test': 'message'}}}]}),
|
||||
self.hass.loop
|
||||
).result()
|
||||
|
||||
assert self.service is not None
|
||||
|
||||
@@ -51,17 +58,19 @@ class TestNotifyGroup(unittest.TestCase):
|
||||
|
||||
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'})
|
||||
run_coroutine_threadsafe(
|
||||
self.service.async_send_message(
|
||||
'Hello', title='Test notification', data={'hello': 'world'}),
|
||||
self.hass.loop).result()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.service1.send_message.mock_calls[0][1][0] == 'Hello'
|
||||
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][1][0] == 'Hello'
|
||||
assert self.service2.send_message.mock_calls[0][2] == {
|
||||
'message': 'Hello',
|
||||
'target': ['unnamed device'],
|
||||
'title': 'Test notification',
|
||||
'data': {'hello': 'world', 'test': 'message'}
|
||||
|
||||
Reference in new issue
Block a user