Skip to content
Myr

Improved test coverage for the test client

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

authored by Armin Ronacher · committed by Armin Ronacher · parent b8866ae · Browse files · 1 file+18 added−9 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+18 added−9 removed

  • other:+18 added−9 removed

1 file+18 added−9 removed

modified:flask/testsuite/testing.py+18 added-9 removed
51 unmodified lines
5253 @app.route('/', methods=['GET', 'POST'])54 def index():55 if flask.request.method == 'POST':56 return flask.redirect('/redirect')56 return flask.redirect('/getsession')57 flask.session['data'] = 'foo'58 return 'index'5960 @app.route('/redirect')61 def redirect():62 return 'redirect'60 @app.route('/getsession')61 def get_session():62 return flask.session.get('data', '<missing>')6364 with app.test_client() as c:65 ctx = app.test_request_context()66 ctx.push()65 rv = c.get('/getsession')66 assert rv.data == '<missing>'6768 rv = c.get('/')69 assert rv.data == 'index'70 assert flask.session.get('data') == 'foo'71 rv = c.post('/', data={}, follow_redirects=True)71 assert rv.data == 'redirect'72 assert flask.session.get('data') == 'foo'73 ctx.pop()72 assert rv.data == 'foo'7374 # XXX: Currently the test client does not support75 # keeping the context around if a redirect is followed.76 # This would be nice to fix but right now the Werkzeug77 # test client does not support that.78 ##assert flask.session.get('data') == 'foo'7980 rv = c.get('/getsession')81 assert rv.data == 'foo'8283 def test_session_transactions(self):84 app = flask.Flask(__name__)85 app.testing = True86 app.secret_key = 'testing'
33 unmodified lines
120121 with app.test_client() as c:122 rv = c.get('/')123 req = flask.request._get_current_object()124 self.assert_(req is not None)125 with c.session_transaction():126 self.assert_(req is flask.request._get_current_object())127128 def test_session_transaction_needs_cookies(self):
78 unmodified lines