get_json separate cache depending on silent arg

This commit is contained in:
fphonor 2018-03-19 23:41:54 +08:00 committed by David Lord
parent 8c0d8c1c14
commit 171eb28c95
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 30 additions and 6 deletions

View file

@ -62,6 +62,21 @@ class TestJSON(object):
with pytest.raises(BadRequest):
flask.request.get_json(silent=False, cache=False)
def test_different_silent_on_bad_request(self, app):
with app.test_request_context(
'/', method='POST', data='malformed',
content_type='application/json'):
assert flask.request.get_json(silent=True) is None
with pytest.raises(BadRequest):
flask.request.get_json(silent=False)
def test_different_silent_on_normal_request(self, app):
with app.test_request_context('/', method='POST', json={'foo': 'bar'}):
silent_rv = flask.request.get_json(silent=True)
normal_rv = flask.request.get_json(silent=False)
assert silent_rv is normal_rv
assert normal_rv['foo'] == 'bar'
def test_post_empty_json_adds_exception_to_response_content_in_debug(self, app, client):
app.config['DEBUG'] = True
app.config['TRAP_BAD_REQUEST_ERRORS'] = False