MCPcopy Create free account
hub / github.com/pallets/flask / test_url_mapping

Function test_url_mapping

tests/test_basic.py:157–190  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

155
156
157def test_url_mapping(app, client):
158 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"
159
160 def index():
161 return flask.request.method
162
163 def more():
164 return flask.request.method
165
166 def options():
167 return random_uuid4
168
169 app.add_url_rule("/", "index", index)
170 app.add_url_rule("/more", "more", more, methods=["GET", "POST"])
171
172 # Issue 1288: Test that automatic options are not added
173 # when non-uppercase 'options' in methods
174 app.add_url_rule("/options", "options", options, methods=["options"])
175
176 assert client.get("/").data == b"GET"
177 rv = client.post("/")
178 assert rv.status_code == 405
179 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]
180 rv = client.head("/")
181 assert rv.status_code == 200
182 assert not rv.data # head truncates
183 assert client.post("/more").data == b"POST"
184 assert client.get("/more").data == b"GET"
185 rv = client.delete("/more")
186 assert rv.status_code == 405
187 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]
188 rv = client.open("/options", method="OPTIONS")
189 assert rv.status_code == 200
190 assert random_uuid4 in rv.data.decode("utf-8")
191
192
193def test_werkzeug_routing(app, client):

Callers

nothing calls this directly

Calls 6

headMethod · 0.80
openMethod · 0.80
add_url_ruleMethod · 0.45
getMethod · 0.45
postMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected