Python rest_framework.status 模块,HTTP_406_NOT_ACCEPTABLE 实例源码

我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用rest_framework.status.HTTP_406_NOT_ACCEPTABLE

项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_split_payment_methods_conflict(self):
        self.login(is_staff=True)
        basket_id = self._prepare_basket()

        # Try and pay_in_full with two methods, isn't allow because it doesn't make sense
        data = self._get_checkout_data(basket_id)
        data['payment'] = {
            'credit-card': {
                'enabled': True,
                'pay_balance': True,
            },
            'cash': {
                'enabled': True,
                'pay_balance': True,
            },
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment']['non_field_errors'][0], 'Can not set pay_balance flag on multiple payment methods.')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_split_payment_methods_missing_pay_balance(self):
        self.login(is_staff=True)
        basket_id = self._prepare_basket()

        # Try and pay_in_full with two methods, isn't allow because it doesn't make sense
        data = self._get_checkout_data(basket_id)
        data['payment'] = {
            'credit-card': {
                'enabled': True,
                'pay_balance': False,
                'amount': '2.00'
            },
            'cash': {
                'enabled': True,
                'pay_balance': False,
                'amount': '8.00'
            },
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment']['non_field_errors'][0], 'Must set pay_balance flag on at least one payment method.')
项目:django-phone-login    作者:wejhink    | 项目源码 | 文件源码
def post(self, request, format=None):
        # Get the patient if present or result None.
        ser = self.serializer_class(
            data=request.data,
            context={'request': request}
        )
        if ser.is_valid():
            token = PhoneToken.create_otp_for_number(
                request.data.get('phone_number')
            )
            if token:
                phone_token = self.serializer_class(
                    token, context={'request': request}
                )
                return Response(phone_token.data)
            return Response({
                'reason': "you can not have more than {n} attempts per day, please try again tomorrow".format(
                    n=getattr(settings, 'PHONE_LOGIN_ATTEMPTS', 10))}, status=status.HTTP_403_FORBIDDEN)
        return Response(
            {'reason': ser.errors}, status=status.HTTP_406_NOT_ACCEPTABLE)
项目:django-phone-login    作者:wejhink    | 项目源码 | 文件源码
def post(self, request, format=None):
        # Get the patient if present or result None.
        ser = self.serializer_class(
            data=request.data, context={'request': request}
        )
        if ser.is_valid():
            pk = request.data.get("pk")
            otp = request.data.get("otp")
            try:
                user = authenticate(request, pk=pk, otp=otp)
                if user:
                    last_login = user.last_login
                login(request, user)
                response = user_detail(user, last_login)
                return Response(response, status=status.HTTP_200_OK)
            except ObjectDoesNotExist:
                return Response(
                    {'reason': "OTP doesn't exist"},
                    status=status.HTTP_406_NOT_ACCEPTABLE
                )
        return Response(
            {'reason': ser.errors}, status=status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_challenge_submission_when_challenge_is_not_active(self):
        self.url = reverse_lazy('jobs:challenge_submission',
                                kwargs={'challenge_id': self.challenge.pk,
                                        'challenge_phase_id': self.challenge_phase.pk})

        self.challenge.end_date = timezone.now() - timedelta(days=1)
        self.challenge.save()

        expected = {
            'error': 'Challenge is not active'
        }

        response = self.client.post(self.url, {
                                    'status': 'submitting', 'input_file': self.input_file}, format="multipart")
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_challenge_submission_when_challenge_phase_is_not_public(self):
        self.url = reverse_lazy('jobs:challenge_submission',
                                kwargs={'challenge_id': self.challenge.pk,
                                        'challenge_phase_id': self.challenge_phase.pk})

        self.challenge_phase.is_public = False
        self.challenge_phase.save()

        expected = {
            'error': 'Sorry, cannot accept submissions since challenge phase is not public'
        }

        response = self.client.post(self.url, {
                                    'status': 'submitting', 'input_file': self.input_file}, format="multipart")
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_change_submission_data_and_visibility_when_challenge_is_not_active(self):
        self.url = reverse_lazy('jobs:change_submission_data_and_visibility',
                                kwargs={'challenge_pk': self.challenge.pk,
                                        'challenge_phase_pk': self.challenge_phase.pk,
                                        'submission_pk': self.submission.pk})
        self.data = {
            'method_name': 'Updated Method Name'
        }
        self.challenge.end_date = timezone.now() - timedelta(days=1)
        self.challenge.save()

        expected = {
            'error': 'Challenge is not active'
        }
        response = self.client.patch(self.url, self.data)
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_add_participant_team_to_challenge_when_some_members_have_already_participated(self):
        self.url = reverse_lazy('challenges:add_participant_team_to_challenge',
                                kwargs={'challenge_pk': self.challenge.pk,
                                        'participant_team_pk': self.participant_team2.pk})

        self.client.post(self.url, {})

        expected = {
            'error': 'Sorry, other team member(s) have already participated in the Challenge.'
            ' Please participate with a different team!',
            'challenge_id': self.challenge.pk,
            'participant_team_id': self.participant_team3.pk,
        }

        # submitting the request again as a new team
        self.url = reverse_lazy('challenges:add_participant_team_to_challenge',
                                kwargs={'challenge_pk': self.challenge.pk,
                                        'participant_team_pk': self.participant_team3.pk})

        response = self.client.post(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def remove_self_from_participant_team(request, participant_team_pk):
    """
    A user can remove himself from the participant team.
    """
    try:
        participant_team = ParticipantTeam.objects.get(pk=participant_team_pk)
    except ParticipantTeam.DoesNotExist:
        response_data = {'error': 'ParticipantTeam does not exist!'}
        return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

    try:
        participant = Participant.objects.get(user=request.user, team__pk=participant_team_pk)
    except:
        response_data = {'error': 'Sorry, you do not belong to this team!'}
        return Response(response_data, status=status.HTTP_401_UNAUTHORIZED)

    if get_list_of_challenges_for_participant_team([participant_team]).exists():
        response_data = {'error': 'Sorry, you cannot delete this team since it has taken part in challenge(s)!'}
        return Response(response_data, status=status.HTTP_403_FORBIDDEN)
    else:
        participant.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def remove_self_from_challenge_host_team(request, challenge_host_team_pk):
    """
    A user can remove himself from the challenge host team.
    """
    try:
        ChallengeHostTeam.objects.get(pk=challenge_host_team_pk)
    except ChallengeHostTeam.DoesNotExist:
        response_data = {'error': 'ChallengeHostTeam does not exist'}
        return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
    try:
        challenge_host = ChallengeHost.objects.filter(user=request.user.id, team_name__pk=challenge_host_team_pk)
        challenge_host.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
    except:
        response_data = {'error': 'Sorry, you do not belong to this team.'}
        return Response(response_data, status=status.HTTP_401_UNAUTHORIZED)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def invite_host_to_team(request, pk):

    try:
        challenge_host_team = ChallengeHostTeam.objects.get(pk=pk)
    except ChallengeHostTeam.DoesNotExist:
        response_data = {'error': 'ChallengeHostTeam does not exist'}
        return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

    serializer = InviteHostToTeamSerializer(data=request.data,
                                            context={'challenge_host_team': challenge_host_team,
                                                     'request': request})
    if serializer.is_valid():
        serializer.save()
        response_data = {
            'message': 'User has been added successfully to the host team'}
        return Response(response_data, status=status.HTTP_202_ACCEPTED)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def challenge_phase_list(request, challenge_pk):
    try:
        challenge = Challenge.objects.get(pk=challenge_pk)
    except Challenge.DoesNotExist:
        response_data = {'error': 'Challenge does not exist'}
        return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

    if request.method == 'GET':
        challenge_phase = ChallengePhase.objects.filter(challenge=challenge, is_public=True)
        paginator, result_page = paginated_queryset(challenge_phase, request)
        serializer = ChallengePhaseSerializer(result_page, many=True)
        response_data = serializer.data
        return paginator.get_paginated_response(response_data)

    elif request.method == 'POST':
        serializer = ChallengePhaseCreateSerializer(data=request.data,
                                                    context={'challenge': challenge})
        if serializer.is_valid():
            serializer.save()
            challenge_phase = get_challenge_phase_model(serializer.instance.pk)
            serializer = ChallengePhaseSerializer(challenge_phase)
            response_data = serializer.data
            return Response(response_data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
项目:cyphon    作者:dunbarcyber    | 项目源码 | 文件源码
def post(self, request):
        """
        Subscribes a user to push notifications
        """
        serializer = SubscribeSerializer(data=request.data)

        if serializer.is_valid() and request.user.is_authenticated:
            user = request.user
            user.push_notification_id = serializer.data['registration_id']
            try:
                user.save()
                return Response(status.HTTP_202_ACCEPTED)
            except IntegrityError:
                return Response(serializer.errors, status.HTTP_406_NOT_ACCEPTABLE)
        else:
            return Response(
                serializer.errors,
                status=status.HTTP_400_BAD_REQUEST
            )
项目:django-oscar-cybersource    作者:thelabnyc    | 项目源码 | 文件源码
def test_manipulate_total_pre_auth(self):
        """Test attempting to manipulate basket price when requesting an auth form"""
        product = self.create_product()

        resp = self.do_get_basket()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        basket_id = resp.data['id']

        resp = self.do_add_to_basket(product.id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['total_incl_tax'], '10.00')

        resp = self.do_checkout(basket_id, extra_data={
            "total": "2.00",  # Try and get $10 of product for only $2
        })
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:BackendAllStars    作者:belatrix    | 项目源码 | 文件源码
def employee_reset_password(request, employee_email):
    """
    This endpoint send an email to employee, with confirmation reset password url.
    ---
    responseMessages:
    - code: 404
      message: Not found
    - code: 406
      message: Request not acceptable
    """
    if request.method == 'GET':
        employee = get_object_or_404(Employee, email=employee_email)

        # Generate random uuid and save in employee
        employee.generate_reset_password_code()

        # Send email with reset password confirmation url
        subject = config.EMPLOYEE_RESET_PASSWORD_CONFIRMATION_SUBJECT
        current_site = Site.objects.get_current()
        employee_reset_password_api = reverse('employees:employee_reset_password', args=[employee.email])
        url = current_site.domain + employee_reset_password_api + employee.reset_password_code
        message = config.EMPLOYEE_RESET_PASSWORD_CONFIRMATION_MESSAGE % (url)

        try:
            send_email = EmailMessage(subject, message, to=[employee.email])
            send_email.send()
        except Exception as e:
            print(e)
            content = {'detail': config.EMAIL_SERVICE_ERROR}
            return Response(content, status=status.HTTP_406_NOT_ACCEPTABLE)

        content = {'detail': 'Confirmation email sent.',
                   'email': employee.email,
                   'reset_password_code': employee.reset_password_code}
        return Response(content, status=status.HTTP_200_OK)
项目:BackendAllStars    作者:belatrix    | 项目源码 | 文件源码
def give_badge_to(request, badge_id, to_employee_id, from_employee_id):
    """
    This endpoint saves badge assignation to employee
    ---
    response_serializer: stars.serializers.EmployeeBadgeSerializer
    responseMessages:
    - code: 400
      message: Bad request
    - code: 401
      message: Unauthorized. Authentication credentials were not provided. Invalid token.
    - code: 403
      message: Forbidden, authentication credentials were not provided
    - code: 404
      message: Not found (from_employee_id or to_employee_id or badge_id)
    - code: 406
      message: User is unable to give stars to itself.
    """
    if to_employee_id == from_employee_id:
        content = {'detail': config.USER_UNABLE_TO_GIVE_BADGES_ITSELF}
        return Response(content, status=status.HTTP_406_NOT_ACCEPTABLE)
    elif request.method == 'POST':
        badge = get_object_or_404(Badge, pk=badge_id)
        to_employee = get_object_or_404(Employee, pk=to_employee_id)
        from_employee = get_object_or_404(Employee, pk=from_employee_id)
        try:
            employee_badge = EmployeeBadge.objects.create(to_user=to_employee, assigned_by=from_employee, badge=badge)
        except Exception as e:
            print(e)
            content = {'detail': config.BADGE_UNIQUE_CONSTRAINT_FAILED}
            return Response(content, status=status.HTTP_406_NOT_ACCEPTABLE)
        serializer = EmployeeBadgeSerializer(employee_badge)
        return Response(serializer.data, status=status.HTTP_201_CREATED)
项目:kuzgun.io    作者:yigitgenc    | 项目源码 | 文件源码
def upload(self, request, parent_lookup_torrent=None):
        """
        Handles sent file, creates File object,
        chunks and writes it into Volume.UPLOAD.

        :return: Response
        """

        if parent_lookup_torrent:
            return Response(status=status.HTTP_406_NOT_ACCEPTABLE)

        uploaded_file_obj = request.data['file']
        uploaded_file_name, uploaded_file_ext = os.path.splitext(uploaded_file_obj.name)
        uploaded_file_name = '{}{}'.format(slugify(uploaded_file_name), uploaded_file_ext)
        uploaded_file_upload_path = '{}/{}'.format(self.request.user.username, uploaded_file_name)

        file_obj, created = File.objects.get_or_create(
            path=uploaded_file_upload_path,
            defaults={
                'volume': Volume.UPLOAD,
                'size': uploaded_file_obj.size
            }
        )

        if not created:
            return Response({
                'detail': "File already exists."
            }, status=status.HTTP_400_BAD_REQUEST)

        # Link file to authenticated user.
        request.user.files.add(file_obj)

        # Handle uploaded file.
        handle_uploaded_file(uploaded_file_obj, file_obj.full_path)

        return Response(status=status.HTTP_201_CREATED)
项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
def post(self, request):
        if not (request.POST.get('uuid') and
                request.POST.get('long') and
                request.POST.get('lat') and
                request.POST.get('bands')
        ):
            return Response("Missing arguments", status=status.HTTP_406_NOT_ACCEPTABLE)

        req_bands = request.POST.get('bands').split(',')
        for band in req_bands:
            if not (band in BTS.bands):
                return Response("Invalid Arguments", status=status.HTTP_400_BAD_REQUEST)

        pnt = GEOSGeometry(Point(float(request.POST.get('long')),
                                 float(request.POST.get('lat'))))

        with transaction.atomic():
            tower = BTS.objects.get(uuid=request.POST.get('uuid'))
            nearby_towers = BTS.objects.filter(
                location__distance_lt=(pnt,D(km=RANGE))).exclude(uuid=request.POST.get('uuid'))
            used_channels = dict.fromkeys(BTS.bands.keys(), set())
            for tower in nearby_towers:
                if (tower.band): #skip those without set bands
                    used_channels[tower.band].add(tower.channel)
            free_channels = dict.fromkeys(req_bands)
            for band in req_bands:
                free_channels[band] = BTS.bands[band]['valid_values'].difference(used_channels[band])
                if (len(free_channels[band]) > 0): #something available
                    return Response({ band : free_channels[band],
                                      'power_level' : POWER_LEVEL},
                                    status=status.HTTP_200_OK)
            return Response("No Available Bands", status=status.HTTP_404_NOT_FOUND)
项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
def post(self, request):
        if not (
                request.POST.get('uuid') and
                request.POST.get('lat') and
                request.POST.get('long') and
                request.POST.get('band') and
                request.POST.get('channel') and
                request.POST.get('power_level')
        ):
            return Response("Missing Arguments", status=status.HTTP_406_NOT_ACCEPTABLE)

        if not (
                request.POST.get('band') in BTS.bands and
                request.POST.get('channel').isdigit() and
                request.POST.get('power_level').isdigit()
        ):
            return Response("Invalid Arguments", status=status.HTTP_400_BAD_REQUEST)

        pnt = GEOSGeometry(Point(float(request.POST.get('long')),
                                 float(request.POST.get('lat'))))

        with transaction.atomic():
            tower = BTS.objects.get(uuid=request.POST.get('uuid')) 
            nearby_towers = BTS.objects.filter(
                location__distance_lt=(pnt,D(km=RANGE))).filter(
                    band=request.POST.get('band')).exclude(uuid=request.POST.get('uuid'))
            for t in nearby_towers:
                if (int(request.POST.get('channel')) == t.channel):
                    return Response("Channel In Use", status=status.HTTP_409_CONFLICT)
            #no one interfered
            tower.channel = int(request.POST.get('channel'))
            tower.location = pnt
            tower.band = request.POST.get('band')
            tower.save()
            return Response("Success", status=status.HTTP_200_OK)
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def post(self, request, format=None):
        # Wipe out any previous state data
        utils.clear_payment_method_states(request)

        # Validate the input
        c_ser = self.get_serializer(data=request.data)
        if not c_ser.is_valid():
            return Response(c_ser.errors, status.HTTP_406_NOT_ACCEPTABLE)

        # Freeze basket
        basket = c_ser.validated_data.get('basket')
        basket.freeze()

        # Save Order
        order = c_ser.save()
        request.session[CHECKOUT_ORDER_ID] = order.id

        # Send order_placed signal
        order_placed.send(sender=self, order=order, user=request.user, request=request)

        # Save payment steps into session for processing
        states = self._record_payments(
            request=request,
            order=order,
            methods=c_ser.fields['payment'].methods,
            data=c_ser.validated_data['payment'])
        utils.set_payment_method_states(order, request, states)

        # Return order data
        o_ser = OrderSerializer(order, context={ 'request': request })
        return Response(o_ser.data)
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_invalid_email_anon_user(self):
        basket_id = self._prepare_basket()
        data = self._get_checkout_data(basket_id)
        data['guest_email'] = ''
        data['payment'] = {
            'credit-card': {
                'enabled': True,
                'pay_balance': True,
            }
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['non_field_errors'][0], 'Guest email is required for anonymous checkouts')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_invalid_email_authed_user(self):
        self.login(is_staff=True, email=None)
        basket_id = self._prepare_basket()
        data = self._get_checkout_data(basket_id)
        data['guest_email'] = ''
        data['payment'] = {
            'credit-card': {
                'enabled': True,
                'pay_balance': True,
            }
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['non_field_errors'][0], 'Email address is required.')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_invalid_basket(self):
        self.login(is_staff=True)
        basket_id = self._prepare_basket()

        data = self._get_checkout_data(basket_id + 1)
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['basket'][0], 'Invalid hyperlink - Object does not exist.')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_no_payment_methods_provided(self):
        self.login(is_staff=True)
        basket_id = self._prepare_basket()

        data = self._get_checkout_data(basket_id)
        data.pop('payment', None)
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment'][0], 'This field is required.')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_no_payment_methods_enabled(self):
        self.login(is_staff=True)
        basket_id = self._prepare_basket()

        data = self._get_checkout_data(basket_id)
        data['payment'] = {
            'cash': {
                'enabled': False
            }
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment']['non_field_errors'][0], 'At least one payment method must be enabled.')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_no_payment_amount_provided(self):
        self.login(is_staff=True)
        basket_id = self._prepare_basket()

        data = self._get_checkout_data(basket_id)
        data['payment'] = {
            'cash': {
                'enabled': True,
                'pay_balance': False,
            }
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment']['cash']['non_field_errors'][0], 'Amount must be greater then 0.00 or pay_balance must be enabled.')

        data = self._get_checkout_data(basket_id)
        data['payment'] = {
            'cash': {
                'enabled': True,
                'pay_balance': False,
                'amount': '0.00'
            }
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment']['cash']['non_field_errors'][0], 'Amount must be greater then 0.00 or pay_balance must be enabled.')
项目:django-oscar-api-checkout    作者:thelabnyc    | 项目源码 | 文件源码
def test_provided_payment_method_not_permitted(self):
        basket_id = self._prepare_basket()

        # Cash payments not allowed since user isn't staff
        data = self._get_checkout_data(basket_id)
        data['payment'] = {
            'cash': {
                'enabled': True,
                'pay_balance': True,
            }
        }
        resp = self._checkout(data)
        self.assertEqual(resp.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(resp.data['payment']['non_field_errors'][0], 'At least one payment method must be enabled.')
项目:django-phone-login    作者:wejhink    | 项目源码 | 文件源码
def test_invalid_data(self):
        response = self.client.post(self.url, self.invalid_data, format='json')
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_participant_team_does_not_exist(self):
        self.url = reverse_lazy('participants:get_participant_team_details',
                                kwargs={'pk': self.participant_team.pk + 1})
        expected = {
            'error': 'ParticipantTeam does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_invite_participant_to_team_with_no_data(self):
        del self.data['email']
        response = self.client.post(self.url, self.data)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_participant_team_for_invite_does_not_exist(self):
        self.url = reverse_lazy('participants:invite_participant_to_team',
                                kwargs={'pk': self.participant_team.pk + 1})
        expected = {
            'error': 'ParticipantTeam does not exist'
        }
        response = self.client.post(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_participant_does_not_exist_in_team(self):
        self.url = reverse_lazy('participants:delete_participant_from_team',
                                kwargs={'participant_team_pk': self.participant_team.pk,
                                        'participant_pk': self.participant2.pk + 1
                                        })

        expected = {
            'error': 'Participant does not exist'
        }

        response = self.client.delete(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_when_participant_is_admin_and_wants_to_delete_himself(self):
        self.url = reverse_lazy('participants:delete_participant_from_team',
                                kwargs={'participant_team_pk': self.participant_team.pk,
                                        'participant_pk': self.participant1.pk
                                        })

        expected = {
            'error': 'You are not allowed to remove yourself since you are admin. Please delete the team if you want to do so!'  # noqa: ignore=E501
        }

        response = self.client.delete(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_when_participant_team_does_not_exist(self):
        self.url = reverse_lazy('participants:remove_self_from_participant_team',
                                kwargs={'participant_team_pk': self.participant_team.pk + 1
                                        })

        expected = {
            'error': 'ParticipantTeam does not exist!'
        }

        response = self.client.delete(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_host_team_does_not_exist(self):
        self.url = reverse_lazy('hosts:get_challenge_host_team_details', kwargs={'pk': self.challenge_host_team.pk + 1})
        expected = {
            'error': 'ChallengeHostTeam does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_host_team_for_challenge_host_does_not_exist(self):
        self.url = reverse_lazy('hosts:get_challenge_host_list',
                                kwargs={'challenge_host_team_pk': self.challenge_host_team.pk + 1})
        expected = {
            'error': 'ChallengeHostTeam does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_host_does_not_exist(self):
        self.url = reverse_lazy('hosts:get_challenge_host_details',
                                kwargs={'challenge_host_team_pk': self.challenge_host_team.pk,
                                        'pk': self.challenge_host.pk + 1})
        expected = {
            'error': 'ChallengeHost does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_when_challenge_host_team_does_not_exist(self):
        self.url = reverse_lazy('hosts:remove_self_from_challenge_host_team',
                                kwargs={'challenge_host_team_pk': self.challenge_host_team.pk + 1
                                        })

        expected = {
            'error': 'ChallengeHostTeam does not exist'
        }

        response = self.client.delete(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_host_team_for_invite_does_not_exist(self):
        self.url = reverse_lazy('hosts:invite_host_to_team',
                                kwargs={'pk': self.challenge_host_team.pk + 1})
        expected = {
            'error': 'ChallengeHostTeam does not exist'
        }
        response = self.client.post(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_incorrect_url_pattern_submission_count(self):
        self.url = reverse_lazy('analytics:get_submission_count',
                                kwargs={'challenge_pk': self.challenge.pk,
                                        'duration': 'INCORRECT'})
        expected = {
            'error': 'Wrong URL pattern!'
        }
        response = self.client.get(self.url, {}, format='json')
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(response.data, expected)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_host_team_for_challenge_does_not_exist(self):
        self.url = reverse_lazy('challenges:get_challenge_list',
                                kwargs={'challenge_host_team_pk': self.challenge_host_team.pk + 1})
        expected = {
            'error': 'ChallengeHostTeam does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_does_not_exist(self):
        self.url = reverse_lazy('challenges:get_challenge_detail',
                                kwargs={'challenge_host_team_pk': self.challenge_host_team.pk,
                                        'challenge_pk': self.challenge.pk + 1})
        expected = {
            'error': 'Challenge does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_host_team_for_challenge_does_not_exist(self):
        self.url = reverse_lazy('challenges:get_challenge_detail',
                                kwargs={'challenge_host_team_pk': self.challenge_host_team.pk + 1,
                                        'challenge_pk': self.challenge.pk})
        expected = {
            'error': 'ChallengeHostTeam does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_when_challenge_host_maps_a_participant_team_with_his_challenge(self):
        self.url = reverse_lazy('challenges:add_participant_team_to_challenge',
                                kwargs={'challenge_pk': self.challenge2.pk,
                                        'participant_team_pk': self.participant_team2.pk})
        expected = {
            'error': 'Sorry, You cannot participate in your own challenge!',
            'challenge_id': self.challenge2.pk,
            'participant_team_id': self.participant_team2.pk
        }
        response = self.client.post(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_participant_team_for_mapping_with_challenge_does_not_exist(self):
        self.url = reverse_lazy('challenges:add_participant_team_to_challenge',
                                kwargs={'challenge_pk': self.challenge.pk,
                                        'participant_team_pk': self.participant_team.pk + 3})
        expected = {
            'error': 'ParticipantTeam does not exist'
        }
        response = self.client.post(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_incorrent_url_pattern_challenges(self):
        self.url = reverse_lazy('challenges:get_all_challenges',
                                kwargs={'challenge_time': "INCORRECT"})
        expected = {'error': 'Wrong url pattern!'}
        response = self.client.get(self.url, {}, format='json')
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
        self.assertEqual(response.data, expected)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_get_challenge_by_pk_when_challenge_does_not_exists(self):
        self.url = reverse_lazy('challenges:get_challenge_by_pk',
                                kwargs={'pk': self.challenge3.pk + 10})
        expected = {
            'error': 'Challenge does not exist!'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_get_challenge_with_incorrect_url_pattern(self):
        self.url = reverse_lazy('challenges:get_challenges_based_on_teams')

        expected = {
            'error': 'Invalid url pattern!'
        }
        response = self.client.get(self.url, {'invalid_q_param': 'invalidvalue'})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
项目:EvalAI    作者:Cloud-CV    | 项目源码 | 文件源码
def test_particular_challenge_for_challenge_phase_does_not_exist(self):
        self.url = reverse_lazy('challenges:get_challenge_phase_list',
                                kwargs={'challenge_pk': self.challenge.pk + 1})
        expected = {
            'error': 'Challenge does not exist'
        }
        response = self.client.get(self.url, {})
        self.assertEqual(response.data, expected)
        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)