Various fixes for the flask adapter
This commit is contained in:
parent
07adf31cd7
commit
bfd1bfb4ff
@ -1,10 +1,11 @@
|
||||
import unittest
|
||||
from flask import Flask
|
||||
from flask import Flask, json
|
||||
from wsmeext.flask import signature
|
||||
from wsme.types import Base, text
|
||||
|
||||
|
||||
class Model(Base):
|
||||
id = int
|
||||
name = text
|
||||
|
||||
|
||||
@ -26,11 +27,11 @@ def divide_by_zero():
|
||||
@test_app.route('/models')
|
||||
@signature([Model])
|
||||
def list_models():
|
||||
return [Model(name=1)]
|
||||
return [Model(name='first')]
|
||||
|
||||
|
||||
@test_app.route('/models/<name>')
|
||||
@signature(Model)
|
||||
@signature(Model, text)
|
||||
def get_model(name):
|
||||
return Model(name=name)
|
||||
|
||||
@ -63,9 +64,13 @@ class FlaskrTestCase(unittest.TestCase):
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_post_model(self):
|
||||
resp = self.app.post('/models', data={"name": "test"})
|
||||
import ipdb
|
||||
ipdb.set_trace()
|
||||
resp = self.app.post('/models', data={"body.name": "test"})
|
||||
assert resp.status_code == 200
|
||||
resp = self.app.post(
|
||||
'/models',
|
||||
data=json.dumps({"name": "test"}),
|
||||
content_type="application/json"
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_serversideerror(self):
|
||||
|
@ -158,7 +158,7 @@ def args_from_args(funcdef, args, kwargs):
|
||||
newargs.append(from_param(argdef.datatype, arg))
|
||||
newkwargs = {}
|
||||
for argname, value in kwargs.items():
|
||||
newkwargs[argname] = from_param(funcdef.get_arg(argname), value)
|
||||
newkwargs[argname] = from_param(funcdef.get_arg(argname).datatype, value)
|
||||
return newargs, newkwargs
|
||||
|
||||
|
||||
@ -229,7 +229,7 @@ def combine_args(funcdef, akw, allow_override=False):
|
||||
return newargs, newkwargs
|
||||
|
||||
|
||||
def get_args(funcdef, args, kwargs, params, body, mimetype):
|
||||
def get_args(funcdef, args, kwargs, params, form, body, mimetype):
|
||||
"""Combine arguments from :
|
||||
* the host framework args and kwargs
|
||||
* the request params
|
||||
@ -248,13 +248,19 @@ def get_args(funcdef, args, kwargs, params, body, mimetype):
|
||||
# extract args from the request parameters
|
||||
from_params = args_from_params(funcdef, params)
|
||||
|
||||
# extract args from the form parameters
|
||||
if form:
|
||||
from_form_params = args_from_params(funcdef, form)
|
||||
else:
|
||||
from_form_params = (), {}
|
||||
|
||||
# extract args from the request body
|
||||
from_body = args_from_body(funcdef, body, mimetype)
|
||||
|
||||
# combine params and body arguments
|
||||
from_params_and_body = combine_args(
|
||||
funcdef,
|
||||
(from_params, from_body)
|
||||
(from_params, from_form_params, from_body)
|
||||
)
|
||||
|
||||
return combine_args(
|
||||
|
@ -21,12 +21,15 @@ def signature(*args, **kw):
|
||||
def decorator(f):
|
||||
sig(f)
|
||||
funcdef = wsme.api.FunctionDefinition.get(f)
|
||||
funcdef.resolve_types(wsme.types.registry)
|
||||
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
args, kwargs = wsme.rest.args.get_args(
|
||||
funcdef, args, kwargs, flask.request.args, flask.request.data,
|
||||
flask.request.content_type
|
||||
funcdef, args, kwargs,
|
||||
flask.request.args, flask.request.form,
|
||||
flask.request.data,
|
||||
flask.request.mimetype
|
||||
)
|
||||
|
||||
dataformat = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user