test_motion_lights.py 916 Bytes
Newer Older
Rob Connolly's avatar
Rob Connolly committed
1
# import pytest
2 3 4
from appdaemontestframework import automation_fixture
from apps.motion_lights import MotionLight

5

6 7 8 9 10 11 12
@automation_fixture(MotionLight)
def motion_light(given_that):
    given_that.passed_arg("motion_sensor").is_set_to("binary_sensor.motion")
    given_that.passed_arg("light").is_set_to("light.test_light")
    given_that.passed_arg("timeout").is_set_to(120)


Rob Connolly's avatar
Rob Connolly committed
13 14 15 16 17 18 19 20 21 22 23 24
def test_callback_registered(given_that, motion_light, assert_that):
    assert_that(motion_light).listens_to.state(
        "binary_sensor.motion", new="on"
    ).with_callback(motion_light.motion_callback)


def test_light_on_off(given_that, motion_light, time_travel, assert_that):
    motion_light.is_light_times = lambda: True
    motion_light.motion_callback(None, None, None, None, None)
    assert_that("light.test_light").was.turned_on()
    time_travel.fast_forward(2).minutes()
    assert_that("light.test_light").was.turned_off()