Esempio n. 1
0
File: utils.py Progetto: brylie/lepo
def get_urlpatterns(handler_module,
                    definition_file='swagger2/petstore-expanded.yaml'):
    # NB: This could just as well be your `urls.py` – it's here to make testing various handler
    #     configurations easier.

    router = Router.from_file(
        os.path.join(os.path.dirname(__file__), 'tests', definition_file))
    router.add_handlers(handler_module)
    validate_router(router)
    router_urls = router.get_urls(
        decorate=(csrf_exempt, ),
        optional_trailing_slash=True,
    )

    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^api/', include((router_urls, 'api'), 'api')),
        url(
            r'^api/',
            include((get_docs_urls(router, 'api-docs'), 'api-docs'),
                    'api-docs')),
    ]
    return urlpatterns
Esempio n. 2
0
def test_validator(doc_version):
    router = get_router('{}/schema-refs.yaml'.format(doc_version))
    with pytest.raises(RouterValidationError) as ei:
        validate_router(router)
    assert len(ei.value.errors) == 2
Esempio n. 3
0
def test_header_underscore(doc_version):
    router = get_router('{}/header-underscore.yaml'.format(doc_version))
    with pytest.raises(RouterValidationError) as ei:
        validate_router(router)
    errors = list(ei.value.flat_errors)
    assert any(isinstance(e[1], InvalidParameterDefinition) for e in errors)
Esempio n. 4
0
File: urls.py Progetto: kcsry/conpo
from lepo.router import Router
from lepo.validate import validate_router
from pkg_resources import resource_filename

from . import handlers

router = Router.from_file(resource_filename('conpo.api', 'swagger.yaml'))
router.add_handlers(handlers)
validate_router(router)
urlpatterns = router.get_urls()
Esempio n. 5
0
File: urls.py Progetto: japsu/lepo
import os

from django.conf.urls import include, url
from django.contrib import admin

from lepo.router import Router
from lepo.validate import validate_router
from lepo_doc.urls import get_docs_urls

router = Router.from_file(os.path.join(os.path.dirname(__file__), '..', 'tests', 'petstore-expanded.yaml'))
router.add_handlers('lepo_tests.handlers.pets')

for error in validate_router(router):
    print('Validation error:', error)

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^api/', include(router.get_urls(), 'api')),
    url(r'^api/', include(get_docs_urls(router, 'api-docs'), 'api-docs')),
]