def test_time_entry_update_invalid_data(self): time_entry = TimeEntry.objects.filter(worker=self.worker).first() serializer = TimeEntrySerializer(time_entry) data = serializer.data data['date'] = '2' # Invalid date. resp = self.request_client.put(reverse( 'orchestra:orchestra:time_entry', kwargs={'pk': time_entry.id}), data=json.dumps(data), content_type='application/json') self.assertEqual(resp.status_code, 400)
def test_time_entry_update(self): time_entry = TimeEntry.objects.filter(worker=self.worker).first() serializer = TimeEntrySerializer(time_entry) data = serializer.data data['time_worked'] = '10:00:00' # Update time worked. self.request_client.put(reverse('orchestra:orchestra:time_entry', kwargs={'pk': time_entry.id}), data=json.dumps(data), content_type='application/json') time_entry.refresh_from_db() self.assertEqual(time_entry.time_worked, datetime.timedelta(hours=10))
def stop_timer(request): worker = Worker.objects.get(user=request.user) try: if request.method == 'POST': time_entry = time_tracking.stop_timer(worker) serializer = TimeEntrySerializer(time_entry) return serializer.data except TimerError as e: raise BadRequest(e) except Exception as e: logger.exception(e) raise e
def test_stop_timer(self, mock_stop): time_entry = TimeEntry(worker=self.worker, date=self.time.date(), time_worked=datetime.timedelta(hours=1)) time_entry.save() mock_stop.return_value = time_entry resp = self.request_client.post( reverse('orchestra:orchestra:stop_timer'), data=json.dumps({}), content_type='application/json') mock_stop.assert_called_with(self.worker) data = load_encoded_json(resp.content) serializer = TimeEntrySerializer(time_entry) self.assertEqual(data, serializer.data)
def _verify_time_entries(self, data): for time_entry in data: serializer = TimeEntrySerializer(data=time_entry) self.assertTrue(serializer.is_valid())
def _verify_time_entries(self, data): for time_entry in data: serializer = TimeEntrySerializer(data=time_entry) self.assertTrue(serializer.is_valid())