If JSON parsing fails it now issues a BadRequest exception.

This commit is contained in:
Armin Ronacher 2011-08-08 21:47:26 +02:00
parent acac64e36a
commit ce70131975
4 changed files with 36 additions and 4 deletions

View file

@ -984,6 +984,15 @@ class BasicFunctionalityTestCase(unittest.TestCase):
class JSONTestCase(unittest.TestCase):
def test_json_bad_requests(self):
app = flask.Flask(__name__)
@app.route('/json', methods=['POST'])
def return_json():
return unicode(flask.request.json)
c = app.test_client()
rv = c.post('/json', data='malformed', content_type='application/json')
self.assertEqual(rv.status_code, 400)
def test_json_body_encoding(self):
app = flask.Flask(__name__)
app.testing = True