From 39e66ca6d782630c67eae4e7e70e60799386ec8b Mon Sep 17 00:00:00 2001 From: Keyan Pishdadian Date: Wed, 4 Mar 2015 14:40:16 -0500 Subject: [PATCH] Add tests for adding exception to response contents only when DEBUG is True --- tests/test_helpers.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 7b5b32f203..015bb08d1f 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -49,6 +49,30 @@ def test_jsonify_date_types(self): assert rv.mimetype == 'application/json' assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple()) + def test_post_empty_json_adds_exception_to_reponse_content_in_debug(self): + app = flask.Flask(__name__) + app.config['DEBUG'] = True + @app.route('/json', methods=['POST']) + def post_json(): + flask.request.get_json() + return None + c = app.test_client() + rv = c.post('/json', data=None, content_type='application/json') + assert rv.status_code == 400 + assert '

No JSON object could be decoded

' in rv.data + + def test_post_empty_json_doesnt_add_exception_to_reponse_if_no_debug(self): + app = flask.Flask(__name__) + app.config['DEBUG'] = False + @app.route('/json', methods=['POST']) + def post_json(): + flask.request.get_json() + return None + c = app.test_client() + rv = c.post('/json', data=None, content_type='application/json') + assert rv.status_code == 400 + assert '

No JSON object could be decoded

' not in rv.data + def test_json_bad_requests(self): app = flask.Flask(__name__) @app.route('/json', methods=['POST'])