Skip to content

Commit 97e2cd0

Browse files
committed
update changelog
move test next to existing test, rename reword / reflow param doc
1 parent 8ad4f47 commit 97e2cd0

File tree

3 files changed

+58
-51
lines changed

3 files changed

+58
-51
lines changed

CHANGES

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ Major release, unreleased
2121
- ``send_file`` supports Unicode in ``attachment_filename``. (`#2223`_)
2222
- Pass ``_scheme`` argument from ``url_for`` to ``handle_build_error``.
2323
(`#2017`_)
24+
- Add support for ``provide_automatic_options`` in ``add_url_rule`` to disable
25+
adding OPTIONS method when the ``view_func`` argument is not a class.
26+
(`#1489`_).
2427

28+
.. _#1489: https://github.com/pallets/flask/pull/1489
2529
.. _#2017: https://github.com/pallets/flask/pull/2017
2630
.. _#2223: https://github.com/pallets/flask/pull/2223
2731

@@ -146,9 +150,6 @@ Released on May 29th 2016, codename Absinthe.
146150
- ``flask.g`` now has ``pop()`` and ``setdefault`` methods.
147151
- Turn on autoescape for ``flask.templating.render_template_string`` by default
148152
(pull request ``#1515``).
149-
- Added support for `provide_automatic_options` in :meth:`add_url_rule` to
150-
turn off automatic OPTIONS when the `view_func` argument is not a class
151-
(pull request ``#1489``).
152153
- ``flask.ext`` is now deprecated (pull request ``#1484``).
153154
- ``send_from_directory`` now raises BadRequest if the filename is invalid on
154155
the server OS (pull request ``#1763``).

flask/app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,7 @@ def iter_blueprints(self):
980980
return iter(self._blueprint_order)
981981

982982
@setupmethod
983-
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):
985984
"""Connects a URL rule. Works exactly like the :meth:`route`
986985
decorator. If a view_func is provided it will be registered with the
987986
endpoint.
@@ -1021,10 +1020,10 @@ def index():
10211020
endpoint
10221021
:param view_func: the function to call when serving a request to the
10231022
provided endpoint
1024-
:param provide_automatic_options: controls whether ``OPTIONS`` should
1025-
be provided automatically. If this
1026-
is not set, will check attributes on
1027-
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 controlled
1025+
by setting the ``view_func.provide_automatic_options = False``
1026+
before adding the rule.
10281027
:param options: the options to be forwarded to the underlying
10291028
:class:`~werkzeug.routing.Rule` object. A change
10301029
to Werkzeug is handling of method options. methods

tests/test_basic.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def index_put():
5050
assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']
5151

5252

53-
def test_options_handling_disabled():
53+
def test_provide_automatic_options_attr():
5454
app = flask.Flask(__name__)
5555

5656
def index():
@@ -70,6 +70,54 @@ def index2():
7070
assert sorted(rv.allow) == ['OPTIONS']
7171

7272

73+
def test_provide_automatic_options_kwarg():
74+
app = flask.Flask(__name__)
75+
76+
def index():
77+
return flask.request.method
78+
79+
def more():
80+
return flask.request.method
81+
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=False
86+
)
87+
88+
c = app.test_client()
89+
assert c.get('/').data == b'GET'
90+
91+
rv = c.post('/')
92+
assert rv.status_code == 405
93+
assert sorted(rv.allow) == ['GET', 'HEAD']
94+
95+
# Older versions of Werkzeug.test.Client don't have an options method
96+
if hasattr(c, 'options'):
97+
rv = c.options('/')
98+
else:
99+
rv = c.open('/', method='OPTIONS')
100+
101+
assert rv.status_code == 405
102+
103+
rv = c.head('/')
104+
assert rv.status_code == 200
105+
assert not rv.data # head truncates
106+
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 == 405
111+
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 == 405
119+
120+
73121
def test_request_dispatching():
74122
app = flask.Flask(__name__)
75123

@@ -1751,44 +1799,3 @@ def run_simple_mock(hostname, port, *args, **kwargs):
17511799
app = flask.Flask(__name__)
17521800
app.config['SERVER_NAME'] = 'pocoo.org:8080'
17531801
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 response
1758-
app = flask.Flask(__name__)
1759-
1760-
def index():
1761-
return flask.request.method
1762-
1763-
def more():
1764-
return flask.request.method
1765-
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 == 405
1773-
assert sorted(rv.allow) == ['GET', 'HEAD']
1774-
# Older versions of Werkzeug.test.Client don't have an options method
1775-
if hasattr(c, 'options'):
1776-
rv = c.options('/')
1777-
else:
1778-
rv = c.open('/', method='OPTIONS')
1779-
assert rv.status_code == 405
1780-
1781-
rv = c.head('/')
1782-
assert rv.status_code == 200
1783-
assert not rv.data # head truncates
1784-
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 == 405
1788-
assert sorted(rv.allow) == ['GET', 'HEAD', 'POST']
1789-
# Older versions of Werkzeug.test.Client don't have an options method
1790-
if hasattr(c, 'options'):
1791-
rv = c.options('/more')
1792-
else:
1793-
rv = c.open('/more', method='OPTIONS')
1794-
assert rv.status_code == 405

0 commit comments

Comments
 (0)