示例#1
0
        def inner(request, *args, **kwargs):
            application_status = _get_application(request, kwargs).values_list("status__status", flat=True)[0]

            if is_editable and application_status in CaseStatusEnum.read_only_statuses():
                return JsonResponse(
                    data={
                        "errors": {
                            "non_field_errors": [
                                strings.Applications.Generic.INVALID_OPERATION_FOR_READ_ONLY_CASE_ERROR
                            ]
                        }
                    },
                    status=status.HTTP_400_BAD_REQUEST,
                )

            if is_major_editable and application_status not in CaseStatusEnum.major_editable_statuses():
                return JsonResponse(
                    data={
                        "errors": {
                            "non_field_errors": [
                                strings.Applications.Generic.INVALID_OPERATION_FOR_NON_DRAFT_OR_MAJOR_EDIT_CASE_ERROR
                            ]
                        }
                    },
                    status=status.HTTP_400_BAD_REQUEST,
                )

            return func(request, *args, **kwargs)
def get_case_statuses(read_only):
    """ Get a list of the case statuses that are read-only. """
    if read_only:
        return CaseStatusEnum.read_only_statuses()
    else:
        return [
            status for status, value in CaseStatusEnum.choices
            if not CaseStatusEnum.is_read_only(status)
        ]
示例#3
0
    def test_application_in_state_editable_failure(self):
        application = self.create_standard_application_case(self.organisation)
        application_status = CaseStatusEnum.read_only_statuses()[0]
        application.status = CaseStatus.objects.get(status=application_status)
        application.save()

        @application_in_state(is_editable=True)
        def a_view(request, *args, **kwargs):
            return HttpResponse()

        resp = a_view(request=None, pk=application.pk)
        self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertTrue(strings.Applications.Generic.
                        INVALID_OPERATION_FOR_READ_ONLY_CASE_ERROR in
                        resp.content.decode("utf-8"))