Example #1
0
 def test_set_desk_disallow(self):
     event = Event(datetime(2017, 2, 13, 7, 0, 0), model.Down())
     self.controller.set_desk(event.index, event.data)
     self.database.insert_desk_event.assert_not_called()
     self.hardware.go.assert_not_called()
     self.timer.schedule.assert_not_called()
     self.timer.stop.assert_called_once()
Example #2
0
    def set_desk(self, time, state):
        if not self.check_time(time):
            return

        self.hardware.go(state)
        self.database.insert_desk_event(Event(time, state))
        self.update_timer(time)
Example #3
0
    def test_database_insert_session(self):
        a = datetime(2017, 1, 1)
        b = datetime(2017, 1, 2)
        c = datetime(2017, 1, 3)

        event = Event(b, Active())
        self.database.insert_session_event(event)
        events = self.database.get_session_events()
        self.assertEqual(events, [event])

        spans = list(self.database.get_session_spans(a, c))
        self.assertEqual(spans, [Span(a, b, Inactive()), Span(b, c, Active())])
Example #4
0
    def test_database_insert_desk(self):
        a = datetime(2017, 1, 1)
        b = datetime(2017, 1, 2)
        c = datetime(2017, 1, 3)

        event = Event(b, Up())
        self.database.insert_desk_event(event)
        events = self.database.get_desk_events()
        self.assertEqual(events, [event])

        spans = list(self.database.get_desk_spans(a, c))
        self.assertEqual(spans, [Span(a, b, Down()), Span(b, c, Up())])
Example #5
0
    def test_set_desk_down(self, compute_active_time):
        compute_active_time.return_value = timedelta(0)
        self.database.get_session_spans.return_value = [
            Span(self.beginning, self.now, model.Active())
        ]
        self.database.get_desk_spans.return_value = [
            Span(self.beginning, self.now, model.Down())
        ]
        event = Event(datetime(2017, 2, 13, 12, 0, 0), model.Down())

        self.controller.set_desk(event.index, event.data)
        self.database.insert_desk_event.assert_called_with(event)
        self.hardware.go.assert_called_with(event.data)
        self.timer.stop.assert_not_called()
        self.timer.schedule.assert_called_with(
            timedelta(minutes=50), model.Up())
Example #6
0
 def test_set_session_inactive(self):
     event = Event(datetime(2017, 2, 13, 13, 0, 0), model.Inactive())
     self.controller.set_session(event.index, event.data)
     self.database.insert_session_event.assert_called_with(event)
     self.hardware.light.assert_called_with(event.data)
Example #7
0
 def set_session(self, time, state):
     self.database.insert_session_event(Event(time, state))
     self.hardware.light(state)
     self.update_timer(time)