Skip to content

Commit

Permalink
Add tests for adding exception to response contents only when DEBUG i…
Browse files Browse the repository at this point in the history
…s True
  • Loading branch information
keyan committed Mar 4, 2015
1 parent 19df249 commit 39e66ca
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_helpers.py
Expand Up @@ -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 '<p>No JSON object could be decoded</p>' 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 '<p>No JSON object could be decoded</p>' not in rv.data

def test_json_bad_requests(self):
app = flask.Flask(__name__)
@app.route('/json', methods=['POST'])
Expand Down

0 comments on commit 39e66ca

Please sign in to comment.