commit
2e17ad7fd4
2 changed files with 10 additions and 0 deletions
|
|
@ -949,6 +949,9 @@ class Flask(_PackageBoundObject):
|
||||||
# a tuple of only `GET` as default.
|
# a tuple of only `GET` as default.
|
||||||
if methods is None:
|
if methods is None:
|
||||||
methods = getattr(view_func, 'methods', None) or ('GET',)
|
methods = getattr(view_func, 'methods', None) or ('GET',)
|
||||||
|
if isinstance(methods, string_types):
|
||||||
|
raise TypeError('Allowed methods have to be iterables of strings, '
|
||||||
|
'for example: @app.route(..., methods=["POST"])')
|
||||||
methods = set(methods)
|
methods = set(methods)
|
||||||
|
|
||||||
# Methods that should always be added
|
# Methods that should always be added
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,13 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
||||||
self.assert_equal(rv.status_code, 405)
|
self.assert_equal(rv.status_code, 405)
|
||||||
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST'])
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST'])
|
||||||
|
|
||||||
|
def test_disallow_string_for_allowed_methods(self):
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
with self.assert_raises(TypeError):
|
||||||
|
@app.route('/', methods='GET POST')
|
||||||
|
def index():
|
||||||
|
return "Hey"
|
||||||
|
|
||||||
def test_url_mapping(self):
|
def test_url_mapping(self):
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
def index():
|
def index():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue