Merge pull request #3154 from brunoais/more-explicit-session-transaction
More explicit explanation: session testing
This commit is contained in:
commit
ab3f922533
1 changed files with 4 additions and 3 deletions
|
|
@ -354,14 +354,15 @@ This however does not make it possible to also modify the session or to
|
||||||
access the session before a request was fired. Starting with Flask 0.8 we
|
access the session before a request was fired. Starting with Flask 0.8 we
|
||||||
provide a so called “session transaction” which simulates the appropriate
|
provide a so called “session transaction” which simulates the appropriate
|
||||||
calls to open a session in the context of the test client and to modify
|
calls to open a session in the context of the test client and to modify
|
||||||
it. At the end of the transaction the session is stored. This works
|
it. At the end of the transaction the session is stored and ready to be
|
||||||
independently of the session backend used::
|
used by the test client. This works independently of the session backend used::
|
||||||
|
|
||||||
with app.test_client() as c:
|
with app.test_client() as c:
|
||||||
with c.session_transaction() as sess:
|
with c.session_transaction() as sess:
|
||||||
sess['a_key'] = 'a value'
|
sess['a_key'] = 'a value'
|
||||||
|
|
||||||
# once this is reached the session was stored
|
# once this is reached the session was stored and ready to be used by the client
|
||||||
|
c.get(...)
|
||||||
|
|
||||||
Note that in this case you have to use the ``sess`` object instead of the
|
Note that in this case you have to use the ``sess`` object instead of the
|
||||||
:data:`flask.session` proxy. The object however itself will provide the
|
:data:`flask.session` proxy. The object however itself will provide the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue