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)) @pytest.mark.parametrize("path,expected_data", [("/health", Handlers.get('health')), ("/dict", Handlers.get('dict')), ("/envelope", Handlers.get('envelope')['data']), ("/list", Handlers.get('list')), ("/attobj", Handlers.get('attobj')), ("/string", Handlers.get('string')), ("/number", Handlers.get('number')), ("/mixed", Handlers.get('mixed'))]) async def test_envelope_middleware(path, expected_data, client, specs): base = openapi.get_base_path(specs) response = await client.get(base + path) payload = await response.json() assert is_enveloped(payload) data, error = unwrap_envelope(payload)
# 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)) @pytest.mark.parametrize( "path,expected_data", [ ("/health", Handlers.get("health")), ("/dict", Handlers.get("dict")), ("/envelope", Handlers.get("envelope")["data"]), ("/list", Handlers.get("list")), ("/attobj", Handlers.get("attobj")), ("/string", Handlers.get("string")), ("/number", Handlers.get("number")), ("/mixed", Handlers.get("mixed")), ], ) async def test_envelope_middleware(path, expected_data, client, specs): base = openapi.get_base_path(specs) response = await client.get(base + path) payload = await response.json() assert is_enveloped(payload)