MCPcopy Create free account
hub / github.com/pallets/flask / test_json_request_and_response

Function test_json_request_and_response

tests/test_testing.py:263–279  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

261
262
263def test_json_request_and_response(app, client):
264 @app.route("/echo", methods=["POST"])
265 def echo():
266 return jsonify(flask.request.get_json())
267
268 with client:
269 json_data = {"drink": {"gin": 1, "tonic": True}, "price": 10}
270 rv = client.post("/echo", json=json_data)
271
272 # Request should be in JSON
273 assert flask.request.is_json
274 assert flask.request.get_json() == json_data
275
276 # Response should be in JSON
277 assert rv.status_code == 200
278 assert rv.is_json
279 assert rv.get_json() == json_data
280
281
282def test_client_json_no_app_context(app, client):

Callers

nothing calls this directly

Calls 1

postMethod · 0.45

Tested by

no test coverage detected