Added separate module for testing
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 c34b03e · Browse files · 4 files·+44 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+44 added−23 removed
- other:+44 added−23 removed
Provenance
- Commit
df3f894- Tree
41c28db- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
c34b03e
4 files changed+44 added−23 removed
modified:flask/app.py+3 added-22 removed
16 unmodified lines17 from itertools import chain18 19 from jinja2 import Environment20 21-from werkzeug import ImmutableDict, create_environ21+from werkzeug import ImmutableDict22 from werkzeug.routing import Map, Rule23 from werkzeug.exceptions import HTTPException, InternalServerError, NotFound24 25 from .helpers import _PackageBoundObject, url_for, get_flashed_messages, \382 unmodified lines408 409 .. versionchanged:: 0.4410 added support for `with` block usage for the client.411 """412- from werkzeug import Client413- class FlaskClient(Client):414- preserve_context = context_preserved = False415- def open(self, *args, **kwargs):416- if self.context_preserved:417- _request_ctx_stack.pop()418- self.context_preserved = False419- kwargs.setdefault('environ_overrides', {}) \420- ['flask._preserve_context'] = self.preserve_context421- old = _request_ctx_stack.top422- try:423- return Client.open(self, *args, **kwargs)424- finally:425- self.context_preserved = _request_ctx_stack.top is not old426- def __enter__(self):427- self.preserve_context = True428- return self429- def __exit__(self, exc_type, exc_value, tb):430- self.preserve_context = False431- if self.context_preserved:432- _request_ctx_stack.pop()412+ from flask.testing import FlaskClient413 return FlaskClient(self, self.response_class, use_cookies=True)414 415 def open_session(self, request):416 """Creates or opens a new session. Default implementation stores all400 unmodified lines817 """Creates a WSGI environment from the given values (see818 :func:`werkzeug.create_environ` for more information, this819 function accepts the same arguments).820 """821+ from werkzeug import create_environ822 return self.request_context(create_environ(*args, **kwargs))823 824 def __call__(self, environ, start_response):825 """Shortcut for :attr:`wsgi_app`."""1 unmodified linemodified:flask/ctx.py+1 added
58 unmodified lines59 # do not pop the request stack if we are in debug mode and an60 # exception happened. This will allow the debugger to still61 # access the request object in the interactive shell. Furthermore62 # the context can be force kept alive for the test client.63+ # See flask.testing for how this works.64 if not self.request.environ.get('flask._preserve_context') and \65 (tb is None or not self.app.debug):66 self.pop()modified:flask/module.py+1 added-1 removed
28 unmodified lines29 path = state.app.static_path30 if state.url_prefix:31 path = state.url_prefix + path32 state.app.add_url_rule(path + '/<path:filename>',33- '%s.static' % module.name,33+ endpoint='%s.static' % module.name,34 view_func=module.send_static_file)35 return _register36 37 165 unmodified linesadded:flask/testing.py+39 added
1+# -*- coding: utf-8 -*-2+"""3+ flask.testing4+ ~~~~~~~~~~~~~5+6+ Implements test support helpers. This module is lazily imported7+ and usually not used in production environments.8+9+ :copyright: (c) 2010 by Armin Ronacher.10+ :license: BSD, see LICENSE for more details.11+"""12+from werkzeug import Client13+from flask import _request_ctx_stack14+15+16+class FlaskClient(Client):17+18+ preserve_context = context_preserved = False19+20+ def open(self, *args, **kwargs):21+ if self.context_preserved:22+ _request_ctx_stack.pop()23+ self.context_preserved = False24+ kwargs.setdefault('environ_overrides', {}) \25+ ['flask._preserve_context'] = self.preserve_context26+ old = _request_ctx_stack.top27+ try:28+ return Client.open(self, *args, **kwargs)29+ finally:30+ self.context_preserved = _request_ctx_stack.top is not old31+32+ def __enter__(self):33+ self.preserve_context = True34+ return self35+36+ def __exit__(self, exc_type, exc_value, tb):37+ self.preserve_context = False38+ if self.context_preserved:39+ _request_ctx_stack.pop()