forked from orbit-oss/flask
Inherit "methods" in MethodView
* Current behavior: If a base class inherits MethodView and child class inherits without overwriting "methods". The "methods" defined in base class would be ignored * Fix: Inherit all the "methods" defined in base classes if "methods" variable is not overwritten
This commit is contained in:
parent
8ef56c8c6d
commit
1f3923a999
3 changed files with 27 additions and 3 deletions
|
|
@ -10,12 +10,11 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
from werkzeug.http import parse_set_header
|
||||
|
||||
import flask
|
||||
import flask.views
|
||||
|
||||
from werkzeug.http import parse_set_header
|
||||
|
||||
|
||||
def common_test(app):
|
||||
c = app.test_client()
|
||||
|
|
@ -199,6 +198,24 @@ def test_endpoint_override(app):
|
|||
common_test(app)
|
||||
|
||||
|
||||
def test_methods_var_inheritance(app, client):
|
||||
class BaseView(flask.views.MethodView):
|
||||
methods = ["GET", "PROPFIND"]
|
||||
|
||||
class ChildView(BaseView):
|
||||
def get(self):
|
||||
return "GET"
|
||||
|
||||
def propfind(self):
|
||||
return "PROPFIND"
|
||||
|
||||
app.add_url_rule("/", view_func=ChildView.as_view("index"))
|
||||
|
||||
assert client.get("/").data == b"GET"
|
||||
assert client.open("/", method="PROPFIND").data == b"PROPFIND"
|
||||
assert ChildView.methods == {"PROPFIND", "GET"}
|
||||
|
||||
|
||||
def test_multiple_inheritance(app, client):
|
||||
class GetView(flask.views.MethodView):
|
||||
def get(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue