예제 #1
0
 def test_event_not_triggered_twice(self, fakedevice, fakeproduct):
     """ Make sure that a device field trigger only fires once """
     with patch_sender() as fake_client:
         trigger_scheduled_events()
         assert fake_client.as_device.call_count == 1
         trigger_scheduled_events()
         assert fake_client.as_device.call_count == 1
예제 #2
0
    def test_event_triggered_from_device_field(self, fakedevice, fakeproduct):
        """ Make sure that a condition which depends on a device field, in this
        case `online`, triggers event defs. """
        with patch_sender() as fake_client:
            trigger_scheduled_events()

        assert fake_client.as_device.called == True
예제 #3
0
    def test_periodic(self, time, expect_call):
        """ test some combinations of periodic tiggers"""
        with patch_sender() as fake_client:
            with freeze_time(time):
                trigger_scheduled_events()

        assert fake_client.as_device.called == expect_call
예제 #4
0
    def test_periodic_conditions(self, temp, expect_call, fakedevice,
                                 fakeproduct):
        """ test some periodic conditions with additional context requirements """

        context = {"temp": temp, "ts": datetime(2020, 1, 1, 2, 0, 0)}
        add_periodic_datums(context, fakedevice, fakeproduct)

        with patch_sender() as fake_client:
            with freeze_time("2020-01-01T02:00:00Z"):
                trigger_scheduled_events()

        assert fake_client.as_device.called == expect_call
예제 #5
0
    def test_redis_functionality(self):
        with patch_sender() as fake_client:
            with freeze_time("2020-01-01T02:00:00Z"):
                trigger_scheduled_events()

        assert fake_client.as_device.called == True

        # Now try again, redis should have saved the evaluation time, so it
        # shouldn't run it again.
        with patch_sender() as fake_client:
            with freeze_time("2020-01-01T02:05:00Z"):
                trigger_scheduled_events()

        # The condition has been evaluated since the time was greater than the
        # condition time, don't reevaluate.
        assert fake_client.as_device.called == False
예제 #6
0
    def test_redis_time_day_functionality(self, fakedevice, fakeproduct):
        """ Make sure that time and day triggers are working correctly."""
        # First test an event definition: time==3600&&day==1
        # If this is evaluated on day one before 3600 it should be false
        # If this is then evaluated on day one after 3600 it should be true
        # (even though the day is the same as the last evaluation)
        with patch_sender() as fake_client:
            with freeze_time("2019-12-31T00:30:00Z"):
                trigger_scheduled_events()

        assert fake_client.as_device.called == False

        with patch_sender() as fake_client:
            with freeze_time("2019-12-31T01:30:00Z"):
                trigger_scheduled_events()

        # Should be true since this was last evaluated before the time matched.
        assert fake_client.as_device.called == True
예제 #7
0
    def test_redis_day_functionality(self, fakedevice, fakeproduct):
        """ Need to confirm exactly what this should do."""
        with patch_sender() as fake_client:
            with freeze_time("2019-12-30T23:30:00Z"):
                trigger_scheduled_events()

        # day == 0. So this should be false.
        assert fake_client.as_device.called == False

        # day == 1. So this should be True
        with patch_sender() as fake_client:
            with freeze_time("2019-12-31T00:30:00Z"):
                trigger_scheduled_events()

        assert fake_client.as_device.called == True

        with patch_sender() as fake_client:
            with freeze_time("2019-12-31T01:30:00Z"):
                trigger_scheduled_events()

        # Last time the condition was evaluated it was true so don't fire again
        assert fake_client.as_device.called == False