Skip to content
Myr

Merge pull request #4165 from yuxiaoy1/patch-1

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

Change flask.xxx to plain version in testing docs

authored by David Lord · committed by GitHub · parents d426b58, 35eb582 · Browse files · 1 file+8 added−8 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+8 added−8 removed

  • other:+8 added−8 removed

1 file+8 added−8 removed

modified:docs/testing.rst+8 added-8 removed
223 unmodified lines
224temporarily. With this you can access the :class:`~flask.request`,225:class:`~flask.g` and :class:`~flask.session` objects like in view226functions. Here is a full example that demonstrates this approach::227228 import flask228 from flask import Flask, request229230 app = flask.Flask(__name__)230 app = Flask(__name__)231232 with app.test_request_context('/?name=Peter'):233 assert flask.request.path == '/'234 assert flask.request.args['name'] == 'Peter'233 assert request.path == '/'234 assert request.args['name'] == 'Peter'235236All the other objects that are context bound can be used in the same237way.238
8 unmodified lines
247the test request context leaves the ``with`` block. If you do want the248:meth:`~flask.Flask.before_request` functions to be called as well, you249need to call :meth:`~flask.Flask.preprocess_request` yourself::250251 app = flask.Flask(__name__)251 app = Flask(__name__)252253 with app.test_request_context('/?name=Peter'):254 app.preprocess_request()255 ...
4 unmodified lines
260If you want to call the :meth:`~flask.Flask.after_request` functions you261need to call into :meth:`~flask.Flask.process_response` which however262requires that you pass it a response object::263264 app = flask.Flask(__name__)264 app = Flask(__name__)265266 with app.test_request_context('/?name=Peter'):267 resp = Response('...')268 resp = app.process_response(resp)
60 unmodified lines
329context around for a little longer so that additional introspection can330happen. With Flask 0.4 this is possible by using the331:meth:`~flask.Flask.test_client` with a ``with`` block::332333 app = flask.Flask(__name__)333 app = Flask(__name__)334335 with app.test_client() as c:336 rv = c.get('/?tequila=42')337 assert request.args['tequila'] == '42'
15 unmodified lines
353keep the context around and access :data:`flask.session`::354355 with app.test_client() as c:356 rv = c.get('/')357 assert flask.session['foo'] == 42357 assert session['foo'] == 42358359This however does not make it possible to also modify the session or to360access the session before a request was fired. Starting with Flask 0.8 we361provide a so called “session transaction” which simulates the appropriate
102 unmodified lines