update changelog
Before adoption: this commit came in with the history the project adopted, so no landing records it.
move test next to existing test, rename reword / reflow param doc
authored by David Lord · committed by David Lord · parent 8ad4f47 · Browse files · 3 files·+58 added−51 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+58 added−51 removed
- tests:+49 added−42 removed
- other:+9 added−9 removed
Provenance
- Commit
97e2cd0- Tree
fc6e542- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
8ad4f47
3 files changed+58 added−51 removed
modified:flask/app.py+5 added-6 removed
978 unmodified lines979 """980 return iter(self._blueprint_order)981 982 @setupmethod983- def add_url_rule(self, rule, endpoint=None, view_func=None,984- provide_automatic_options=None, **options):983+ def add_url_rule(self, rule, endpoint=None, view_func=None, provide_automatic_options=None, **options):984 """Connects a URL rule. Works exactly like the :meth:`route`985 decorator. If a view_func is provided it will be registered with the986 endpoint.987 31 unmodified lines1019 itself assumes the name of the view function as1020 endpoint1021 :param view_func: the function to call when serving a request to the1022 provided endpoint1024- :param provide_automatic_options: controls whether ``OPTIONS`` should1025- be provided automatically. If this1026- is not set, will check attributes on1027- the view or list of methods.1023+ :param provide_automatic_options: controls whether the ``OPTIONS``1024+ method should be added automatically. This can also be controlled1025+ by setting the ``view_func.provide_automatic_options = False``1026+ before adding the rule.1027 :param options: the options to be forwarded to the underlying1028 :class:`~werkzeug.routing.Rule` object. A change1029 to Werkzeug is handling of method options. methods1030 is a list of methods this rule should be limited1000 unmodified linesmodified:tests/test_basic.py+49 added-42 removed
48 unmodified lines49 rv = app.test_client().open('/', method='OPTIONS')50 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']51 52 53-def test_options_handling_disabled():53+def test_provide_automatic_options_attr():54 app = flask.Flask(__name__)55 56 def index():57 return 'Hello World!'11 unmodified lines69 rv = app.test_client().open('/', method='OPTIONS')70 assert sorted(rv.allow) == ['OPTIONS']71 72 73+def test_provide_automatic_options_kwarg():74+ app = flask.Flask(__name__)75+76+ def index():77+ return flask.request.method78+79+ def more():80+ return flask.request.method81+82+ app.add_url_rule('/', view_func=index, provide_automatic_options=False)83+ app.add_url_rule(84+ '/more', view_func=more, methods=['GET', 'POST'],85+ provide_automatic_options=False86+ )87+88+ c = app.test_client()89+ assert c.get('/').data == b'GET'90+91+ rv = c.post('/')92+ assert rv.status_code == 40593+ assert sorted(rv.allow) == ['GET', 'HEAD']94+95+ # Older versions of Werkzeug.test.Client don't have an options method96+ if hasattr(c, 'options'):97+ rv = c.options('/')98+ else:99+ rv = c.open('/', method='OPTIONS')100+101+ assert rv.status_code == 405102+103+ rv = c.head('/')104+ assert rv.status_code == 200105+ assert not rv.data # head truncates106+ assert c.post('/more').data == b'POST'107+ assert c.get('/more').data == b'GET'108+109+ rv = c.delete('/more')110+ assert rv.status_code == 405111+ assert sorted(rv.allow) == ['GET', 'HEAD', 'POST']112+113+ if hasattr(c, 'options'):114+ rv = c.options('/more')115+ else:116+ rv = c.open('/more', method='OPTIONS')117+118+ assert rv.status_code == 405119+120+121 def test_request_dispatching():122 app = flask.Flask(__name__)123 124 @app.route('/')1673 unmodified lines1798 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1799 app = flask.Flask(__name__)1800 app.config['SERVER_NAME'] = 'pocoo.org:8080'1801 app.run(host, port)1754-1755-1756-def test_disable_automatic_options():1757- # Issue 1488: Add support for a kwarg to add_url_rule to disable the auto OPTIONS response1758- app = flask.Flask(__name__)1759-1760- def index():1761- return flask.request.method1762-1763- def more():1764- return flask.request.method1765-1766- app.add_url_rule('/', 'index', index, provide_automatic_options=False)1767- app.add_url_rule('/more', 'more', more, methods=['GET', 'POST'], provide_automatic_options=False)1768-1769- c = app.test_client()1770- assert c.get('/').data == b'GET'1771- rv = c.post('/')1772- assert rv.status_code == 4051773- assert sorted(rv.allow) == ['GET', 'HEAD']1774- # Older versions of Werkzeug.test.Client don't have an options method1775- if hasattr(c, 'options'):1776- rv = c.options('/')1777- else:1778- rv = c.open('/', method='OPTIONS')1779- assert rv.status_code == 4051780-1781- rv = c.head('/')1782- assert rv.status_code == 2001783- assert not rv.data # head truncates1784- assert c.post('/more').data == b'POST'1785- assert c.get('/more').data == b'GET'1786- rv = c.delete('/more')1787- assert rv.status_code == 4051788- assert sorted(rv.allow) == ['GET', 'HEAD', 'POST']1789- # Older versions of Werkzeug.test.Client don't have an options method1790- if hasattr(c, 'options'):1791- rv = c.options('/more')1792- else:1793- rv = c.open('/more', method='OPTIONS')1794- assert rv.status_code == 405modified:CHANGES+4 added-3 removed
19 unmodified lines20 be properly associated with the required host. (``#1559``)21 - ``send_file`` supports Unicode in ``attachment_filename``. (`#2223`_)22 - Pass ``_scheme`` argument from ``url_for`` to ``handle_build_error``.23 (`#2017`_)24+- Add support for ``provide_automatic_options`` in ``add_url_rule`` to disable25+ adding OPTIONS method when the ``view_func`` argument is not a class.26+ (`#1489`_).27 28+.. _#1489: https://github.com/pallets/flask/pull/148929 .. _#2017: https://github.com/pallets/flask/pull/201730 .. _#2223: https://github.com/pallets/flask/pull/222331 32 Version 0.12.1116 unmodified lines149 - Allow custom Jinja environment subclasses (pull request ``#1422``).150 - ``flask.g`` now has ``pop()`` and ``setdefault`` methods.151 - Turn on autoescape for ``flask.templating.render_template_string`` by default152 (pull request ``#1515``).149-- Added support for `provide_automatic_options` in :meth:`add_url_rule` to150- turn off automatic OPTIONS when the `view_func` argument is not a class151- (pull request ``#1489``).153 - ``flask.ext`` is now deprecated (pull request ``#1484``).154 - ``send_from_directory`` now raises BadRequest if the filename is invalid on155 the server OS (pull request ``#1763``).156 - Added the ``JSONIFY_MIMETYPE`` configuration variable (pull request ``#1728``).486 unmodified lines