Exemplo n.º 1
0
 def validate(self, user_answer):
     """
     Validate that the users answer is a string and only contains alphanumeric characters
     :param user_answer: The answer the user provided for the response
     :return: ValidationResult(): An object containing the result of the validation
     """
     result = ValidationResult(False)
     if isinstance(user_answer, str):
         result.is_valid = not user_answer.isspace()
     else:
         result.is_valid = False
         result.errors.append(AbstractValidator.NOT_STRING)
     return result
    def validate(self, user_answer):
        result = ValidationResult(False)
        try:
            integer_value = int(user_answer)        # NOQA
            if integer_value > 9999999999:          # 10 digits
                result.is_valid = False
                result.errors.append(AbstractValidator.INTEGER_TOO_LARGE)
                return result

            result.is_valid = True
        except Exception:
            result.is_valid = False
            result.errors.append(AbstractValidator.NOT_INTEGER)
        return result
Exemplo n.º 3
0
    def validate(self, user_answer):
        """
        Validate that the users answer is an integer
        :param user_answer: The answer the user provided for the response
        :return: ValidationResult(): An object containing the result of the validation
        """
        result = ValidationResult(False)
        try:
            integer_value = int(user_answer)  # NOQA
            if integer_value > 9999999999:  # 10 digits
                result.is_valid = False
                result.errors.append(AbstractValidator.INTEGER_TOO_LARGE)
                return result

            result.is_valid = True
        except (ValueError, TypeError):
            result.is_valid = False
            result.errors.append(AbstractValidator.NOT_INTEGER)
        return result
    def validate(self, user_answer):
        validation_result = ValidationResult()
        validation_result.is_valid = False

        if isinstance(user_answer, list):
            self._validate_list(user_answer, validation_result)
        else:
            self._validate_single(user_answer, validation_result)

        # We only want ONE error message
        if not validation_result.is_valid:
            validation_result.errors.append(AbstractValidator.MANDATORY)

        return validation_result
Exemplo n.º 5
0
    def validate(self, user_answer):
        """
        Validate that a field is mandatory
        :param user_answer: The answer the user provided for the response
        :return: ValidationResult(): An object containing the result of the validation
        """
        validation_result = ValidationResult()
        validation_result.is_valid = False

        if isinstance(user_answer, list):
            self._validate_list(user_answer, validation_result)
        else:
            self._validate_single(user_answer, validation_result)

        # We only want ONE error message
        if not validation_result.is_valid:
            validation_result.errors.append(AbstractValidator.MANDATORY)

        return validation_result