def echo_nested(request): argmap = { 'name': fields.Nested({ 'first': fields.Str(), 'last': fields.Str() }) } return parser.parse(argmap, request)
def echo_json_ignore_extra_data(request): try: return parser.parse(hello_exclude_schema, request) except json.JSONDecodeError: error = HTTPBadRequest() error.body = json.dumps(["Invalid JSON."]).encode("utf-8") error.content_type = "application/json" raise error
def echo_nested(request): argmap = { "name": fields.Nested({ "first": fields.Str(), "last": fields.Str() }) } return parser.parse(argmap, request)
def echo_json_or_form(request): try: return parser.parse(hello_args, request, location="json_or_form") except json.JSONDecodeError: error = HTTPBadRequest() error.body = json.dumps(["Invalid JSON."]).encode("utf-8") error.content_type = "application/json" raise error
def echo_nested_many(request): argmap = { 'users': fields.Nested({ 'id': fields.Int(), 'name': fields.Str() }, many=True) } return parser.parse(argmap, request)
def echo_nested_many(request): argmap = { "users": fields.Nested({ "id": fields.Int(), "name": fields.Str() }, many=True) } return parser.parse(argmap, request)
def echo_multi(request): return parser.parse(hello_multiple, request)
def echo_query(request): return parser.parse(hello_args, request, locations=("query", ))
def echo(request): return parser.parse(hello_args, request)
def echo_matchdict(request): return parser.parse({"mymatch": fields.Int()}, request, locations=("matchdict", ))
def echo_multi_form(request): return parser.parse(hello_multiple, request, location="form")
def echo_headers(request): return parser.parse(hello_args, request, locations=("headers", ))
def echo_file(request): args = {'myfile': fields.Field()} result = parser.parse(args, request, locations=('files', )) myfile = result['myfile'] content = myfile.file.read().decode('utf8') return {'myfile': content}
def echo_form(request): return parser.parse(hello_args, request, location="form")
def echo_many_schema(request): return parser.parse(hello_many_schema, request, locations=("json", ))
def echo(request): return parser.parse(hello_args, request, location="query")
def echo_headers(request): return parser.parse(hello_exclude_schema, request, location="headers")
def always_error(request): def always_fail(value): raise ma.ValidationError("something went wrong") argmap = {"text": fields.Str(validate=always_fail)} return parser.parse(argmap, request)
def echo_many_schema(request): return parser.parse(hello_many_schema, request)
def echo_matchdict(request): return parser.parse({'mymatch': fields.Int()}, request, locations=('matchdict', ))
def error400(request): def always_fail(value): raise ValidationError("something went wrong", status_code=400) argmap = {"text": fields.Str(validate=always_fail)} return parser.parse(argmap, request)
def echo_file(request): args = {"myfile": fields.Field()} result = parser.parse(args, request, locations=("files", )) myfile = result["myfile"] content = myfile.file.read().decode("utf8") return {"myfile": content}
def echo_cookie(request): return parser.parse(hello_args, request, locations=("cookies", ))
def always_error(request): def always_fail(value): raise ValidationError('something went wrong') argmap = {'text': fields.Str(validate=always_fail)} return parser.parse(argmap, request)
def echo_multi(request): return parser.parse(hello_multiple, request, location="query")
def test_parse_via_webargs_api(self, lti_user, schema, pyramid_request): deserialized = parser.parse(schema, pyramid_request, locations=["headers"]) assert deserialized == lti_user