Skip to content
Myr

Update the testing documentation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Adam Byrtek · committed by Markus Unterwaditzer · parent 23de586 · Browse files · 1 file+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−1 removed

  • other:+21 added−1 removed

1 file+21 added−1 removed

modified:docs/testing.rst+21 added-1 removed
358 unmodified lines
359-----------------360361.. versionadded:: 1.0362363Flask has comprehensive363Flask has a great support for JSON, and is a popular choice for building REST364APIs. Testing both JSON requests and responses using the test client is very365convenient:366367 from flask import json, jsonify368369 @app.route('/api/auth')370 def auth():371 email = request.json['email']372 password = request.json['password']373 return jsonify(token=generate_token(email, password))374375 with app.test_client() as c:376 email = 'john@example.com'377 password = 'secret'378 resp = c.post('/api/auth', json={'email': email, 'password': password})379 assert verify_token(email, resp.json['token'])380381Note that if the ``json`` argument is provided then the test client will put382the JSON-serialized object in the request body, and also set the383``Content-Type: application/json`` header.