Пример #1
0
    def post(self, request, format=None):
        action = request.data.get('action')
        request_off_id = request.data.get('request_off_id')
        comment = request.data.get('comment')
        user = request.user.profile
        try:
            if action == Workday.STATUS_APPROVED:
                data = ActionRequestService.action_approve(
                    request_off_id, user, comment)
                serializer = RequestDetailSerializer(data)
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)

            elif action == Workday.STATUS_REJECTED:
                data = ActionRequestService.action_reject(
                    request_off_id, user, comment)
                serializer = RequestDetailSerializer(data)
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)

            elif action == Workday.STATUS_CANCEL:
                data = ActionRequestService.action_cancel(request_off_id, user)
                serializer = RequestOffSerializer(data)
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)
        except Exception as e:
            error = str(e)
            return Response({'error': error},
                            status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
    def test_services_rejected_and_service_approve_request_approved(self):
        request_detail = ActionRequestService.action_reject(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.status, Workday.STATUS_REJECTED)
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_REJECTED)

        request_detail = ActionRequestService.action_approve(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.status, Workday.STATUS_REJECTED)
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_REJECTED)
Пример #3
0
    def test_services_cancel_and_approve_request_cancel_and_reject_request_cancel(self):
        request_off = ActionRequestService.action_cancel(self.response_request_data['id'], self.user3_profile)
        self.assertEqual(request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_off.status, Workday.STATUS_CANCEL)

        request_detail = ActionRequestService.action_approve(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_CANCEL)
        self.assertEqual(request_detail.status, None)

        request_detail = ActionRequestService.action_reject(self.response_request_data['id'], self.user2_profile, '')
        self.assertEqual(request_detail.request_off.id, UUID(self.response_request_data['id']))
        self.assertEqual(request_detail.request_off.status, Workday.STATUS_CANCEL)
        self.assertEqual(request_detail.status, None)