Example #1
0
def test_paths_is_required():
    raw_schema = RawSchemaFactory()
    raw_schema.pop('paths', None)

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['required']['required'],
        err.value.detail,
        'required.paths',
    )
Example #2
0
def test_paths_is_required():
    raw_schema = RawSchemaFactory()
    raw_schema.pop('paths', None)

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['required']['required'],
        err.value.detail,
        'paths.required',
    )
Example #3
0
def test_consumes_not_required():
    raw_schema = RawSchemaFactory()
    raw_schema.pop('consumes', None)

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'consumes',
        errors,
    )
def test_consumes_not_required():
    raw_schema = RawSchemaFactory()
    raw_schema.pop('consumes', None)

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'consumes',
        errors,
    )
Example #5
0
def test_info_field_is_required():
    """
    Test that the info field is required for overall schema validation.
    """
    raw_schema = RawSchemaFactory()
    raw_schema.pop('info', None)

    assert 'info' not in raw_schema

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['required']['required'],
        err.value.detail,
        'required.info',
    )
Example #6
0
def test_swagger_field_is_required():
    """
    Test that the info field is required for overall schema validation.
    """
    raw_schema = RawSchemaFactory()
    raw_schema.pop('swagger', None)

    assert 'swagger' not in raw_schema

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['required']['required'],
        err.value.detail,
        'required.swagger',
    )
Example #7
0
def test_version_must_be_a_string(value):
    data = RawSchemaFactory(swagger=value, )
    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(data)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'swagger.type',
    )
Example #8
0
def test_base_path_is_not_required():
    """
    Test that the info field is required for overall schema validation.
    """
    raw_schema = RawSchemaFactory()
    raw_schema.pop('basePath', None)

    assert 'basePath' not in raw_schema

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'basePath',
        errors,
    )
Example #9
0
def test_swagger_field_with_invalid_version():
    raw_schema = RawSchemaFactory(swagger='not-valid')

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'swagger.enum',
    )
Example #10
0
def test_swagger_field_with_valid_version():
    raw_schema = RawSchemaFactory(swagger='2.0')

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('swagger', errors)
Example #11
0
def test_consumes_with_invalid_mimetype():
    raw_schema = RawSchemaFactory(consumes=['invalid-mimetype'])

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['mimetype']['invalid'],
        err.value.detail,
        'consumes',
    )
Example #12
0
def test_invalid_host_value_with_scheme(value):
    raw_schema = RawSchemaFactory(host=value)

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['host']['may_not_include_scheme'],
        err.value.detail,
        'host.scheme',
    )
Example #13
0
def test_schemes_invalid_for_invalid_schemes_value():
    raw_schema = RawSchemaFactory(schemes=['invalid-scheme'])

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['schemes']['invalid'],
        err.value.detail,
        'schemes',
    )
Example #14
0
def test_schemes_invalid_for_non_array_value(value):
    raw_schema = RawSchemaFactory(schemes=value)

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'schemes.type',
    )
Example #15
0
def test_base_path_must_begin_with_slash():
    raw_schema = RawSchemaFactory(basePath='api/v3/')

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['path']['must_start_with_slash'],
        err.value.detail,
        'basePath',
    )
Example #16
0
def test_schemes_is_not_required():
    """
    Test that the info field is required for overall schema validation.
    """
    raw_schema = RawSchemaFactory()
    raw_schema.pop('schemes', None)

    assert 'schemes' not in raw_schema

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'schemes',
        errors,
    )
Example #17
0
def test_paths_dynamically_validates_paths():
    raw_schema = RawSchemaFactory(paths={'does-not-start-with-slash': None})

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['path']['must_start_with_slash'],
        err.value.detail,
        'paths.does-not-start-with-slash',
    )
Example #18
0
def test_paths_with_invalid_types(value):
    raw_schema = RawSchemaFactory(paths=value)

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'paths.type',
    )
Example #19
0
def test_swagger_field_cannot_be_null():
    raw_schema = RawSchemaFactory(swagger=None)

    assert raw_schema['swagger'] is None

    with pytest.raises(ValidationError) as err:
        swagger_schema_validator(raw_schema)

    assert_path_in_errors(
        'swagger',
        err.value.detail,
    )
Example #20
0
def test_produces_with_valid():
    raw_schema = RawSchemaFactory(produces=['application/json'])

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'produces',
        errors,
    )
Example #21
0
def test_base_path_with_valid_path():
    raw_schema = RawSchemaFactory(basePath='/api/v3/')

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'basePath',
        errors,
    )
Example #22
0
def test_valid_host_values(value):
    raw_schema = RawSchemaFactory(host=value)

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'host',
        errors,
    )