コード例 #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)
コード例 #2
0
ファイル: validations.py プロジェクト: ezramorris/ripozo
    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)
コード例 #3
0
ファイル: common.py プロジェクト: ezramorris/ripozo
 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)
コード例 #4
0
ファイル: common.py プロジェクト: vaughnderson-su2/ripozo
 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)
コード例 #5
0
ファイル: common.py プロジェクト: ezramorris/ripozo
 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
コード例 #6
0
ファイル: common.py プロジェクト: vaughnderson-su2/ripozo
 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
コード例 #7
0
ファイル: common.py プロジェクト: ezramorris/ripozo
    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)
コード例 #8
0
ファイル: common.py プロジェクト: vaughnderson-su2/ripozo
    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)
コード例 #9
0
ファイル: field.py プロジェクト: ezramorris/ripozo
    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)
コード例 #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)
コード例 #11
0
ファイル: common.py プロジェクト: ezramorris/ripozo
    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
コード例 #12
0
ファイル: common.py プロジェクト: vaughnderson-su2/ripozo
    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
コード例 #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)
コード例 #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)
コード例 #15
0
ファイル: validations.py プロジェクト: ezramorris/ripozo
 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)
コード例 #16
0
ファイル: validations.py プロジェクト: ezramorris/ripozo
 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)