Exemplo n.º 1
0
def validate(raw_schema, target=None, **kwargs):
    """
    Given the python representation of a JSONschema as defined in the swagger
    spec, validate that the schema complies to spec.  If `target` is provided,
    that target will be validated against the provided schema.
    """
    schema = schema_validator(raw_schema, **kwargs)
    if target is not None:
        validate_object(target, schema=schema, **kwargs)
Exemplo n.º 2
0
def validate(raw_schema, target=None, **kwargs):
    """
    Given the python representation of a JSONschema as defined in the swagger
    spec, validate that the schema complies to spec.  If `target` is provided,
    that target will be validated against the provided schema.
    """
    schema = schema_validator(raw_schema, **kwargs)

    if target is not None:
        validate_object(target, schema=schema, **kwargs)
Exemplo n.º 3
0
def validate_items(objs, field_validators, **kwargs):
    errors = ErrorList()
    for obj, _field_validators in zip(objs, field_validators):
        try:
            validate_object(obj, field_validators=_field_validators, **kwargs)
        except ValidationError as e:
            errors.add_error(e.detail)

    if errors:
        raise ValidationError(errors)
Exemplo n.º 4
0
def validate_items(objs, validators):
    errors = []
    for obj, validator in zip(objs, validators):
        try:
            validate_object(obj, validator, inner=True)
        except ValidationError as e:
            errors.extend(list(e.messages))

    if errors:
        raise SafeNestedValidationError(errors)
Exemplo n.º 5
0
def validate_items(objs, field_validators, **kwargs):
    errors = ErrorList()
    for obj, _field_validators in zip(objs, field_validators):
        try:
            validate_object(
                obj,
                field_validators=_field_validators,
                **kwargs
            )
        except ValidationError as e:
            errors.add_error(e.detail)

    if errors:
        raise ValidationError(errors)
def test_header_type_validation_for_invalid_values(type_, value):
    header_definition = single_header_validator({
        'type': type_,
    })
    validators = construct_header_validators(header_definition=header_definition, context={})

    with pytest.raises(ValidationError) as err:
        validate_object(value, validators)

    assert 'type' in err.value.detail
    assert_error_message_equal(
        err.value.detail['type'][0],
        MESSAGES['type']['invalid'],
    )
Exemplo n.º 7
0
def test_header_type_validation_for_invalid_values(type_, value):
    header_definition = single_header_validator({
        'type': type_,
    })
    validators = construct_header_validators(
        header_definition=header_definition, context={})

    with pytest.raises(ValidationError) as err:
        validate_object(value, validators)

    assert 'type' in err.value.detail
    assert_error_message_equal(
        err.value.detail['type'][0],
        MESSAGES['type']['invalid'],
    )
def test_header_type_validation_for_invalid_values(type_, value):
    from django.core.exceptions import ValidationError
    serializer = HeaderSerializer(
        data={
            'type': type_,
        }
    )
    assert serializer.is_valid()
    header_definition = serializer.object
    validators = construct_header_validators(header_definition=header_definition, context={})

    with pytest.raises(ValidationError) as err:
        validate_object(value, validators, inner=True)

    assert 'type' in err.value.messages[0]
    assert_error_message_equal(
        err.value.messages[0]['type'][0],
        MESSAGES['type']['invalid'],
    )
Exemplo n.º 9
0
 def __call__(self, value, **kwargs):
     return validate_object(value, schema=self.schema, **kwargs)
Exemplo n.º 10
0
 def __call__(self, value, **kwargs):
     return validate_object(
         value,
         schema=self.schema,
         **kwargs
     )
Exemplo n.º 11
0
 def __call__(self, value):
     return validate_object(value, self.validators, inner=True)
Exemplo n.º 12
0
def validate_properties(obj, key, validators):
    if obj is EMPTY:
        return
    validate_object(obj.get(key, EMPTY), validators, inner=True)
Exemplo n.º 13
0
 def __call__(self, value, **kwargs):
     return validate_object(
         value,
         schema=self.context['definitions'][self.reference],
         **kwargs)