forked from orbit-oss/flask
Improve compression by removing whitespace from separators when using jsonify() and JSONIFY_PRETTYPRINT_REGULAR is False.
Commit includes Changelog entry and two new tests in test_basic.py.
This commit is contained in:
parent
050a659c2f
commit
d425279650
3 changed files with 39 additions and 1 deletions
|
|
@ -959,6 +959,34 @@ def test_make_response_with_response_instance():
|
|||
assert rv.headers['X-Foo'] == 'bar'
|
||||
|
||||
|
||||
def test_jsonify_no_prettyprint():
|
||||
app = flask.Flask(__name__)
|
||||
app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})
|
||||
with app.test_request_context():
|
||||
compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}'
|
||||
uncompressed_msg = {
|
||||
"msg": {
|
||||
"submsg": "W00t"
|
||||
},
|
||||
"msg2": "foobar"
|
||||
}
|
||||
|
||||
rv = flask.make_response(
|
||||
flask.jsonify(uncompressed_msg), 200)
|
||||
assert rv.data == compressed_msg
|
||||
|
||||
def test_jsonify_prettyprint():
|
||||
app = flask.Flask(__name__)
|
||||
app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})
|
||||
with app.test_request_context():
|
||||
compressed_msg = {"msg":{"submsg":"W00t"},"msg2":"foobar"}
|
||||
pretty_response =\
|
||||
b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}'
|
||||
|
||||
rv = flask.make_response(
|
||||
flask.jsonify(compressed_msg), 200)
|
||||
assert rv.data == pretty_response
|
||||
|
||||
def test_url_generation():
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue