Add service schema tests for notify entity platform (#115457)

* Add service schema tests for notify entity platform

* Use correct entity

* Assert on exception value
This commit is contained in:
Jan Bouwhuis 2024-04-12 10:40:17 +02:00 committed by GitHub
parent f3a3e6821b
commit a213de3db5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)