test_action.py 796 B

123456789101112131415161718192021222324252627
  1. import datetime
  2. import unittest.mock
  3. import pytest
  4. import systemctl_mqtt
  5. # pylint: disable=protected-access
  6. @pytest.mark.parametrize(
  7. "delay", [datetime.timedelta(seconds=4), datetime.timedelta(hours=21)]
  8. )
  9. def test_poweroff_trigger(delay):
  10. action = systemctl_mqtt._MQTTActionSchedulePoweroff()
  11. with unittest.mock.patch(
  12. "systemctl_mqtt._dbus.schedule_shutdown"
  13. ) as schedule_shutdown_mock:
  14. action.trigger(
  15. state=systemctl_mqtt._State(
  16. mqtt_topic_prefix="systemctl/hostname",
  17. homeassistant_discovery_prefix="homeassistant",
  18. homeassistant_node_id="node",
  19. poweroff_delay=delay,
  20. )
  21. )
  22. schedule_shutdown_mock.assert_called_once_with(action="poweroff", delay=delay)