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

Function test_view_provide_automatic_options_attr

tests/test_views.py:101–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99
100
101def test_view_provide_automatic_options_attr():
102 app = flask.Flask(__name__)
103
104 class Index1(flask.views.View):
105 provide_automatic_options = False
106
107 def dispatch_request(self):
108 return "Hello World!"
109
110 app.add_url_rule("/", view_func=Index1.as_view("index"))
111 c = app.test_client()
112 rv = c.open("/", method="OPTIONS")
113 assert rv.status_code == 405
114
115 app = flask.Flask(__name__)
116
117 class Index2(flask.views.View):
118 methods = ["OPTIONS"]
119 provide_automatic_options = True
120
121 def dispatch_request(self):
122 return "Hello World!"
123
124 app.add_url_rule("/", view_func=Index2.as_view("index"))
125 c = app.test_client()
126 rv = c.open("/", method="OPTIONS")
127 assert sorted(rv.allow) == ["OPTIONS"]
128
129 app = flask.Flask(__name__)
130
131 class Index3(flask.views.View):
132 def dispatch_request(self):
133 return "Hello World!"
134
135 app.add_url_rule("/", view_func=Index3.as_view("index"))
136 c = app.test_client()
137 rv = c.open("/", method="OPTIONS")
138 assert "OPTIONS" in rv.allow
139
140
141def test_implicit_head(app, client):

Callers

nothing calls this directly

Calls 4

test_clientMethod · 0.95
as_viewMethod · 0.80
openMethod · 0.80
add_url_ruleMethod · 0.45

Tested by

no test coverage detected