MCPcopy
hub / github.com/pallets/flask / test_view_decorators

Function test_view_decorators

tests/test_views.py:80–98  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

78
79
80def test_view_decorators(app, client):
81 def add_x_parachute(f):
82 def new_function(*args, **kwargs):
83 resp = flask.make_response(f(*args, **kwargs))
84 resp.headers["X-Parachute"] = "awesome"
85 return resp
86
87 return new_function
88
89 class Index(flask.views.View):
90 decorators = [add_x_parachute]
91
92 def dispatch_request(self):
93 return "Awesome"
94
95 app.add_url_rule("/", view_func=Index.as_view("index"))
96 rv = client.get("/")
97 assert rv.headers["X-Parachute"] == "awesome"
98 assert rv.data == b"Awesome"
99
100
101def test_view_provide_automatic_options_attr():

Callers

nothing calls this directly

Calls 3

as_viewMethod · 0.80
add_url_ruleMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected