forked from orbit-oss/flask
add View.init_every_request attribute
This commit is contained in:
parent
aab1d9935e
commit
6e23239567
3 changed files with 61 additions and 13 deletions
|
|
@ -240,3 +240,21 @@ def test_remove_method_from_parent(app, client):
|
|||
assert client.get("/").data == b"GET"
|
||||
assert client.post("/").status_code == 405
|
||||
assert sorted(View.methods) == ["GET"]
|
||||
|
||||
|
||||
def test_init_once(app, client):
|
||||
n = 0
|
||||
|
||||
class CountInit(flask.views.View):
|
||||
init_every_request = False
|
||||
|
||||
def __init__(self):
|
||||
nonlocal n
|
||||
n += 1
|
||||
|
||||
def dispatch_request(self):
|
||||
return str(n)
|
||||
|
||||
app.add_url_rule("/", view_func=CountInit.as_view("index"))
|
||||
assert client.get("/").data == b"1"
|
||||
assert client.get("/").data == b"1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue