don't push app context for test client json

This commit is contained in:
David Lord 2019-05-17 08:39:16 -07:00
parent f2c854060a
commit a4f0f19796
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
4 changed files with 95 additions and 39 deletions

View file

@ -73,14 +73,10 @@ def make_test_environ_builder(
sep = b'?' if isinstance(url.query, bytes) else '?'
path += sep + url.query
# TODO use EnvironBuilder.json_dumps once we require Werkzeug 0.15
if 'json' in kwargs:
assert 'data' not in kwargs, (
"Client cannot provide both 'json' and 'data'."
)
# push a context so flask.json can use app's json attributes
with app.app_context():
kwargs['data'] = json_dumps(kwargs.pop('json'))
assert 'data' not in kwargs, "Client cannot provide both 'json' and 'data'."
kwargs['data'] = json_dumps(kwargs.pop('json'), app=app)
if 'content_type' not in kwargs:
kwargs['content_type'] = 'application/json'