Closed rth closed 7 years ago
As was suggested on the pocoo IRC channel, replacing,
test_app.post(data={"a": {"name": "Alice"}})
with
test_app.post(data=json.dumps({"a": {"name": "Alice"}}),
content_type='application/json')
fixes this problem (also related SO answers here).
I'm having trouble with this issue too. Possibly because the data I'm passing is to be interpreted as forms which are nested, dumping to json and setting the content_type as such doesn't work, or at least doesn't place the data in my forms as I need it to be when the request is processed.
I also have the same issue as toonarmycaption. The above fix does not work for me.
https://github.com/pallets/werkzeug/issues/1646
Form data is not nestable, it's always sent as a flat list of keys/values. WTForms accomplishes nesting by applying prefixes to the keys so that it can reconstruct the nesting after loading the flat data. You'll need to provide this same flat data. If you're not using WTForms to read the data (the middle portion of your post), you need to access the same flat keys, Werkzeug doesn't parse it into a nested structure.
Currently it does not seem possible to run unit-tests on endpoints that accept a nested dictionary as input when using flask with webargs / marshmallow,
Here is a minimal example,
which runs as expected,
however if I try running tests on it, the argument parsing fails in
werkzeug.test.EnvironBuilder
with the following error,this uses Python 3.5, flask 0.12 and webargs 1.5.2. Any suggestions on how to address this issue (or possible workarounds) would be much appreciated.