forked from orbit-oss/flask
add json provider interface
This commit is contained in:
parent
c356c6da5f
commit
69f9845ef2
13 changed files with 662 additions and 282 deletions
|
|
@ -1302,28 +1302,17 @@ def test_make_response_with_response_instance(app, req_ctx):
|
|||
assert rv.headers["X-Foo"] == "bar"
|
||||
|
||||
|
||||
def test_jsonify_no_prettyprint(app, req_ctx):
|
||||
app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})
|
||||
compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n'
|
||||
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, req_ctx):
|
||||
app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})
|
||||
compressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}
|
||||
pretty_response = (
|
||||
b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}\n'
|
||||
)
|
||||
|
||||
rv = flask.make_response(flask.jsonify(compressed_msg), 200)
|
||||
assert rv.data == pretty_response
|
||||
@pytest.mark.parametrize("compact", [True, False])
|
||||
def test_jsonify_no_prettyprint(app, compact):
|
||||
app.json.compact = compact
|
||||
rv = app.json.response({"msg": {"submsg": "W00t"}, "msg2": "foobar"})
|
||||
data = rv.data.strip()
|
||||
assert (b" " not in data) is compact
|
||||
assert (b"\n" not in data) is compact
|
||||
|
||||
|
||||
def test_jsonify_mimetype(app, req_ctx):
|
||||
app.config.update({"JSONIFY_MIMETYPE": "application/vnd.api+json"})
|
||||
app.json.mimetype = "application/vnd.api+json"
|
||||
msg = {"msg": {"submsg": "W00t"}}
|
||||
rv = flask.make_response(flask.jsonify(msg), 200)
|
||||
assert rv.mimetype == "application/vnd.api+json"
|
||||
|
|
@ -1333,15 +1322,15 @@ def test_json_dump_dataclass(app, req_ctx):
|
|||
from dataclasses import make_dataclass
|
||||
|
||||
Data = make_dataclass("Data", [("name", str)])
|
||||
value = flask.json.dumps(Data("Flask"), app=app)
|
||||
value = flask.json.loads(value, app=app)
|
||||
value = app.json.dumps(Data("Flask"))
|
||||
value = app.json.loads(value)
|
||||
assert value == {"name": "Flask"}
|
||||
|
||||
|
||||
def test_jsonify_args_and_kwargs_check(app, req_ctx):
|
||||
with pytest.raises(TypeError) as e:
|
||||
flask.jsonify("fake args", kwargs="fake")
|
||||
assert "behavior undefined" in str(e.value)
|
||||
assert "args or kwargs" in str(e.value)
|
||||
|
||||
|
||||
def test_url_generation(app, req_ctx):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue