Ejemplo n.º 1
0
    def test_basic_validation_none_object(self, validate_type):
        """Check that validate_type is not called when object is None"""
        f = Field('f')
        basic_validation(f, None)
        self.assertFalse(validate_type.called)

        # Also ensure that it is called
        basic_validation(f, object())
        self.assertTrue(validate_type.called)
Ejemplo n.º 2
0
    def test_basic_validation_none_object(self, validate_type):
        """Check that validate_type is not called when object is None"""
        f = Field('f')
        basic_validation(f, None)
        self.assertFalse(validate_type.called)

        # Also ensure that it is called
        basic_validation(f, object())
        self.assertTrue(validate_type.called)
Ejemplo n.º 3
0
 def _validate(self, obj, skip_required=False):
     obj = basic_validation(self, obj, skip_required=skip_required)
     obj = obj or {}
     return validate_size(self, obj, len(obj),
                          minimum=self.minimum,
                          maximum=self.maximum,
                          msg=self.error_message)
Ejemplo n.º 4
0
 def _validate(self, obj, skip_required=False):
     obj = basic_validation(self, obj, skip_required=skip_required)
     obj = obj or {}
     return validate_size(self, obj, len(obj),
                          minimum=self.minimum,
                          maximum=self.maximum,
                          msg=self.error_message)
Ejemplo n.º 5
0
 def _validate(self, obj, skip_required=False):
     obj = basic_validation(self, obj, skip_required=skip_required)
     if obj is None:
         return obj
     obj = validate_size(self, obj, obj,
                         minimum=self.minimum,
                         maximum=self.maximum,
                         msg=self.error_message)
     return obj
Ejemplo n.º 6
0
 def _validate(self, obj, skip_required=False):
     obj = basic_validation(self, obj, skip_required=skip_required)
     if obj is None:
         return obj
     obj = validate_size(self, obj, obj,
                         minimum=self.minimum,
                         maximum=self.maximum,
                         msg=self.error_message)
     return obj
Ejemplo n.º 7
0
    def _validate(self, obj, skip_required=False):
        """
        Just makes a size check on top of instance type check

        :param datetime obj:
        :return: The object unchanged
        :rtype: datetime
        :raises: ValidationException
        """
        obj = basic_validation(self, obj, skip_required=skip_required)
        return validate_size(self, obj, obj,
                             minimum=self.minimum,
                             maximum=self.maximum,
                             msg=self.error_message)
Ejemplo n.º 8
0
    def _validate(self, obj, skip_required=False):
        """
        Just makes a size check on top of instance type check

        :param datetime obj:
        :return: The object unchanged
        :rtype: datetime
        :raises: ValidationException
        """
        obj = basic_validation(self, obj, skip_required=skip_required)
        return validate_size(self, obj, obj,
                             minimum=self.minimum,
                             maximum=self.maximum,
                             msg=self.error_message)
Ejemplo n.º 9
0
    def _validate(self, obj, skip_required=False):
        """
        An object to be validated

        :param object obj:
        :param bool skip_required: If this is set to True
            then the required statement will be skipped
            regardless of whether the field is actually
            required or not.  This is useful for circumstances
            where you want validations to run and the field is
            normally required but not in this case.  See the
            restmixins.Update for an example.
        :return: The same exact object simple validated.
        :rtype: object
        :raises: ripozo.exceptions.ValidationException
        """
        return basic_validation(self, obj, skip_required=skip_required)
Ejemplo n.º 10
0
    def _validate(self, obj, skip_required=False):
        """
        An object to be validated

        :param object obj:
        :param bool skip_required: If this is set to True
            then the required statement will be skipped
            regardless of whether the field is actually
            required or not.  This is useful for circumstances
            where you want validations to run and the field is
            normally required but not in this case.  See the
            restmixins.Update for an example.
        :return: The same exact object simple validated.
        :rtype: object
        :raises: ripozo.exceptions.ValidationException
        """
        return basic_validation(self, obj, skip_required=skip_required)
Ejemplo n.º 11
0
    def _validate(self, obj, skip_required=False):
        """
        Validates the object.  It makes a call to super checking if the input
        can be None

        :param unicode obj:
        :return:
        :rtype: unicode
        :raises: ValidationException
        """
        obj = basic_validation(self, obj, skip_required=skip_required)
        if obj is None:
            return obj
        obj = validate_size(self, obj, len(obj),
                            minimum=self.minimum,
                            maximum=self.maximum,
                            msg=self.error_message)
        obj = validate_regex(self, obj, regex=self.regex)
        return obj
Ejemplo n.º 12
0
    def _validate(self, obj, skip_required=False):
        """
        Validates the object.  It makes a call to super checking if the input
        can be None

        :param unicode obj:
        :return:
        :rtype: unicode
        :raises: ValidationException
        """
        obj = basic_validation(self, obj, skip_required=skip_required)
        if obj is None:
            return obj
        obj = validate_size(self, obj, len(obj),
                            minimum=self.minimum,
                            maximum=self.maximum,
                            msg=self.error_message)
        obj = validate_regex(self, obj, regex=self.regex)
        return obj
Ejemplo n.º 13
0
 def test_basic_validation_skip_required(self):
     """Tests when skip_required is True and the object is None"""
     f = Field('f', required=True)
     resp = basic_validation(f, None, skip_required=True)
     self.assertIsNone(resp)
Ejemplo n.º 14
0
 def test_basic_validation(self):
     """Success case for basic_validation"""
     f = Field('f', required=True)
     obj = object()
     resp = basic_validation(f, obj, skip_required=False)
     self.assertIs(resp, obj)
Ejemplo n.º 15
0
 def test_basic_validation_skip_required(self):
     """Tests when skip_required is True and the object is None"""
     f = Field('f', required=True)
     resp = basic_validation(f, None, skip_required=True)
     self.assertIsNone(resp)
Ejemplo n.º 16
0
 def test_basic_validation(self):
     """Success case for basic_validation"""
     f = Field('f', required=True)
     obj = object()
     resp = basic_validation(f, obj, skip_required=False)
     self.assertIs(resp, obj)