コード例 #1
0
def test_prepends_basepath(specs):

    # not - strict
    try:
        handlers = Handlers()
        routes = create_routes_from_namespace(specs, handlers, strict=False)
    except Exception:  # pylint: disable=W0703
        pytest.fail("Non-strict failed", pytrace=True)

    basepath = openapi.get_base_path(specs)
    for route in routes:
        assert route.path.startswith(basepath)
        assert route.handler.__name__[len("get_"):] in route.path
コード例 #2
0
def test_filtered_routing(specs):
    handlers = Handlers()
    found = get_handlers_from_namespace(handlers)

    hdl_sel = {name: hdl for name, hdl in found.items() if "i" in name}
    opr_iter = ((mth, url, opname, _tags)
                for mth, url, opname, _tags in iter_path_operations(specs)
                if "i" in opname)

    routes = map_handlers_with_operations(hdl_sel, opr_iter, strict=True)

    for rdef in routes:
        assert rdef.method == "GET"
        assert rdef.handler in hdl_sel.values()
コード例 #3
0
def client(loop, aiohttp_client, specs):
    app = web.Application()

    # routes
    handlers = Handlers()
    routes = create_routes_from_namespace(specs, handlers, strict=False)
    app.router.add_routes(routes)

    # validators
    app[APP_OPENAPI_SPECS_KEY] = specs

    # middlewares
    base = openapi.get_base_path(specs)
    app.middlewares.append(error_middleware_factory(base))
    app.middlewares.append(envelope_middleware_factory(base))

    return loop.run_until_complete(aiohttp_client(app))
コード例 #4
0
def test_create_routes_from_namespace(specs):
    handlers = Handlers()

    # not - strict
    try:
        routes = create_routes_from_namespace(specs, handlers, strict=False)
    except Exception:  # pylint: disable=W0703
        pytest.fail("Non-strict failed", pytrace=True)

    # strict
    with pytest.raises((RuntimeError, ValueError)):
        routes = create_routes_from_namespace(specs, handlers, strict=True)

    # Removing non-spec handler
    handlers.get_health_wrong = None
    routes = create_routes_from_namespace(specs, handlers, strict=True)

    assert len(routes) == len(specs.paths)
    for rdef in routes:
        assert rdef.method == "GET"