Example #1
0
 def validate(self, request, match_id, team, *args, **kwargs):
     kwargs['match_id'] = match_id
     super().validate(request, *args, **kwargs)
     match = Match.objects.filter(id=match_id).first()
     if not match:
         raise NotFoundError(
             error_message=RESOURCE_NOT_FOUND_MESSAGE.format(MATCH),
             error_code=INVALID_MATCH_ID,
         )
     if not match.is_operable_match():
         raise BadRequestError(
             error_message=MATCH_IS_FINISHED,
             error_code=INVALID_MATCH_STATUS,
         )
     if team not in self.VALID_TEAMS:
         raise BadRequestError(
             error_message=TEAM_NOT_ONE_OF.format(','.join(
                 self.VALID_TEAMS)),
             error_code=INVALID_TEAM_SELECTION,
         )
     if not match.can_substract_points(team):
         raise BadRequestError(
             error_message=CAN_NOT_SUBSCRACT_POINTS,
             error_code=INVALID_SET_STATUS,
         )
     self.common = {'match': match}
Example #2
0
 def validate(self, request, match_id, team, *args, **kwargs):
     kwargs['match_id'] = match_id
     super().validate(request, *args, **kwargs)
     if not self.common['match'].is_operable_match():
         raise BadRequestError(
             error_message=MATCH_IS_FINISHED,
             error_code=INVALID_MATCH_STATUS,
         )
     if team not in self.VALID_TEAMS:
         raise BadRequestError(
             error_message=TEAM_NOT_ONE_OF.format(','.join(
                 self.VALID_TEAMS)),
             error_code=INVALID_TEAM_SELECTION,
         )
Example #3
0
 def wrapper(*args, **kwargs):
     try:
         return validate_request_schema(*args, **kwargs)
     except jsonschema.exceptions.ValidationError as error:
         raise BadRequestError(
             error_message=error.message,
             error_code=NOT_A_JSON_BODY,
         )
Example #4
0
 def validate(self, request, *args, **kwargs):
     super().validate(request, *args, **kwargs)
     if request.GET.get('page',
                        False) is not False and request.GET.get('page') < 1:
         raise BadRequestError(
             error_message='Page number must be positive',
             error_code=INVALID_PAGE,
         )
Example #5
0
 def validate(self, request, *args, **kwargs):
     super().validate(request, *args, **kwargs)
     self.common['body'] = json.loads(request.body)
     if self.common['body']['sets_number'] % 2 == 0:
         raise BadRequestError(
             error_message=FIELD_MUST_BE_ODD.format('sets_number'),
             error_code=REQUIRED_TO_BE_ODD,
         )
Example #6
0
    def wrapper(*args, **kwargs):
        try:
            return run(*args, **kwargs)
        except JSONDecodeError:

            return get_json_response_from_http_error(
                BadRequestError(
                    error_message='Not a json body',
                    error_code=NOT_A_JSON_BODY,
                ))
Example #7
0
def validate_token(view, request, *args, **kwargs):
    match = Match.objects.filter(id=kwargs['match_id']).first()
    if not match:
        raise NotFoundError(
            error_message=RESOURCE_NOT_FOUND_MESSAGE.format(MATCH),
            error_code=INVALID_MATCH_ID,
        )
    if 'token' in request.GET.keys():
        if match.token == request.GET.get('token'):
            view.common['match'] = match
            return
    raise BadRequestError(
        error_message=INVALID_TOKEN_MESSAGE,
        error_code=INVALID_TOKEN,
    )
Example #8
0
 def validate(self, request, *args, **kwargs):
     super().validate(request, *args, **kwargs)
     if not request.GET.get('access_code', False):
         raise BadRequestError(
             error_message=REQUIRED_QUERY_PARAMETER.format('access_code'),
             error_code=REQUIRED_QUERY_PARAM,
         )
     match = Match.objects.filter(
         access_code=request.GET.get('access_code'),
         status=Match.Status.LIVE.value,
     ).first()
     if not match:
         raise NotFoundError(
             error_message=RESOURCE_NOT_FOUND_MESSAGE.format(MATCH),
             error_code=INVALID_ACCESS_CODE,
         )
     self.common = {'match': match}
Example #9
0
 def validate_request_content_type(self, request):
     if self.content_type:
         if not request.content_type == self.content_type:
             raise BadRequestError('Content type must be {}.'.format(
                 self.content_type))
Example #10
0
 def validate_request_schema(self, request):
     if self.required_body and not request.body:
         raise BadRequestError('You must pass a body')
     if self.schema:
         request_params = json.loads(request.body)
         validate_request(instance=request_params, schema=self.schema)
Example #11
0
 def get_think():
     raise BadRequestError(
         error_message='Invalid field error',
         error_code='SOME_ERROR_CODE',
     )