Ejemplo n.º 1
0
def test_proper_error_on_missing_api_declaration():
    with pytest.raises(ValidationError) as exc:
        dir_path = 'tests/sample_schemas/missing_api_declaration/'
        with open(os.path.join(dir_path, API_DOCS_FILENAME)) as f:
            resource_listing = simplejson.load(f)
            validate_swagger_schema(dir_path, resource_listing)

    assert "{0}{1}".format(dir_path, "missing.json") in str(exc)
Ejemplo n.º 2
0
def test_proper_error_on_missing_api_declaration():
    with pytest.raises(ValidationError) as exc:
        dir_path = 'tests/sample_schemas/missing_api_declaration/'.replace('/', os.path.sep)
        with open(os.path.join(dir_path, API_DOCS_FILENAME)) as f:
            resource_listing = simplejson.load(f)
            validate_swagger_schema(dir_path, resource_listing)

    assert os.path.basename(dir_path) in str(exc)
    assert os.path.basename('missing.json') in str(exc)
Ejemplo n.º 3
0
def test_proper_error_on_missing_api_declaration():
    with pytest.raises(ValidationError) as exc:
        dir_path = 'tests/sample_schemas/missing_api_declaration/'.replace(
            '/', os.path.sep)
        with open(os.path.join(dir_path, API_DOCS_FILENAME)) as f:
            resource_listing = simplejson.load(f)
            validate_swagger_schema(dir_path, resource_listing)

    assert os.path.basename(dir_path) in str(exc)
    assert os.path.basename('missing.json') in str(exc)
Ejemplo n.º 4
0
def get_swagger_schema(settings):
    """Return a :class:`pyramid_swagger.model.SwaggerSchema` constructed from
    the swagger specs in `pyramid_swagger.schema_directory`. If
    `pyramid_swagger.enable_swagger_spec_validation` is enabled the schema
    will be validated before returning it.

    :param settings: a pyramid registry settings with configuration for
        building a swagger schema
    :type settings: dict
    :returns: a :class:`pyramid_swagger.model.SwaggerSchema`
    """
    schema_dir = settings.get('pyramid_swagger.schema_directory', 'api_docs')
    resource_listing = get_resource_listing(
        schema_dir,
        settings.get('pyramid_swagger.generate_resource_listing', False))

    if settings.get('pyramid_swagger.enable_swagger_spec_validation', True):
        validate_swagger_schema(schema_dir, resource_listing)

    return compile_swagger_schema(schema_dir, resource_listing)
Ejemplo n.º 5
0
def get_swagger_schema(settings):
    """Return a :class:`pyramid_swagger.model.SwaggerSchema` constructed from
    the swagger specs in `pyramid_swagger.schema_directory`. If
    `pyramid_swagger.enable_swagger_spec_validation` is enabled the schema
    will be validated before returning it.

    :param settings: a pyramid registry settings with configuration for
        building a swagger schema
    :type settings: dict
    :returns: a :class:`pyramid_swagger.model.SwaggerSchema`
    """
    schema_dir = settings.get('pyramid_swagger.schema_directory', 'api_docs')
    resource_listing = get_resource_listing(
        schema_dir,
        settings.get('pyramid_swagger.generate_resource_listing', False)
    )

    if settings.get('pyramid_swagger.enable_swagger_spec_validation', True):
        validate_swagger_schema(schema_dir, resource_listing)

    return compile_swagger_schema(schema_dir, resource_listing)
Ejemplo n.º 6
0
def test_success_for_good_app():
    dir_path = 'tests/sample_schemas/good_app/'
    with open(os.path.join(dir_path, API_DOCS_FILENAME)) as f:
        resource_listing = simplejson.load(f)
        validate_swagger_schema(dir_path, resource_listing)