Skip to content
Myr

Merge pull request #3154 from brunoais/more-explicit-session-transaction

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

More explicit explanation: session testing

authored by David Lord · committed by GitHub · parents 55801b5, 6142aa6 · Browse files · 1 file+4 added−3 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+4 added−3 removed

  • other:+4 added−3 removed

1 file+4 added−3 removed

modified:docs/testing.rst+4 added-3 removed
352 unmodified lines
353This however does not make it possible to also modify the session or to354access the session before a request was fired. Starting with Flask 0.8 we355provide a so called “session transaction” which simulates the appropriate356calls to open a session in the context of the test client and to modify357it. At the end of the transaction the session is stored. This works358independently of the session backend used::357it. At the end of the transaction the session is stored and ready to be358used by the test client. This works independently of the session backend used::359360 with app.test_client() as c:361 with c.session_transaction() as sess:362 sess['a_key'] = 'a value'363364 # once this is reached the session was stored364 # once this is reached the session was stored and ready to be used by the client365 c.get(...)366367Note that in this case you have to use the ``sess`` object instead of the368:data:`flask.session` proxy. The object however itself will provide the369same interface.
88 unmodified lines