Skip to content
Myr

Require that cookies are enabled in the test client for session transactions

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 5235c3e · Browse files · 2 files+18 added−5 removed
This commit

State

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

Diff stats

2 files+18 added−5 removed

  • other:+18 added−5 removed

2 files+18 added−5 removed

modified:flask/testsuite/testing.py+12 added
82 unmodified lines
83 req = flask.request._get_current_object()84 with c.session_transaction():85 self.assert_(req is flask.request._get_current_object())8687 def test_session_transaction_needs_cookies(self):88 app = flask.Flask(__name__)89 app.testing = True90 c = app.test_client(use_cookies=False)91 try:92 with c.session_transaction() as s:93 pass94 except RuntimeError, e:95 self.assert_('cookies' in str(e))96 else:97 self.fail('Expected runtime error')9899 def test_test_client_context_binding(self):100 app = flask.Flask(__name__)101 @app.route('/')102 def index():
31 unmodified lines
modified:flask/testing.py+6 added-5 removed
51 unmodified lines
52 request variables this function accepts the same arguments as53 :meth:`~flask.Flask.test_request_context` which are directly54 passed through.55 """56 if self.cookie_jar is None:57 raise RuntimeError('Session transactions only make sense '58 'with cookies enabled.')59 app = self.application60 environ_overrides = kwargs.pop('environ_overrides', {})58 if self.cookie_jar is not None:59 self.cookie_jar.inject_wsgi(environ_overrides)61 self.cookie_jar.inject_wsgi(environ_overrides)62 outer_reqctx = _request_ctx_stack.top63 with app.test_request_context(*args, **kwargs) as c:64 sess = app.open_session(c.request)65 if sess is None:
15 unmodified lines
8182 resp = app.response_class()83 if not app.session_interface.is_null_session(sess):84 app.save_session(sess, resp)83 if self.cookie_jar is not None:84 headers = resp.get_wsgi_headers(c.request.environ)85 self.cookie_jar.extract_wsgi(c.request.environ, headers)85 headers = resp.get_wsgi_headers(c.request.environ)86 self.cookie_jar.extract_wsgi(c.request.environ, headers)8788 def open(self, *args, **kwargs):89 if self.context_preserved:90 _request_ctx_stack.pop()
28 unmodified lines