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"
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
def client(event_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 event_loop.run_until_complete(aiohttp_client(app))