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)
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)
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
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)
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)
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
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)
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)