Ejemplo n.º 1
0
    def test_get_timer_object_not_created(self):
        timer = TaskTimer(worker=self.worker)
        timer.save()
        new_timer = get_timer_object(self.worker)

        # Function should return the already created timer object.
        self.assertEqual(new_timer, timer)
Ejemplo n.º 2
0
    def test_get_timer_object_not_created(self):
        timer = TaskTimer(worker=self.worker)
        timer.save()
        new_timer = get_timer_object(self.worker)

        # Function should return the already created timer object.
        self.assertEqual(new_timer, timer)
Ejemplo n.º 3
0
 def test_get_timer_current_duration(self):
     timer = TaskTimer(worker=self.worker,
                       assignment=self.assignment,
                       start_time=self.time)
     timer.save()
     self.time = self.time + datetime.timedelta(hours=1)
     duration = get_timer_current_duration(self.worker)
     self.assertEqual(duration, datetime.timedelta(hours=1))
Ejemplo n.º 4
0
 def test_get_timer_current_duration(self):
     timer = TaskTimer(worker=self.worker,
                       assignment=self.assignment,
                       start_time=self.time)
     timer.save()
     self.time = self.time + datetime.timedelta(hours=1)
     duration = get_timer_current_duration(self.worker)
     self.assertEqual(duration, datetime.timedelta(hours=1))
Ejemplo n.º 5
0
 def test_get_timer(self, mock_get):
     timer = TaskTimer(worker=self.worker, start_time=timezone.now())
     timer.save()
     resp = self.request_client.get(
         reverse('orchestra:orchestra:get_timer'))
     mock_get.assert_called_with(self.worker)
     data = load_encoded_json(resp.content)
     expected = TaskTimerSerializer(timer).data
     expected['time_worked'] = '1:00:00'
     self.assertEqual(data, expected)
Ejemplo n.º 6
0
 def test_start_timer(self, mock_start):
     timer = TaskTimer(worker=self.worker, start_time=self.time)
     timer.save()
     mock_start.return_value = timer
     resp = self.request_client.post(
         reverse('orchestra:orchestra:start_timer'),
         data=json.dumps({'assignment': '11'}),
         content_type='application/json')
     mock_start.assert_called_with(self.worker, assignment_id='11')
     data = load_encoded_json(resp.content)
     serializer = TaskTimerSerializer(timer)
     self.assertEqual(data, serializer.data)
Ejemplo n.º 7
0
 def test_get_timer(self, mock_get):
     timer = TaskTimer(
         worker=self.worker,
         start_time=timezone.now())
     timer.save()
     resp = self.request_client.get(
         reverse('orchestra:orchestra:get_timer'))
     mock_get.assert_called_with(self.worker)
     data = load_encoded_json(resp.content)
     expected = TaskTimerSerializer(timer).data
     expected['time_worked'] = '1:00:00'
     self.assertEqual(data, expected)
Ejemplo n.º 8
0
 def test_start_timer(self, mock_start):
     timer = TaskTimer(worker=self.worker, start_time=self.time)
     timer.save()
     mock_start.return_value = timer
     resp = self.request_client.post(
         reverse('orchestra:orchestra:start_timer'),
         data=json.dumps({'assignment': '11'}),
         content_type='application/json')
     mock_start.assert_called_with(self.worker, assignment_id='11')
     data = load_encoded_json(resp.content)
     serializer = TaskTimerSerializer(timer)
     self.assertEqual(data, serializer.data)
Ejemplo n.º 9
0
    def test_stop_timer_atomic(self, mock_reset):
        timer = TaskTimer(worker=self.worker, start_time=self.time)
        timer.save()
        time_entries_count = TimeEntry.objects.count()
        self.assertIsNone(timer.stop_time)

        with self.assertRaises(Exception):
            stop_timer(self.worker)

        # Verify that transaction rolled back.
        timer.refresh_from_db()
        self.assertIsNone(timer.stop_time)
        self.assertEqual(TimeEntry.objects.count(), time_entries_count)
Ejemplo n.º 10
0
    def test_stop_timer_atomic(self, mock_reset):
        timer = TaskTimer(worker=self.worker, start_time=self.time)
        timer.save()
        time_entries_count = TimeEntry.objects.count()
        self.assertIsNone(timer.stop_time)

        with self.assertRaises(Exception):
            stop_timer(self.worker)

        # Verify that transaction rolled back.
        timer.refresh_from_db()
        self.assertIsNone(timer.stop_time)
        self.assertEqual(TimeEntry.objects.count(), time_entries_count)
Ejemplo n.º 11
0
    def test_stop_timer(self):
        timer = TaskTimer(worker=self.worker,
                          assignment=self.assignment,
                          start_time=self.time)
        timer.save()
        start_time = self.time
        self.time = self.time + datetime.timedelta(hours=1)
        time_entry = stop_timer(self.worker)

        # Time entry object is created correctly.
        self.assertEqual(time_entry.worker, self.worker)
        self.assertEqual(time_entry.date, start_time.date())
        self.assertEqual(time_entry.time_worked, datetime.timedelta(hours=1))
        self.assertEqual(time_entry.assignment, self.assignment)
        self.assertEqual(time_entry.timer_start_time, start_time)
        self.assertEqual(time_entry.timer_stop_time, self.time)

        # Timer object should be reset.
        timer.refresh_from_db()
        self.assertIsNone(timer.start_time)
        self.assertIsNone(timer.stop_time)
Ejemplo n.º 12
0
    def test_stop_timer(self):
        timer = TaskTimer(worker=self.worker,
                          assignment=self.assignment,
                          start_time=self.time)
        timer.save()
        start_time = self.time
        self.time = self.time + datetime.timedelta(hours=1)
        time_entry = stop_timer(self.worker)

        # Time entry object is created correctly.
        self.assertEqual(time_entry.worker, self.worker)
        self.assertEqual(time_entry.date, start_time.date())
        self.assertEqual(time_entry.time_worked, datetime.timedelta(hours=1))
        self.assertEqual(time_entry.assignment, self.assignment)
        self.assertEqual(time_entry.timer_start_time, start_time)
        self.assertEqual(time_entry.timer_stop_time, self.time)

        # Timer object should be reset.
        timer.refresh_from_db()
        self.assertIsNone(timer.start_time)
        self.assertIsNone(timer.stop_time)
Ejemplo n.º 13
0
 def test_start_timer_already_running(self):
     timer = TaskTimer(worker=self.worker, start_time=self.time)
     timer.save()
     with self.assertRaisesRegex(TimerError, 'Timer has already started'):
         start_timer(self.worker)
Ejemplo n.º 14
0
 def test_get_timer_current_duration_no_start_time(self):
     timer = TaskTimer(worker=self.worker, assignment=self.assignment)
     timer.save()
     duration = get_timer_current_duration(self.worker)
     self.assertIsNone(duration)
Ejemplo n.º 15
0
 def test_get_timer_current_duration_no_start_time(self):
     timer = TaskTimer(worker=self.worker,
                       assignment=self.assignment)
     timer.save()
     duration = get_timer_current_duration(self.worker)
     self.assertIsNone(duration)
Ejemplo n.º 16
0
 def test_stop_timer_not_running(self):
     timer = TaskTimer(worker=self.worker)
     timer.save()
     with self.assertRaisesRegex(TimerError, 'Timer not started'):
         stop_timer(self.worker)
Ejemplo n.º 17
0
 def test_stop_timer_not_running(self):
     timer = TaskTimer(worker=self.worker)
     timer.save()
     with self.assertRaisesRegex(TimerError, 'Timer not started'):
         stop_timer(self.worker)
Ejemplo n.º 18
0
 def test_start_timer_already_running(self):
     timer = TaskTimer(worker=self.worker,
                       start_time=self.time)
     timer.save()
     with self.assertRaisesRegex(TimerError, 'Timer has already started'):
         start_timer(self.worker)