Skip to content

Commit d8eaaba

Browse files
authored
add app.query route decorator (#6133)
2 parents 3596b1a + 8999295 commit d8eaaba

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Unreleased
2929
- ``Flask.select_jinja_autoescape`` uses case-insensitive comparison instead
3030
of only lower case file extensions. :pr:`6012`
3131
- Fix parsing IPv6 with port in ``run`` and the test client. :pr:`6096`
32+
- Add ``app.query`` route decorator for the HTTP QUERY method.
3233

3334

3435
Version 3.1.3

src/flask/sansio/scaffold.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ def get(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
300300
"""
301301
return self._method_route("GET", rule, options)
302302

303+
@setupmethod
304+
def query(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
305+
"""Shortcut for :meth:`route` with ``methods=["QUERY"]``.
306+
307+
.. versionadded:: 3.2
308+
"""
309+
return self._method_route("QUERY", rule, options)
310+
303311
@setupmethod
304312
def post(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
305313
"""Shortcut for :meth:`route` with ``methods=["POST"]``.

tests/test_basic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from contextlib import nullcontext
88
from datetime import datetime
99
from datetime import timezone
10+
from functools import partial
1011
from platform import python_implementation
1112

1213
import pytest
@@ -52,10 +53,12 @@ def index_put():
5253
assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]
5354

5455

55-
@pytest.mark.parametrize("method", ["get", "post", "put", "delete", "patch"])
56+
@pytest.mark.parametrize("method", ["get", "query", "post", "put", "delete", "patch"])
5657
def test_method_route(app, client, method):
5758
method_route = getattr(app, method)
58-
client_method = getattr(client, method)
59+
client_method = getattr(
60+
client, method, partial(client.open, method=method.capitalize())
61+
)
5962

6063
@method_route("/")
6164
def hello():

0 commit comments

Comments
 (0)