84 lines
2.8 KiB
Python
84 lines
2.8 KiB
Python
"""The tests for notify services that change targets."""
|
|
from homeassistant.components import notify
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
async def test_same_targets(hass: HomeAssistant):
|
|
"""Test not changing the targets in a notify service."""
|
|
test = NotificationService(hass)
|
|
await test.async_setup(hass, "notify", "test")
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hasattr(test, "registered_targets")
|
|
assert test.registered_targets == {"test_a": 1, "test_b": 2}
|
|
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
assert test.registered_targets == {"test_a": 1, "test_b": 2}
|
|
|
|
|
|
async def test_change_targets(hass: HomeAssistant):
|
|
"""Test changing the targets in a notify service."""
|
|
test = NotificationService(hass)
|
|
await test.async_setup(hass, "notify", "test")
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hasattr(test, "registered_targets")
|
|
assert test.registered_targets == {"test_a": 1, "test_b": 2}
|
|
|
|
test.target_list = {"a": 0}
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
assert test.target_list == {"a": 0}
|
|
assert test.registered_targets == {"test_a": 0}
|
|
|
|
|
|
async def test_add_targets(hass: HomeAssistant):
|
|
"""Test adding the targets in a notify service."""
|
|
test = NotificationService(hass)
|
|
await test.async_setup(hass, "notify", "test")
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hasattr(test, "registered_targets")
|
|
assert test.registered_targets == {"test_a": 1, "test_b": 2}
|
|
|
|
test.target_list = {"a": 1, "b": 2, "c": 3}
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
assert test.target_list == {"a": 1, "b": 2, "c": 3}
|
|
assert test.registered_targets == {"test_a": 1, "test_b": 2, "test_c": 3}
|
|
|
|
|
|
async def test_remove_targets(hass: HomeAssistant):
|
|
"""Test removing targets from the targets in a notify service."""
|
|
test = NotificationService(hass)
|
|
await test.async_setup(hass, "notify", "test")
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hasattr(test, "registered_targets")
|
|
assert test.registered_targets == {"test_a": 1, "test_b": 2}
|
|
|
|
test.target_list = {"c": 1}
|
|
await test.async_register_services()
|
|
await hass.async_block_till_done()
|
|
assert test.target_list == {"c": 1}
|
|
assert test.registered_targets == {"test_c": 1}
|
|
|
|
|
|
class NotificationService(notify.BaseNotificationService):
|
|
"""A test class for notification services."""
|
|
|
|
def __init__(self, hass):
|
|
"""Initialize the service."""
|
|
self.hass = hass
|
|
self.target_list = {"a": 1, "b": 2}
|
|
|
|
@property
|
|
def targets(self):
|
|
"""Return a dictionary of devices."""
|
|
return self.target_list
|