Exemplo n.º 1
0
def test_responses_are_validated():
    """
    Sanity check that the individual response objects are validated.
    """
    context = {'deferred_references': set()}

    with pytest.raises(ValidationError) as err:
        definitions_validator(
            {
                'responses': {
                    'WrongType': [],
                    'AlsoWrongType': None,
                },
            },
            context=context)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'responses.WrongType',
    )
    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'responses.AlsoWrongType',
    )
Exemplo n.º 2
0
def test_parameters_definitions_type_validation_for_invalid_types(value):
    context = {'deferred_references': set()}
    with pytest.raises(ValidationError) as err:
        definitions_validator({'parameters': value}, context=context)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'parameters',
    )
Exemplo n.º 3
0
def test_responses_definitions_type_validation_for_invalid_types(value):
    context = {'deferred_references': set()}
    with pytest.raises(ValidationError) as err:
        definitions_validator({'responses': value}, context=context)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'responses',
    )
Exemplo n.º 4
0
def test_deferred_references_are_validated():
    deferred_references = set()
    context = {"deferred_references": deferred_references}

    definitions = {
        "definitions": {"SomeReference": {"type": OBJECT, "properties": {"address": {"$ref": "#/definitions/Address"}}}}
    }
    with pytest.raises(ValidationError) as err:
        definitions_validator(definitions, context=context)

    assert_message_in_errors(MESSAGES["reference"]["undefined"], err.value.detail, "definitions.Address")
Exemplo n.º 5
0
def test_references_end_up_in_deferred_referrences():
    deferred_references = set()
    context = {"deferred_references": deferred_references}

    definitions = {
        "definitions": {
            "SomeReference": {"type": OBJECT, "properties": {"address": {"$ref": "#/definitions/Address"}}},
            "Address": {"type": STRING},
        }
    }
    definitions_validator(definitions, context=context)
    assert "#/definitions/Address" in deferred_references
Exemplo n.º 6
0
def test_parameters_definitions_are_not_required():
    context = {'deferred_references': set()}
    try:
        definitions_validator({}, context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'parameters',
        errors,
    )
Exemplo n.º 7
0
def test_responses_definitions_are_not_required():
    context = {'deferred_references': set()}
    try:
        definitions_validator({}, context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'responses',
        errors,
    )
Exemplo n.º 8
0
def test_single_parameter_type_validation(value):
    context = {'deferred_references': set()}

    with pytest.raises(ValidationError) as err:
        definitions_validator({
            'parameters': {
                'SomeParameter': value,
            },
        },
                              context=context)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'parameters.SomeParameter',
    )
Exemplo n.º 9
0
def SchemaFactory(**kwargs):
    raw_schema = RawSchemaFactory(**kwargs)

    context = {'deferred_references': set()}
    definitions = definitions_validator(raw_schema, context=context)

    swagger_schema = swagger_schema_validator(raw_schema, context=definitions)

    return swagger_schema
Exemplo n.º 10
0
def test_responses_definitions_with_valid_response_definition():
    context = {'deferred_references': set()}
    response_definition = ResponseDefinitionFactory()
    try:
        definitions_validator({
            'responses': {
                'SomeResponse': response_definition,
            },
        }, context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'responses',
        errors,
    )
Exemplo n.º 11
0
def SchemaFactory(**kwargs):
    raw_schema = RawSchemaFactory(**kwargs)

    context = {'deferred_references': set()}
    definitions = definitions_validator(raw_schema, context=context)

    swagger_schema = swagger_schema_validator(raw_schema, context=definitions)

    return swagger_schema
Exemplo n.º 12
0
def parse(raw_schema):
    context = {
        'deferred_references': set(),
    }
    swagger_definitions = definitions_validator(raw_schema, context=context)

    swagger_schema = swagger_schema_validator(
        raw_schema,
        context=swagger_definitions,
    )
    return swagger_schema
Exemplo n.º 13
0
def test_responses_definitions_with_valid_response_definition():
    context = {'deferred_references': set()}
    response_definition = ResponseDefinitionFactory()
    try:
        definitions_validator(
            {
                'responses': {
                    'SomeResponse': response_definition,
                },
            },
            context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'responses',
        errors,
    )
Exemplo n.º 14
0
def test_basic_valid_parameter():
    context = {'deferred_references': set()}
    raw_parameter = ParameterFactory()
    try:
        definitions_validator(
            {
                'parameters': {
                    'SomeParameter': raw_parameter,
                },
            },
            context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'parameters',
        errors,
    )
Exemplo n.º 15
0
def parse(raw_schema):
    context = {
        'deferred_references': set(),
    }
    swagger_definitions = definitions_validator(raw_schema, context=context)

    swagger_schema = swagger_schema_validator(
        raw_schema,
        context=swagger_definitions,
    )
    return swagger_schema
Exemplo n.º 16
0
def test_references_end_up_in_deferred_referrences():
    deferred_references = set()
    context = {'deferred_references': deferred_references}

    definitions = {
        'definitions': {
            'SomeReference': {
                'type': OBJECT,
                'properties': {
                    'address': {
                        '$ref': '#/definitions/Address',
                    }
                }
            },
            'Address': {
                'type': STRING,
            }
        }
    }
    definitions_validator(definitions, context=context)
    assert '#/definitions/Address' in deferred_references
Exemplo n.º 17
0
def test_references_end_up_in_external_deferred_references():
    deferred_references = set()
    context = {'deferred_references': deferred_references}

    definitions = {
        'definitions': {
            'SomeReference': {
                'type': OBJECT,
                'properties': {
                    'address': {
                        '$ref': 'jsonschemas/ext.json#',
                    }
                }
            },
            'Address': {
                'type': STRING,
            }
        }
    }
    definitions_validator(definitions, context=context, base_path=DIR)
    assert 'jsonschemas/ext.json#' in deferred_references
Exemplo n.º 18
0
def test_responses_are_validated():
    """
    Sanity check that the individual response objects are validated.
    """
    context = {'deferred_references': set()}

    with pytest.raises(ValidationError) as err:
        definitions_validator({
            'responses': {
                'WrongType': [],
                'AlsoWrongType': None,
            },
        }, context=context)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'responses.WrongType',
    )
    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'responses.AlsoWrongType',
    )
Exemplo n.º 19
0
def test_deferred_references_are_validated():
    deferred_references = set()
    context = {'deferred_references': deferred_references}

    definitions = {
        'definitions': {
            'SomeReference': {
                'type': OBJECT,
                'properties': {
                    'address': {
                        '$ref': '#/definitions/Address',
                    }
                }
            },
        }
    }
    with pytest.raises(ValidationError) as err:
        definitions_validator(definitions, context=context)

    assert_message_in_errors(
        MESSAGES['reference']['undefined'],
        err.value.detail,
        'definitions.Address',
    )