2020-08-17 16:54:56 +00:00
|
|
|
"""The tests for the trigger helper."""
|
2021-08-20 04:43:04 +00:00
|
|
|
from unittest.mock import MagicMock, call, patch
|
|
|
|
|
2020-08-17 16:54:56 +00:00
|
|
|
import pytest
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2021-08-20 04:43:04 +00:00
|
|
|
from homeassistant.helpers.trigger import (
|
|
|
|
_async_get_trigger_platform,
|
|
|
|
async_validate_trigger_config,
|
|
|
|
)
|
2020-08-17 16:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_bad_trigger_platform(hass):
|
|
|
|
"""Test bad trigger platform."""
|
|
|
|
with pytest.raises(vol.Invalid) as ex:
|
|
|
|
await async_validate_trigger_config(hass, [{"platform": "not_a_platform"}])
|
|
|
|
assert "Invalid platform 'not_a_platform' specified" in str(ex)
|
2021-08-20 04:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_subtype(hass):
|
|
|
|
"""Test trigger subtypes."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.helpers.trigger.async_get_integration", return_value=MagicMock()
|
|
|
|
) as integration_mock:
|
|
|
|
await _async_get_trigger_platform(hass, {"platform": "test.subtype"})
|
|
|
|
assert integration_mock.call_args == call(hass, "test")
|