async def echo_lol(request): #just FORFUN test parsed1 = parser.parse(hello_args, request, location="headers") parsed2 = parser.parse(hello_args, request, location="headers") parsed3 = parser.parse(hello_args, request, location="headers") (res1, res2, res3) = await asyncio.gather(parsed1, parsed2, parsed3) return J(res2)
async def echo_nested_many_with_data_key(request): args = { "x_field": fields.Nested({"id": fields.Int()}, many=True, data_key="X-Field") } parsed = await parser.parse(args, request) return J(parsed)
async def error(request): def always_fail(value): raise ValidationError("something went wrong") args = {"text": fields.Str(validate=always_fail)} parsed = await parser.parse(args, request) return J(parsed)
async def echo_nested(request): args = { "name": fields.Nested({ "first": fields.Str(), "last": fields.Str() }) } parsed = await parser.parse(args, request) return J(parsed)
async def echo_nested_many(request): args = { "users": fields.Nested({ "id": fields.Int(), "name": fields.Str() }, many=True) } parsed = await parser.parse(args, request) return J(parsed)
async def echo_nested_many_with_data_key(request): data_key_kwarg = { "load_from" if (MARSHMALLOW_VERSION_INFO[0] < 3) else "data_key": "X-Field" } args = { "x_field": fields.Nested({"id": fields.Int()}, many=True, **data_key_kwarg) } parsed = await parser.parse(args, request) return J(parsed)
async def post(self, request, val): return J({"val": val})
async def handle_validation_error(request, err): assert isinstance(err.data["schema"], ma.Schema) return J({"errors": err.exc.messages}, status=422)
async def post(self, request, args): return J(args)
async def echo_use_kwargs(request, name): return J({"name": name})
async def echo(request): parsed = await parser.parse(hello_args, request) return J(parsed)
async def echo_use_kwargs_missing(request, username, password): assert password is missing return J({"username": username})
async def echo_view_arg_with_use_args(request, args, **kwargs): return J(args)
async def echo_json_or_form(request): parsed = await parser.parse(hello_args, request, location="json_or_form") return J(parsed)
async def echo_use_args_validated(request, args): return J(args)
async def echo_use_kwargs_missing(request, username, **kwargs): assert "password" not in kwargs return J({"username": username})
async def multi(request): parsed = await parser.parse(hello_multiple, request, location="query") return J(parsed)
async def echo_use_kwargs_with_path(request, name, value): return J({"value": value})
async def echo_use_args_with_path(request, args, name): return J(args)
async def many_nested(request): parsed = await parser.parse(hello_many_schema, request, location="json") return J(parsed, content_type="application/json")
async def multi_json(request): parsed = await parser.parse(hello_multiple, request) return J(parsed)
async def multi_form(request): parsed = await parser.parse(hello_multiple, request, location="form") return J(parsed)
async def handle_validation_error(request, err): app.config.update({'FALLBACK_ERROR_FORMAT': 'json'}) if err.status_code == 422: assert isinstance(err.data["schema"], ma.Schema) return J(err.exc.message, status=err.status_code)
async def echo_headers(request): parsed1 = parser.parse(hello_args, request, location="headers") res1 = await parsed1 return J(res1)
async def echo_query(request): parsed = await parser.parse(hello_args, request, location="query") return J(parsed)
async def echo_cookie(request): parsed = await parser.parse(hello_args, request, location="cookies") return J(parsed)
async def echo_use_args(request, args): return J(args)
async def echo_file(request): args = {"myfile": fields.Field()} result = await parser.parse(args, request, location="files") fp = result["myfile"] content = fp.body.decode("utf8") return J({"myfile": content})
async def echo_json_ignore_extra_data(request): parsed = await parser.parse(hello_args, request, unknown=ma.EXCLUDE) return J(parsed)
async def echo_view_arg(request, view_arg): parsed = await parser.parse({"view_arg": fields.Int()}, request, location="view_args") return J(parsed)