Skip to content
Myr

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

4 files+44 added−23 removed

modified:flask/app.py+3 added-22 removed
16 unmodified lines
17from itertools import chain1819from jinja2 import Environment2021from werkzeug import ImmutableDict, create_environ21from werkzeug import ImmutableDict22from werkzeug.routing import Map, Rule23from werkzeug.exceptions import HTTPException, InternalServerError, NotFound2425from .helpers import _PackageBoundObject, url_for, get_flashed_messages, \
382 unmodified lines
408409 .. 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)414415 def open_session(self, request):416 """Creates or opens a new session. Default implementation stores all
400 unmodified lines
817 """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))823824 def __call__(self, environ, start_response):825 """Shortcut for :attr:`wsgi_app`."""
1 unmodified line
modified:flask/ctx.py+1 added
58 unmodified lines
59 # 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 lines
29 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 _register3637
165 unmodified lines
added:flask/testing.py+39 added
1# -*- coding: utf-8 -*-2"""3 flask.testing4 ~~~~~~~~~~~~~56 Implements test support helpers. This module is lazily imported7 and usually not used in production environments.89 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12from werkzeug import Client13from flask import _request_ctx_stack141516class FlaskClient(Client):1718 preserve_context = context_preserved = False1920 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 old3132 def __enter__(self):33 self.preserve_context = True34 return self3536 def __exit__(self, exc_type, exc_value, tb):37 self.preserve_context = False38 if self.context_preserved:39 _request_ctx_stack.pop()