def test_api_check_default_succeed(property_spec):
    definitions = {
        'injected_definition': {
            'properties': {
                'property': property_spec,
            },
        },
    }

    # Success if no exception are raised
    validate_definitions(definitions, lambda x: x)
예제 #2
0
def test_api_check_default_succeed(property_spec):
    definitions = {
        'injected_definition': {
            'properties': {
                'property': property_spec,
            },
        },
    }

    # Success if no exception are raised
    validate_definitions(definitions, lambda x: x)
def test_multiple_types_fail():
    definitions = {
        'definition_1': {
            'type': ['number', 'boolean'],
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert excinfo.value.args[0].startswith('type must be a string; lists are not allowed')
def test_type_array_without_items_succeed_fails():
    definitions = {
        'definition_1': {
            'type': 'array',
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert str(excinfo.value) == 'Definition of type array must define `items` property (definition #/definitions/definition_1).'
예제 #5
0
def test_type_array_with_items_succeed_validation():
    definitions = {
        'definition_1': {
            'type': 'array',
            'items': {
                'type': 'string',
            },
        },
    }

    # Success if no exception are raised
    validate_definitions(definitions, lambda x: x)
def test_type_array_with_items_succeed_validation():
    definitions = {
        'definition_1': {
            'type': 'array',
            'items': {
                'type': 'string',
            },
        },
    }

    # Success if no exception are raised
    validate_definitions(definitions, lambda x: x)
def test_multiple_types_fail():
    definitions = {
        'definition_1': {
            'type': ['number', 'boolean'],
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert excinfo.value.args[0].startswith(
        'type must be a string; lists are not allowed')
예제 #8
0
def test_type_array_without_items_succeed_fails():
    definitions = {
        'definition_1': {
            'type': 'array',
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert str(
        excinfo.value
    ) == 'Definition of type array must define `items` property (definition #/definitions/definition_1).'
예제 #9
0
def test_multiple_types_fail():
    definitions = {
        'definition_1': {
            'type': ['number', 'boolean'],
        },
    }

    with pytest.raises(
            SwaggerValidationError,
            match=
            r"In definition of .*, type must be a string; lists are not allowed \(.*\)",
    ) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert str(definitions['definition_1']['type']) in str(excinfo.value)
예제 #10
0
def test_api_check_default_fails(property_spec, validator, instance):
    definitions = {
        'injected_definition': {
            'properties': {
                'property': property_spec,
            },
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    validation_error = excinfo.value.args[1]
    assert validation_error.instance == instance
    assert validation_error.validator == validator
def test_api_check_default_fails(property_spec, validator, instance):
    definitions = {
        'injected_definition': {
            'properties': {
                'property': property_spec,
            },
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    validation_error = excinfo.value.args[1]
    assert validation_error.instance == instance
    assert validation_error.validator == validator
예제 #12
0
def test_inline_model_is_not_valid_validation_fails():
    definitions = {
        'definition_1': {
            'properties': {
                'property': {
                    'type': 'array',
                },
            },
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert str(excinfo.value) == 'Definition of type array must define `items` property ' \
                                 '(definition #/definitions/definition_1/properties/property).'
def test_inline_model_is_not_valid_validation_fails():
    definitions = {
        'definition_1': {
            'properties': {
                'property': {
                    'type': 'array',
                },
            },
        },
    }

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_definitions(definitions, lambda x: x)

    assert str(excinfo.value) == 'Definition of type array must define `items` property ' \
                                 '(definition #/definitions/definition_1/properties/property).'