Set up notify group with the notify services in test (#115526)

This commit is contained in:
Jan Bouwhuis 2024-04-13 17:10:16 +02:00 committed by GitHub
parent 36bdda5669
commit 197070486f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,6 @@ from unittest.mock import MagicMock, call, patch
from homeassistant import config as hass_config from homeassistant import config as hass_config
from homeassistant.components import notify from homeassistant.components import notify
from homeassistant.components.group import SERVICE_RELOAD from homeassistant.components.group import SERVICE_RELOAD
import homeassistant.components.group.notify as group
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -83,9 +82,6 @@ async def help_setup_notify(
async def test_send_message_with_data(hass: HomeAssistant, tmp_path: Path) -> None: async def test_send_message_with_data(hass: HomeAssistant, tmp_path: Path) -> None:
"""Test sending a message with to a notify group.""" """Test sending a message with to a notify group."""
send_message_mock = await help_setup_notify(
hass, tmp_path, {"service1": 1, "service2": 2}
)
assert await async_setup_component( assert await async_setup_component(
hass, hass,
"group", "group",
@ -93,9 +89,10 @@ async def test_send_message_with_data(hass: HomeAssistant, tmp_path: Path) -> No
) )
await hass.async_block_till_done() await hass.async_block_till_done()
service = await group.async_get_service( group_setup = [
hass,
{ {
"platform": "group",
"name": "My notification group",
"services": [ "services": [
{"service": "test_service1"}, {"service": "test_service1"},
{ {
@ -105,16 +102,21 @@ async def test_send_message_with_data(hass: HomeAssistant, tmp_path: Path) -> No
"data": {"test": "message", "default": "default"}, "data": {"test": "message", "default": "default"},
}, },
}, },
] ],
}, }
]
send_message_mock = await help_setup_notify(
hass, tmp_path, {"service1": 1, "service2": 2}, group_setup
) )
assert hass.services.has_service("notify", "my_notification_group")
# Test sending a message to a notify group. # Test sending a message to a notify group.
await service.async_send_message( await hass.services.async_call(
"Hello", title="Test notification", data={"hello": "world"} "notify",
"my_notification_group",
{"message": "Hello", "title": "Test notification", "data": {"hello": "world"}},
blocking=True,
) )
await hass.async_block_till_done()
send_message_mock.assert_has_calls( send_message_mock.assert_has_calls(
[ [
call( call(
@ -138,14 +140,16 @@ async def test_send_message_with_data(hass: HomeAssistant, tmp_path: Path) -> No
send_message_mock.reset_mock() send_message_mock.reset_mock()
# Test sending a message which overrides service defaults to a notify group # Test sending a message which overrides service defaults to a notify group
await service.async_send_message( await hass.services.async_call(
"Hello", "notify",
title="Test notification", "my_notification_group",
data={"hello": "world", "default": "override"}, {
"message": "Hello",
"title": "Test notification",
"data": {"hello": "world", "default": "override"},
},
blocking=True,
) )
await hass.async_block_till_done()
send_message_mock.assert_has_calls( send_message_mock.assert_has_calls(
[ [
call( call(