Merge branch 'test-client-kwargs'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #992
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 6b3fbb3, 986b922 · Browse files · 2 files·+25 added−4 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+25 added−4 removed
- other:+25 added−4 removed
Provenance
- Commit
050a659- Tree
e259392- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
6b3fbb3- Parent 2
986b922
2 files changed+25 added−4 removed
modified:flask/app.py+20 added-2 removed
819 unmodified lines820 # resetted normally. This makes it possible to restart the server821 # without reloader and that stuff from an interactive shell.822 self._got_first_request = False823 824- def test_client(self, use_cookies=True):824+ def test_client(self, use_cookies=True, **kwargs):825 """Creates a test client for this application. For information826 about unit testing head over to :ref:`testing`.827 828 Note that if you are testing for assertions or exceptions in your14 unmodified lines843 with app.test_client() as c:844 rv = c.get('/?vodka=42')845 assert request.args['vodka'] == '42'846 847+ Additionally, you may pass optional keyword arguments that will then848+ be passed to the application's :attr:`test_client_class` constructor.849+ For example::850+851+ from flask.testing import FlaskClient852+853+ class CustomClient(FlaskClient):854+ def __init__(self, authentication=None, *args, **kwargs):855+ FlaskClient.__init__(*args, **kwargs)856+ self._authentication = authentication857+858+ app.test_client_class = CustomClient859+ client = app.test_client(authentication='Basic ....')860+861 See :class:`~flask.testing.FlaskClient` for more information.862 863 .. versionchanged:: 0.4864 added support for `with` block usage for the client.1 unmodified line866 .. versionadded:: 0.7867 The `use_cookies` parameter was added as well as the ability868 to override the client to be used by setting the869 :attr:`test_client_class` attribute.870+871+ .. versionchanged:: 1.0872+ Added `**kwargs` to support passing additional keyword arguments to873+ the constructor of :attr:`test_client_class`.874 """875 cls = self.test_client_class876 if cls is None:877 from flask.testing import FlaskClient as cls860- return cls(self, self.response_class, use_cookies=use_cookies)878+ return cls(self, self.response_class, use_cookies=use_cookies, **kwargs)879 880 def open_session(self, request):881 """Creates or opens a new session. Default implementation stores all882 session data in a signed cookie. This requires that the1025 unmodified linesmodified:CHANGES+5 added-2 removed
6 unmodified lines7 -----------8 9 (release date to be announced, codename to be selected)10 11+- Added `**kwargs` to :meth:`flask.Test.test_client` to support passing12+ additional keyword arguments to the constructor of13+ :attr:`flask.Flask.test_client_class`.14 - Added ``SESSION_REFRESH_EACH_REQUEST`` config key that controls the15 set-cookie behavior. If set to `True` a permanent session will be16 refreshed each request and get their lifetime extended, if set to17 `False` it will only be modified if the session actually modifies.4 unmodified lines22 from a view function.23 - Added :meth:`flask.Config.from_json`.24 - Added :attr:`flask.Flask.config_class`.25 - Added :meth:`flask.config.Config.get_namespace`.23-- Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the 24- templates will be reloaded only if the application is running in 26+- Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the27+ templates will be reloaded only if the application is running in28 debug mode. For higher performance it’s possible to disable that.29 - Added a workaround for a limitation in Python 3.3's namespace loader.30 - Added support for explicit root paths when using Python 3.3's namespace31 packages.505 unmodified lines