diff --git a/flask/testing.py b/flask/testing.py index dd879c37..3b2f26ef 100644 --- a/flask/testing.py +++ b/flask/testing.py @@ -35,16 +35,14 @@ def make_test_environ_builder(app, path='/', base_url=None, json=None, *args, ** if url.query: path += '?' + url.query - if json: + if json is not None: if 'data' in kwargs: raise RuntimeError('Client cannot provide both `json` and `data`') kwargs['data'] = json_dumps(json) # Only set Content-Type when not explicitly provided - if 'Content-Type' not in kwargs.get('headers', {}): - new_headers = kwargs.get('headers', {}).copy() - new_headers['Content-Type'] = 'application/json' - kwargs['headers'] = new_headers + if 'content_type' not in kwargs: + kwargs['content_type'] = 'application/json' return EnvironBuilder(path, base_url, *args, **kwargs) diff --git a/tests/test_testing.py b/tests/test_testing.py index b3f4defe..727f08f7 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -215,6 +215,7 @@ def test_json_request(): json_data = {'drink': {'gin': 1, 'tonic': True}, 'price': 10} rv = c.post('/api', json=json_data) assert rv.status_code == 200 + assert flask.request.is_json assert flask.request.get_json() == json_data def test_subdomain():