diff --git a/tests/components/notify/test_init.py b/tests/components/notify/test_init.py index 26ed2ddc250..1f9ec81e36a 100644 --- a/tests/components/notify/test_init.py +++ b/tests/components/notify/test_init.py @@ -7,6 +7,7 @@ from typing import Any from unittest.mock import MagicMock, Mock, patch import pytest +import voluptuous as vol import yaml from homeassistant import config as hass_config @@ -120,6 +121,27 @@ async def test_send_message_service( await hass.async_block_till_done() entity.send_message_mock_calls.assert_called_once() + entity.send_message_mock_calls.reset_mock() + + # Test schema: `None` message fails + with pytest.raises(vol.Invalid) as exc: + await hass.services.async_call( + notify.DOMAIN, + notify.SERVICE_SEND_MESSAGE, + {"entity_id": "notify.test", notify.ATTR_MESSAGE: None}, + ) + assert ( + str(exc.value) == "string value is None for dictionary value @ data['message']" + ) + entity.send_message_mock_calls.assert_not_called() + + # Test schema: No message fails + with pytest.raises(vol.Invalid) as exc: + await hass.services.async_call( + notify.DOMAIN, notify.SERVICE_SEND_MESSAGE, {"entity_id": "notify.test"} + ) + assert str(exc.value) == "required key not provided @ data['message']" + entity.send_message_mock_calls.assert_not_called() # Test unloading the entry succeeds assert await hass.config_entries.async_unload(config_entry.entry_id)