Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

1,968 lines · 52.6 KiB · Python

Last changed by

f-strings everywhereDavid Lordbefore adoption2ae740d

History of this file

Take it

The walk stopped after 200 commits: lines older than 16d83d6 point at it.

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1–6why, one step back
1"""
2 tests.basic3 ~~~~~~~~~~~~~~~~~~~~~45 The basic functionality.6

Merge branch '1.0.x'David Lordbefore adoption1351d0a

lines 7–8why, one step back
7 :copyright: 2010 Pallets
8 :license: BSD-3-Clause

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 9–10why, one step back
9"""
10import re

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

line 11why, one step back
11import sys

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 12–18why, one step back
12import time
13import uuid14from datetime import datetime15from threading import Thread1617import pytest18import werkzeug.serving

Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697

lines 19–21why, one step back
19from werkzeug.exceptions import BadRequest
20from werkzeug.exceptions import Forbidden21from werkzeug.exceptions import NotFound

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 22–28why, one step back
22from werkzeug.http import parse_date
23from werkzeug.routing import BuildError2425import flask262728def test_options_work(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 29–37why, one step back
29 @app.route("/", methods=["GET", "POST"])
30 def index():31 return "Hello World"3233 rv = client.open("/", method="OPTIONS")34 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]35 assert rv.data == b""3637

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 38why, one step back
38def test_options_on_multiple_rules(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 39–43why, one step back
39 @app.route("/", methods=["GET", "POST"])
40 def index():41 return "Hello World"4243 @app.route("/", methods=["PUT"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 44why, one step back
44 def index_put():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 45–50why, one step back
45 return "Aha!"
4647 rv = client.open("/", method="OPTIONS")48 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]4950

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 51why, one step back
51def test_provide_automatic_options_attr():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 52–56why, one step back
52 app = flask.Flask(__name__)
5354 def index():55 return "Hello World!"56

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 57why, one step back
57 index.provide_automatic_options = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 58–66why, one step back
58 app.route("/")(index)
59 rv = app.test_client().open("/", method="OPTIONS")60 assert rv.status_code == 4056162 app = flask.Flask(__name__)6364 def index2():65 return "Hello World!"66

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 67why, one step back
67 index2.provide_automatic_options = True

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 68–72why, one step back
68 app.route("/", methods=["OPTIONS"])(index2)
69 rv = app.test_client().open("/", method="OPTIONS")70 assert sorted(rv.allow) == ["OPTIONS"]7172

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 73why, one step back
73def test_provide_automatic_options_kwarg(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 74–80why, one step back
74 def index():
75 return flask.request.method7677 def more():78 return flask.request.method7980 app.add_url_rule("/", view_func=index, provide_automatic_options=False)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 81why, one step back
81 app.add_url_rule(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 82–92why, one step back
82 "/more",
83 view_func=more,84 methods=["GET", "POST"],85 provide_automatic_options=False,86 )87 assert client.get("/").data == b"GET"8889 rv = client.post("/")90 assert rv.status_code == 40591 assert sorted(rv.allow) == ["GET", "HEAD"]92

remove more compat codeDavid Lordbefore adoption57d628c

line 93why, one step back
93 rv = client.open("/", method="OPTIONS")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 94–105why, one step back
94 assert rv.status_code == 405
9596 rv = client.head("/")97 assert rv.status_code == 20098 assert not rv.data # head truncates99 assert client.post("/more").data == b"POST"100 assert client.get("/more").data == b"GET"101102 rv = client.delete("/more")103 assert rv.status_code == 405104 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]105

remove more compat codeDavid Lordbefore adoption57d628c

line 106why, one step back
106 rv = client.open("/more", method="OPTIONS")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 107–109why, one step back
107 assert rv.status_code == 405
108109

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 110why, one step back
110def test_request_dispatching(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 111–132why, one step back
111 @app.route("/")
112 def index():113 return flask.request.method114115 @app.route("/more", methods=["GET", "POST"])116 def more():117 return flask.request.method118119 assert client.get("/").data == b"GET"120 rv = client.post("/")121 assert rv.status_code == 405122 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]123 rv = client.head("/")124 assert rv.status_code == 200125 assert not rv.data # head truncates126 assert client.post("/more").data == b"POST"127 assert client.get("/more").data == b"GET"128 rv = client.delete("/more")129 assert rv.status_code == 405130 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]131132

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 133–134why, one step back
133def test_disallow_string_for_allowed_methods(app):
134 with pytest.raises(TypeError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 135–137why, one step back
135
136 @app.route("/", methods="GET POST")137 def index():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 138why, one step back
138 return "Hey"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 139–140why, one step back
139
140

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 141–142why, one step back
141def test_url_mapping(app, client):
142 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 143–149why, one step back
143
144 def index():145 return flask.request.method146147 def more():148 return flask.request.method149

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 150–151why, one step back
150 def options():
151 return random_uuid4

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 152–155why, one step back
152
153 app.add_url_rule("/", "index", index)154 app.add_url_rule("/more", "more", more, methods=["GET", "POST"])155

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

lines 156–157why, one step back
156 # Issue 1288: Test that automatic options are not added
157 # when non-uppercase 'options' in methods

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 158–173why, one step back
158 app.add_url_rule("/options", "options", options, methods=["options"])
159160 assert client.get("/").data == b"GET"161 rv = client.post("/")162 assert rv.status_code == 405163 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]164 rv = client.head("/")165 assert rv.status_code == 200166 assert not rv.data # head truncates167 assert client.post("/more").data == b"POST"168 assert client.get("/more").data == b"GET"169 rv = client.delete("/more")170 assert rv.status_code == 405171 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]172 rv = client.open("/options", method="OPTIONS")173 assert rv.status_code == 200

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 174why, one step back
174 assert random_uuid4 in rv.data.decode("utf-8")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 175–176why, one step back
175
176

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 177why, one step back
177def test_werkzeug_routing(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 178–196why, one step back
178 from werkzeug.routing import Submount, Rule
179180 app.url_map.add(181 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])182 )183184 def bar():185 return "bar"186187 def index():188 return "index"189190 app.view_functions["bar"] = bar191 app.view_functions["index"] = index192193 assert client.get("/foo/").data == b"index"194 assert client.get("/foo/bar").data == b"bar"195196

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 197why, one step back
197def test_endpoint_decorator(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 198–215why, one step back
198 from werkzeug.routing import Submount, Rule
199200 app.url_map.add(201 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])202 )203204 @app.endpoint("bar")205 def bar():206 return "bar"207208 @app.endpoint("index")209 def index():210 return "index"211212 assert client.get("/foo/").data == b"index"213 assert client.get("/foo/bar").data == b"bar"214215

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 216why, one step back
216def test_session(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 217why, one step back
217 @app.route("/set", methods=["POST"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 218why, one step back
218 def set():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 219–222why, one step back
219 assert not flask.session.accessed
220 assert not flask.session.modified221 flask.session["value"] = flask.request.form["value"]222 assert flask.session.accessed

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 223why, one step back
223 assert flask.session.modified

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 224–232why, one step back
224 return "value set"
225226 @app.route("/get")227 def get():228 assert not flask.session.accessed229 assert not flask.session.modified230 v = flask.session.get("value", "None")231 assert flask.session.accessed232 assert not flask.session.modified

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 233why, one step back
233 return v

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 234–238why, one step back
234
235 assert client.post("/set", data={"value": "42"}).data == b"value set"236 assert client.get("/get").data == b"42"237238

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 239why, one step back
239def test_session_using_server_name(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 240–251why, one step back
240 app.config.update(SERVER_NAME="example.com")
241242 @app.route("/")243 def index():244 flask.session["testing"] = 42245 return "Hello World"246247 rv = client.get("/", "http://example.com/")248 assert "domain=.example.com" in rv.headers["set-cookie"].lower()249 assert "httponly" in rv.headers["set-cookie"].lower()250251

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 252why, one step back
252def test_session_using_server_name_and_port(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 253–264why, one step back
253 app.config.update(SERVER_NAME="example.com:8080")
254255 @app.route("/")256 def index():257 flask.session["testing"] = 42258 return "Hello World"259260 rv = client.get("/", "http://example.com:8080/")261 assert "domain=.example.com" in rv.headers["set-cookie"].lower()262 assert "httponly" in rv.headers["set-cookie"].lower()263264

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 265why, one step back
265def test_session_using_server_name_port_and_path(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 266–278why, one step back
266 app.config.update(SERVER_NAME="example.com:8080", APPLICATION_ROOT="/foo")
267268 @app.route("/")269 def index():270 flask.session["testing"] = 42271 return "Hello World"272273 rv = client.get("/", "http://example.com:8080/foo")274 assert "domain=example.com" in rv.headers["set-cookie"].lower()275 assert "path=/foo" in rv.headers["set-cookie"].lower()276 assert "httponly" in rv.headers["set-cookie"].lower()277278

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 279why, one step back
279def test_session_using_application_root(app, client):

apply pyupgradeDavid Lordbefore adoption524fd0b

line 280why, one step back
280 class PrefixPathMiddleware:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 281–283why, one step back
281 def __init__(self, app, prefix):
282 self.app = app283 self.prefix = prefix

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 284why, one step back
284

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 285why, one step back
285 def __call__(self, environ, start_response):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 286why, one step back
286 environ["SCRIPT_NAME"] = self.prefix

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 287why, one step back
287 return self.app(environ, start_response)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 288–300why, one step back
288
289 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, "/bar")290 app.config.update(APPLICATION_ROOT="/bar")291292 @app.route("/")293 def index():294 flask.session["testing"] = 42295 return "Hello World"296297 rv = client.get("/", "http://example.com:8080/")298 assert "path=/bar" in rv.headers["set-cookie"].lower()299300

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 301why, one step back
301def test_session_using_session_settings(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 302–305why, one step back
302 app.config.update(
303 SERVER_NAME="www.example.com:8080",304 APPLICATION_ROOT="/test",305 SESSION_COOKIE_DOMAIN=".example.com",

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 306–307why, one step back
306 SESSION_COOKIE_HTTPONLY=False,
307 SESSION_COOKIE_SECURE=True,

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 308–325why, one step back
308 SESSION_COOKIE_SAMESITE="Lax",
309 SESSION_COOKIE_PATH="/",310 )311312 @app.route("/")313 def index():314 flask.session["testing"] = 42315 return "Hello World"316317 rv = client.get("/", "http://www.example.com:8080/test/")318 cookie = rv.headers["set-cookie"].lower()319 assert "domain=.example.com" in cookie320 assert "path=/" in cookie321 assert "secure" in cookie322 assert "httponly" not in cookie323 assert "samesite" in cookie324325

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 326why, one step back
326def test_session_using_samesite_attribute(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 327–333why, one step back
327 @app.route("/")
328 def index():329 flask.session["testing"] = 42330 return "Hello World"331332 app.config.update(SESSION_COOKIE_SAMESITE="invalid")333

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 334why, one step back
334 with pytest.raises(ValueError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 335–336why, one step back
335 client.get("/")
336

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 337why, one step back
337 app.config.update(SESSION_COOKIE_SAMESITE=None)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 338–352why, one step back
338 rv = client.get("/")
339 cookie = rv.headers["set-cookie"].lower()340 assert "samesite" not in cookie341342 app.config.update(SESSION_COOKIE_SAMESITE="Strict")343 rv = client.get("/")344 cookie = rv.headers["set-cookie"].lower()345 assert "samesite=strict" in cookie346347 app.config.update(SESSION_COOKIE_SAMESITE="Lax")348 rv = client.get("/")349 cookie = rv.headers["set-cookie"].lower()350 assert "samesite=lax" in cookie351352

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 353why, one step back
353def test_session_localhost_warning(recwarn, app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 354–363why, one step back
354 app.config.update(SERVER_NAME="localhost:5000")
355356 @app.route("/")357 def index():358 flask.session["testing"] = 42359 return "testing"360361 rv = client.get("/", "http://localhost:5000/")362 assert "domain" not in rv.headers["set-cookie"].lower()363 w = recwarn.pop(UserWarning)

f-strings everywhereDavid Lordbefore adoption2ae740d

line 364why, one step back
364 assert "'localhost' is not a valid cookie domain" in str(w.message)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 365–366why, one step back
365
366

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 367why, one step back
367def test_session_ip_warning(recwarn, app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 368–380why, one step back
368 app.config.update(SERVER_NAME="127.0.0.1:5000")
369370 @app.route("/")371 def index():372 flask.session["testing"] = 42373 return "testing"374375 rv = client.get("/", "http://127.0.0.1:5000/")376 assert "domain=127.0.0.1" in rv.headers["set-cookie"].lower()377 w = recwarn.pop(UserWarning)378 assert "cookie domain is an IP" in str(w.message)379380

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 381–382why, one step back
381def test_missing_session(app):
382 app.secret_key = None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 383why, one step back
383

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 384–385why, one step back
384 def expect_exception(f, *args, **kwargs):
385 e = pytest.raises(RuntimeError, f, *args, **kwargs)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 386–393why, one step back
386 assert e.value.args and "session is unavailable" in e.value.args[0]
387388 with app.test_request_context():389 assert flask.session.get("missing_key") is None390 expect_exception(flask.session.__setitem__, "foo", 42)391 expect_exception(flask.session.pop, "foo")392393

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 394–395why, one step back
394def test_session_expiration(app, client):
395 permanent = True

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 396–399why, one step back
396
397 @app.route("/")398 def index():399 flask.session["test"] = 42

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 400why, one step back
400 flask.session.permanent = permanent

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 401–404why, one step back
401 return ""
402403 @app.route("/test")404 def test():

remove _compat moduleDavid Lordbefore adoption662c245

line 405why, one step back
405 return str(flask.session.permanent)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 406–409why, one step back
406
407 rv = client.get("/")408 assert "set-cookie" in rv.headers409 match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 410–414why, one step back
410 expires = parse_date(match.group())
411 expected = datetime.utcnow() + app.permanent_session_lifetime412 assert expires.year == expected.year413 assert expires.month == expected.month414 assert expires.day == expected.day

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 415–418why, one step back
415
416 rv = client.get("/test")417 assert rv.data == b"True"418

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 419why, one step back
419 permanent = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 420–422why, one step back
420 rv = client.get("/")
421 assert "set-cookie" in rv.headers422 match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 423why, one step back
423 assert match is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 424–425why, one step back
424
425

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 426why, one step back
426def test_session_stored_last(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 427why, one step back
427 @app.after_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 428why, one step back
428 def modify_session(response):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 429–439why, one step back
429 flask.session["foo"] = 42
430 return response431432 @app.route("/")433 def dump_session_contents():434 return repr(flask.session.get("foo"))435436 assert client.get("/").data == b"None"437 assert client.get("/").data == b"42"438439

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 440–442why, one step back
440def test_session_special_types(app, client):
441 now = datetime.utcnow().replace(microsecond=0)442 the_uuid = uuid.uuid4()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 443–457why, one step back
443
444 @app.route("/")445 def dump_session_contents():446 flask.session["t"] = (1, 2, 3)447 flask.session["b"] = b"\xff"448 flask.session["m"] = flask.Markup("<html>")449 flask.session["u"] = the_uuid450 flask.session["d"] = now451 flask.session["t_tag"] = {" t": "not-a-tuple"}452 flask.session["di_t_tag"] = {" t__": "not-a-tuple"}453 flask.session["di_tag"] = {" di": "not-a-dict"}454 return "", 204455456 with client:457 client.get("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 458why, one step back
458 s = flask.session

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 459–470why, one step back
459 assert s["t"] == (1, 2, 3)
460 assert type(s["b"]) == bytes461 assert s["b"] == b"\xff"462 assert type(s["m"]) == flask.Markup463 assert s["m"] == flask.Markup("<html>")464 assert s["u"] == the_uuid465 assert s["d"] == now466 assert s["t_tag"] == {" t": "not-a-tuple"}467 assert s["di_t_tag"] == {" t__": "not-a-tuple"}468 assert s["di_tag"] == {" di": "not-a-dict"}469470

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 471why, one step back
471def test_session_cookie_setting(app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 472–474why, one step back
472 is_permanent = True
473474 @app.route("/bump")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 475why, one step back
475 def bump():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 476why, one step back
476 rv = flask.session["foo"] = flask.session.get("foo", 0) + 1

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 477–478why, one step back
477 flask.session.permanent = is_permanent
478 return str(rv)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 479–480why, one step back
479
480 @app.route("/read")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 481why, one step back
481 def read():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 482–483why, one step back
482 return str(flask.session.get("foo", 0))
483

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 484–485why, one step back
484 def run_test(expect_header):
485 with app.test_client() as c:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 486–491why, one step back
486 assert c.get("/bump").data == b"1"
487 assert c.get("/bump").data == b"2"488 assert c.get("/bump").data == b"3"489490 rv = c.get("/read")491 set_cookie = rv.headers.get("set-cookie")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 492why, one step back
492 assert (set_cookie is not None) == expect_header

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 493–496why, one step back
493 assert rv.data == b"3"
494495 is_permanent = True496 app.config["SESSION_REFRESH_EACH_REQUEST"] = True

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 497why, one step back
497 run_test(expect_header=True)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 498–511why, one step back
498
499 is_permanent = True500 app.config["SESSION_REFRESH_EACH_REQUEST"] = False501 run_test(expect_header=False)502503 is_permanent = False504 app.config["SESSION_REFRESH_EACH_REQUEST"] = True505 run_test(expect_header=False)506507 is_permanent = False508 app.config["SESSION_REFRESH_EACH_REQUEST"] = False509 run_test(expect_header=False)510511

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 512why, one step back
512def test_session_vary_cookie(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 513why, one step back
513 @app.route("/set")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 514why, one step back
514 def set_session():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 515–522why, one step back
515 flask.session["test"] = "test"
516 return ""517518 @app.route("/get")519 def get():520 return flask.session.get("test")521522 @app.route("/getitem")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 523why, one step back
523 def getitem():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 524–526why, one step back
524 return flask.session["test"]
525526 @app.route("/setdefault")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 527why, one step back
527 def setdefault():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 528–530why, one step back
528 return flask.session.setdefault("test", "default")
529530 @app.route("/vary-cookie-header-set")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 531why, one step back
531 def vary_cookie_header_set():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 532–537why, one step back
532 response = flask.Response()
533 response.vary.add("Cookie")534 flask.session["test"] = "test"535 return response536537 @app.route("/vary-header-set")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 538why, one step back
538 def vary_header_set():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 539–544why, one step back
539 response = flask.Response()
540 response.vary.update(("Accept-Encoding", "Accept-Language"))541 flask.session["test"] = "test"542 return response543544 @app.route("/no-vary-header")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 545why, one step back
545 def no_vary_header():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 546–548why, one step back
546 return ""
547548 def expect(path, header_value="Cookie"):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 549why, one step back
549 rv = client.get(path)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 550why, one step back
550

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 551–552why, one step back
551 if header_value:
552 # The 'Vary' key should exist in the headers only once.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 553–566why, one step back
553 assert len(rv.headers.get_all("Vary")) == 1
554 assert rv.headers["Vary"] == header_value555 else:556 assert "Vary" not in rv.headers557558 expect("/set")559 expect("/get")560 expect("/getitem")561 expect("/setdefault")562 expect("/vary-cookie-header-set")563 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")564 expect("/no-vary-header", None)565566

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 567–568why, one step back
567def test_flashes(app, req_ctx):
568 assert not flask.session.modified

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 569why, one step back
569 flask.flash("Zap")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 570why, one step back
570 flask.session.modified = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 571why, one step back
571 flask.flash("Zip")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 572why, one step back
572 assert flask.session.modified

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 573–575why, one step back
573 assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]
574575

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 576–581why, one step back
576def test_extended_flashing(app):
577 # Be sure app.testing=True below, else tests can fail silently.578 #579 # Specifically, if app.testing is not set to True, the AssertionErrors580 # in the view functions will cause a 500 response to the test client581 # instead of propagating exceptions.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 582–584why, one step back
582
583 @app.route("/")584 def index():

apply pyupgradeDavid Lordbefore adoption524fd0b

lines 585–587why, one step back
585 flask.flash("Hello World")
586 flask.flash("Hello World", "error")587 flask.flash(flask.Markup("<em>Testing</em>"), "warning")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 588–591why, one step back
588 return ""
589590 @app.route("/test/")591 def test():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 592why, one step back
592 messages = flask.get_flashed_messages()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 593why, one step back
593 assert list(messages) == [

apply pyupgradeDavid Lordbefore adoption524fd0b

lines 594–596why, one step back
594 "Hello World",
595 "Hello World",596 flask.Markup("<em>Testing</em>"),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 597–600why, one step back
597 ]
598 return ""599600 @app.route("/test_with_categories/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 601–603why, one step back
601 def test_with_categories():
602 messages = flask.get_flashed_messages(with_categories=True)603 assert len(messages) == 3

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 604why, one step back
604 assert list(messages) == [

apply pyupgradeDavid Lordbefore adoption524fd0b

lines 605–607why, one step back
605 ("message", "Hello World"),
606 ("error", "Hello World"),607 ("warning", flask.Markup("<em>Testing</em>")),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 608–611why, one step back
608 ]
609 return ""610611 @app.route("/test_filter/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 612why, one step back
612 def test_filter():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 613–615why, one step back
613 messages = flask.get_flashed_messages(
614 category_filter=["message"], with_categories=True615 )

apply pyupgradeDavid Lordbefore adoption524fd0b

line 616why, one step back
616 assert list(messages) == [("message", "Hello World")]

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 617–619why, one step back
617 return ""
618619 @app.route("/test_filters/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 620why, one step back
620 def test_filters():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 621–624why, one step back
621 messages = flask.get_flashed_messages(
622 category_filter=["message", "warning"], with_categories=True623 )624 assert list(messages) == [

apply pyupgradeDavid Lordbefore adoption524fd0b

lines 625–626why, one step back
625 ("message", "Hello World"),
626 ("warning", flask.Markup("<em>Testing</em>")),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 627–630why, one step back
627 ]
628 return ""629630 @app.route("/test_filters_without_returning_categories/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 631why, one step back
631 def test_filters2():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 632why, one step back
632 messages = flask.get_flashed_messages(category_filter=["message", "warning"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 633why, one step back
633 assert len(messages) == 2

apply pyupgradeDavid Lordbefore adoption524fd0b

lines 634–635why, one step back
634 assert messages[0] == "Hello World"
635 assert messages[1] == flask.Markup("<em>Testing</em>")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 636–637why, one step back
636 return ""
637

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 638why, one step back
638 # Create new test client on each test to clean flashed messages.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 639–656why, one step back
639
640 client = app.test_client()641 client.get("/")642 client.get("/test_with_categories/")643644 client = app.test_client()645 client.get("/")646 client.get("/test_filter/")647648 client = app.test_client()649 client.get("/")650 client.get("/test_filters/")651652 client = app.test_client()653 client.get("/")654 client.get("/test_filters_without_returning_categories/")655656

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 657why, one step back
657def test_request_processing(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 658–681why, one step back
658 evts = []
659660 @app.before_request661 def before_request():662 evts.append("before")663664 @app.after_request665 def after_request(response):666 response.data += b"|after"667 evts.append("after")668 return response669670 @app.route("/")671 def index():672 assert "before" in evts673 assert "after" not in evts674 return "request"675676 assert "after" not in evts677 rv = client.get("/").data678 assert "after" in evts679 assert rv == b"request|after"680681

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 682why, one step back
682def test_request_preprocessing_early_return(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 683–685why, one step back
683 evts = []
684685 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 686–687why, one step back
686 def before_request1():
687 evts.append(1)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 688–689why, one step back
688
689 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 690–692why, one step back
690 def before_request2():
691 evts.append(2)692 return "hello"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 693–694why, one step back
693
694 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 695–697why, one step back
695 def before_request3():
696 evts.append(3)697 return "bye"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 698–701why, one step back
698
699 @app.route("/")700 def index():701 evts.append("index")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 702why, one step back
702 return "damnit"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 703–705why, one step back
703
704 rv = client.get("/").data.strip()705 assert rv == b"hello"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 706why, one step back
706 assert evts == [1, 2]

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 707–708why, one step back
707
708

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 709why, one step back
709def test_after_request_processing(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 710–711why, one step back
710 @app.route("/")
711 def index():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 712–713why, one step back
712 @flask.after_this_request
713 def foo(response):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 714why, one step back
714 response.headers["X-Foo"] = "a header"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 715why, one step back
715 return response

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 716–719why, one step back
716
717 return "Test"718719 resp = client.get("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 720why, one step back
720 assert resp.status_code == 200

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 721–723why, one step back
721 assert resp.headers["X-Foo"] == "a header"
722723

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 724why, one step back
724def test_teardown_request_handler(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 725–741why, one step back
725 called = []
726727 @app.teardown_request728 def teardown_request(exc):729 called.append(True)730 return "Ignored"731732 @app.route("/")733 def root():734 return "Response"735736 rv = client.get("/")737 assert rv.status_code == 200738 assert b"Response" in rv.data739 assert len(called) == 1740741

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 742why, one step back
742def test_teardown_request_handler_debug_mode(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 743–759why, one step back
743 called = []
744745 @app.teardown_request746 def teardown_request(exc):747 called.append(True)748 return "Ignored"749750 @app.route("/")751 def root():752 return "Response"753754 rv = client.get("/")755 assert rv.status_code == 200756 assert b"Response" in rv.data757 assert len(called) == 1758759

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 760why, one step back
760def test_teardown_request_handler_error(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 761–764why, one step back
761 called = []
762 app.testing = False763764 @app.teardown_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 765why, one step back
765 def teardown_request1(exc):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 766–772why, one step back
766 assert type(exc) == ZeroDivisionError
767 called.append(True)768 # This raises a new error and blows away sys.exc_info(), so we can769 # test that all teardown_requests get passed the same original770 # exception.771 try:772 raise TypeError()

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 773why, one step back
773 except Exception:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 774–776why, one step back
774 pass
775776 @app.teardown_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 777why, one step back
777 def teardown_request2(exc):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 778–784why, one step back
778 assert type(exc) == ZeroDivisionError
779 called.append(True)780 # This raises a new error and blows away sys.exc_info(), so we can781 # test that all teardown_requests get passed the same original782 # exception.783 try:784 raise TypeError()

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 785why, one step back
785 except Exception:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 786–788why, one step back
786 pass
787788 @app.route("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 789why, one step back
789 def fails():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 790–794why, one step back
790 1 // 0
791792 rv = client.get("/")793 assert rv.status_code == 500794 assert b"Internal Server Error" in rv.data

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 795why, one step back
795 assert len(called) == 2

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 796–797why, one step back
796
797

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 798why, one step back
798def test_before_after_request_order(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 799–801why, one step back
799 called = []
800801 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 802–803why, one step back
802 def before1():
803 called.append(1)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 804–805why, one step back
804
805 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 806–807why, one step back
806 def before2():
807 called.append(2)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 808–809why, one step back
808
809 @app.after_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 810–811why, one step back
810 def after1(response):
811 called.append(4)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 812–814why, one step back
812 return response
813814 @app.after_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 815–816why, one step back
815 def after2(response):
816 called.append(3)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 817–819why, one step back
817 return response
818819 @app.teardown_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 820–821why, one step back
820 def finish1(exc):
821 called.append(6)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 822–823why, one step back
822
823 @app.teardown_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 824–825why, one step back
824 def finish2(exc):
825 called.append(5)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 826–832why, one step back
826
827 @app.route("/")828 def index():829 return "42"830831 rv = client.get("/")832 assert rv.data == b"42"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 833why, one step back
833 assert called == [1, 2, 3, 4, 5, 6]

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 834–835why, one step back
834
835

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 836why, one step back
836def test_error_handling(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 837–839why, one step back
837 app.testing = False
838839 @app.errorhandler(404)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 840why, one step back
840 def not_found(e):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 841–846why, one step back
841 return "not found", 404
842843 @app.errorhandler(500)844 def internal_server_error(e):845 return "internal server error", 500846

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 847–848why, one step back
847 @app.errorhandler(Forbidden)
848 def forbidden(e):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 849–855why, one step back
849 return "forbidden", 403
850851 @app.route("/")852 def index():853 flask.abort(404)854855 @app.route("/error")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 856why, one step back
856 def error():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 857–859why, one step back
857 1 // 0
858859 @app.route("/forbidden")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 860why, one step back
860 def error2():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 861–869why, one step back
861 flask.abort(403)
862863 rv = client.get("/")864 assert rv.status_code == 404865 assert rv.data == b"not found"866 rv = client.get("/error")867 assert rv.status_code == 500868 assert b"internal server error" == rv.data869 rv = client.get("/forbidden")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 870why, one step back
870 assert rv.status_code == 403

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 871–873why, one step back
871 assert b"forbidden" == rv.data
872873

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 874–875why, one step back
874def test_error_handler_unknown_code(app):
875 with pytest.raises(KeyError) as exc_info:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 876–880why, one step back
876 app.register_error_handler(999, lambda e: ("999", 999))
877878 assert "Use a subclass" in exc_info.value.args[0]879880

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 881why, one step back
881def test_error_handling_processing(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 882–892why, one step back
882 app.testing = False
883884 @app.errorhandler(500)885 def internal_server_error(e):886 return "internal server error", 500887888 @app.route("/")889 def broken_func():890 1 // 0891892 @app.after_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 893why, one step back
893 def after_request(resp):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 894why, one step back
894 resp.mimetype = "text/x-special"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 895why, one step back
895 return resp

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 896–901why, one step back
896
897 resp = client.get("/")898 assert resp.mimetype == "text/x-special"899 assert resp.data == b"internal server error"900901

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 902why, one step back
902def test_baseexception_error_handling(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 903–906why, one step back
903 app.testing = False
904905 @app.route("/")906 def broken_func():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 907why, one step back
907 raise KeyboardInterrupt()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 908why, one step back
908

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 909why, one step back
909 with pytest.raises(KeyboardInterrupt):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 910–911why, one step back
910 client.get("/")
911

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 912–914why, one step back
912 ctx = flask._request_ctx_stack.top
913 assert ctx.preserved914 assert type(ctx._preserved_exc) is KeyboardInterrupt

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 915–916why, one step back
915
916

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 917why, one step back
917def test_before_request_and_routing_errors(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 918why, one step back
918 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 919why, one step back
919 def attach_something():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 920–922why, one step back
920 flask.g.something = "value"
921922 @app.errorhandler(404)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 923–924why, one step back
923 def return_something(error):
924 return flask.g.something, 404

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 925–930why, one step back
925
926 rv = client.get("/")927 assert rv.status_code == 404928 assert rv.data == b"value"929930

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 931–932why, one step back
931def test_user_error_handling(app, client):
932 class MyException(Exception):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 933–934why, one step back
933 pass
934

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 935–937why, one step back
935 @app.errorhandler(MyException)
936 def handle_my_exception(e):937 assert isinstance(e, MyException)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 938–941why, one step back
938 return "42"
939940 @app.route("/")941 def index():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 942why, one step back
942 raise MyException()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 943–946why, one step back
943
944 assert client.get("/").data == b"42"945946

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 947–948why, one step back
947def test_http_error_subclass_handling(app, client):
948 class ForbiddenSubclass(Forbidden):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 949–950why, one step back
949 pass
950

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 951why, one step back
951 @app.errorhandler(ForbiddenSubclass)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 952why, one step back
952 def handle_forbidden_subclass(e):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 953why, one step back
953 assert isinstance(e, ForbiddenSubclass)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 954–955why, one step back
954 return "banana"
955

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 956why, one step back
956 @app.errorhandler(403)

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 957why, one step back
957 def handle_403(e):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 958–959why, one step back
958 assert not isinstance(e, ForbiddenSubclass)
959 assert isinstance(e, Forbidden)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 960–962why, one step back
960 return "apple"
961962 @app.route("/1")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 963–964why, one step back
963 def index1():
964 raise ForbiddenSubclass()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 965–970why, one step back
965
966 @app.route("/2")967 def index2():968 flask.abort(403)969970 @app.route("/3")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 971–972why, one step back
971 def index3():
972 raise Forbidden()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 973–978why, one step back
973
974 assert client.get("/1").data == b"banana"975 assert client.get("/2").data == b"apple"976 assert client.get("/3").data == b"apple"977978

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 979–980why, one step back
979def test_errorhandler_precedence(app, client):
980 class E1(Exception):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 981–982why, one step back
981 pass
982

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 983why, one step back
983 class E2(Exception):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 984–985why, one step back
984 pass
985

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 986why, one step back
986 class E3(E1, E2):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 987–988why, one step back
987 pass
988

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 989–990why, one step back
989 @app.errorhandler(E2)
990 def handle_e2(e):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 991–992why, one step back
991 return "E2"
992

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 993–994why, one step back
993 @app.errorhandler(Exception)
994 def handle_exception(e):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 995–997why, one step back
995 return "Exception"
996997 @app.route("/E1")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 998–999why, one step back
998 def raise_e1():
999 raise E1

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1000–1001why, one step back
1000
1001 @app.route("/E3")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1002–1003why, one step back
1002 def raise_e3():
1003 raise E3

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1004–1011why, one step back
1004
1005 rv = client.get("/E1")1006 assert rv.data == b"Exception"10071008 rv = client.get("/E3")1009 assert rv.data == b"E2"10101011

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1012why, one step back
1012def test_trapping_of_bad_request_key_errors(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1013–1017why, one step back
1013 @app.route("/key")
1014 def fail():1015 flask.request.form["missing_key"]10161017 @app.route("/abort")

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

lines 1018–1019why, one step back
1018 def allow_abort():
1019 flask.abort(400)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1020–1027why, one step back
1020
1021 rv = client.get("/key")1022 assert rv.status_code == 4001023 assert b"missing_key" not in rv.data1024 rv = client.get("/abort")1025 assert rv.status_code == 40010261027 app.debug = True

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1028why, one step back
1028 with pytest.raises(KeyError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1029why, one step back
1029 client.get("/key")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1030why, one step back
1030 assert e.errisinstance(BadRequest)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1031–1036why, one step back
1031 assert "missing_key" in e.value.get_description()
1032 rv = client.get("/abort")1033 assert rv.status_code == 40010341035 app.debug = False1036 app.config["TRAP_BAD_REQUEST_ERRORS"] = True

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

line 1037why, one step back
1037 with pytest.raises(KeyError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1038why, one step back
1038 client.get("/key")

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

line 1039why, one step back
1039 with pytest.raises(BadRequest):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1040–1042why, one step back
1040 client.get("/abort")
10411042

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1043why, one step back
1043def test_trapping_of_all_http_exceptions(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1044–1049why, one step back
1044 app.config["TRAP_HTTP_EXCEPTIONS"] = True
10451046 @app.route("/fail")1047 def fail():1048 flask.abort(404)1049

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1050why, one step back
1050 with pytest.raises(NotFound):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1051–1053why, one step back
1051 client.get("/fail")
10521053

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1054why, one step back
1054def test_error_handler_after_processor_error(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1055–1058why, one step back
1055 app.testing = False
10561057 @app.before_request1058 def before_request():

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1059why, one step back
1059 if _trigger == "before":

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1060–1063why, one step back
1060 1 // 0
10611062 @app.after_request1063 def after_request(response):

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1064why, one step back
1064 if _trigger == "after":

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1065–1075why, one step back
1065 1 // 0
1066 return response10671068 @app.route("/")1069 def index():1070 return "Foo"10711072 @app.errorhandler(500)1073 def internal_server_error(e):1074 return "Hello Server Error", 5001075

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1076why, one step back
1076 for _trigger in "before", "after":

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1077why, one step back
1077 rv = client.get("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1078why, one step back
1078 assert rv.status_code == 500

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1079–1081why, one step back
1079 assert rv.data == b"Hello Server Error"
10801081

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1082–1083why, one step back
1082def test_enctype_debug_helper(app, client):
1083 from flask.debughelpers import DebugFilesKeyError

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1084–1090why, one step back
1084
1085 app.debug = True10861087 @app.route("/fail", methods=["POST"])1088 def index():1089 return flask.request.files["foo"].filename1090

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1091–1093why, one step back
1091 # with statement is important because we leave an exception on the
1092 # stack otherwise and we want to ensure that this is not the case1093 # to not negatively affect other tests.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1094why, one step back
1094 with client:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1095why, one step back
1095 with pytest.raises(DebugFilesKeyError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1096–1097why, one step back
1096 client.post("/fail", data={"foo": "index.txt"})
1097 assert "no file contents were transmitted" in str(e.value)

f-strings everywhereDavid Lordbefore adoption2ae740d

line 1098why, one step back
1098 assert "This was submitted: 'index.txt'" in str(e.value)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1099–1100why, one step back
1099
1100

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1101why, one step back
1101def test_response_types(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1102why, one step back
1102 @app.route("/text")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1103why, one step back
1103 def from_text():

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1104why, one step back
1104 return "Hällo Wörld"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1105–1106why, one step back
1105
1106 @app.route("/bytes")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1107why, one step back
1107 def from_bytes():

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1108why, one step back
1108 return "Hällo Wörld".encode()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1109–1110why, one step back
1109
1110 @app.route("/full_tuple")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1111why, one step back
1111 def from_full_tuple():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1112–1118why, one step back
1112 return (
1113 "Meh",1114 400,1115 {"X-Foo": "Testing", "Content-Type": "text/plain; charset=utf-8"},1116 )11171118 @app.route("/text_headers")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1119why, one step back
1119 def from_text_headers():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1120–1122why, one step back
1120 return "Hello", {"X-Foo": "Test", "Content-Type": "text/plain; charset=utf-8"}
11211122 @app.route("/text_status")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1123why, one step back
1123 def from_text_status():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1124–1126why, one step back
1124 return "Hi, status!", 400
11251126 @app.route("/response_headers")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1127why, one step back
1127 def from_response_headers():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1128–1133why, one step back
1128 return (
1129 flask.Response("Hello world", 404, {"X-Foo": "Baz"}),1130 {"X-Foo": "Bar", "X-Bar": "Foo"},1131 )11321133 @app.route("/response_status")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1134why, one step back
1134 def from_response_status():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1135–1137why, one step back
1135 return app.response_class("Hello world", 400), 500
11361137 @app.route("/wsgi")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1138–1139why, one step back
1138 def from_wsgi():
1139 return NotFound()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1140why, one step back
1140

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

line 1141why, one step back
1141 @app.route("/dict")

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

lines 1142–1143why, one step back
1142 def from_dict():
1143 return {"foo": "bar"}, 201

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1144why, one step back
1144

apply pyupgradeDavid Lordbefore adoption524fd0b

lines 1145–1146why, one step back
1145 assert client.get("/text").data == "Hällo Wörld".encode()
1146 assert client.get("/bytes").data == "Hällo Wörld".encode()

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1147why, one step back
1147

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1148–1177why, one step back
1148 rv = client.get("/full_tuple")
1149 assert rv.data == b"Meh"1150 assert rv.headers["X-Foo"] == "Testing"1151 assert rv.status_code == 4001152 assert rv.mimetype == "text/plain"11531154 rv = client.get("/text_headers")1155 assert rv.data == b"Hello"1156 assert rv.headers["X-Foo"] == "Test"1157 assert rv.status_code == 2001158 assert rv.mimetype == "text/plain"11591160 rv = client.get("/text_status")1161 assert rv.data == b"Hi, status!"1162 assert rv.status_code == 4001163 assert rv.mimetype == "text/html"11641165 rv = client.get("/response_headers")1166 assert rv.data == b"Hello world"1167 assert rv.headers.getlist("X-Foo") == ["Baz", "Bar"]1168 assert rv.headers["X-Bar"] == "Foo"1169 assert rv.status_code == 40411701171 rv = client.get("/response_status")1172 assert rv.data == b"Hello world"1173 assert rv.status_code == 50011741175 rv = client.get("/wsgi")1176 assert b"Not Found" in rv.data1177 assert rv.status_code == 404

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1178why, one step back
1178

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

line 1179why, one step back
1179 rv = client.get("/dict")

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

lines 1180–1181why, one step back
1180 assert rv.json == {"foo": "bar"}
1181 assert rv.status_code == 201

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1182–1183why, one step back
1182
1183

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1184why, one step back
1184def test_response_type_errors():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1185–1188why, one step back
1185 app = flask.Flask(__name__)
1186 app.testing = True11871188 @app.route("/none")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1189why, one step back
1189 def from_none():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1190–1192why, one step back
1190 pass
11911192 @app.route("/small_tuple")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1193why, one step back
1193 def from_small_tuple():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1194–1196why, one step back
1194 return ("Hello",)
11951196 @app.route("/large_tuple")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1197why, one step back
1197 def from_large_tuple():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1198–1200why, one step back
1198 return "Hello", 234, {"X-Foo": "Bar"}, "???"
11991200 @app.route("/bad_type")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1201–1202why, one step back
1201 def from_bad_type():
1202 return True

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1203–1204why, one step back
1203
1204 @app.route("/bad_wsgi")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1205–1206why, one step back
1205 def from_bad_wsgi():
1206 return lambda: None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1207–1211why, one step back
1207
1208 c = app.test_client()12091210 with pytest.raises(TypeError) as e:1211 c.get("/none")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1212why, one step back
1212 assert "returned None" in str(e.value)

Merge pull request #3498 from raymond-devries/3445-traceback-for-noneDavid Lordbefore adoptiona3e4395

line 1213why, one step back
1213 assert "from_none" in str(e.value)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1214–1216why, one step back
1214
1215 with pytest.raises(TypeError) as e:1216 c.get("/small_tuple")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1217why, one step back
1217 assert "tuple must have the form" in str(e.value)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1218–1222why, one step back
1218
1219 pytest.raises(TypeError, c.get, "/large_tuple")12201221 with pytest.raises(TypeError) as e:1222 c.get("/bad_type")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1223why, one step back
1223 assert "it was a bool" in str(e.value)

Merge pull request #3235 from johnzeringue/better-return-type-errorDavid Lordbefore adoption52f9aa7

line 1224why, one step back
1224

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1225–1227why, one step back
1225 pytest.raises(TypeError, c.get, "/bad_wsgi")
12261227

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1228–1229why, one step back
1228def test_make_response(app, req_ctx):
1229 rv = flask.make_response()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1230–1244why, one step back
1230 assert rv.status_code == 200
1231 assert rv.data == b""1232 assert rv.mimetype == "text/html"12331234 rv = flask.make_response("Awesome")1235 assert rv.status_code == 2001236 assert rv.data == b"Awesome"1237 assert rv.mimetype == "text/html"12381239 rv = flask.make_response("W00t", 404)1240 assert rv.status_code == 4041241 assert rv.data == b"W00t"1242 assert rv.mimetype == "text/html"12431244

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1245why, one step back
1245def test_make_response_with_response_instance(app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1246–1247why, one step back
1246 rv = flask.make_response(flask.jsonify({"msg": "W00t"}), 400)
1247 assert rv.status_code == 400

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1248why, one step back
1248 assert rv.data == b'{"msg":"W00t"}\n'

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1249–1265why, one step back
1249 assert rv.mimetype == "application/json"
12501251 rv = flask.make_response(flask.Response(""), 400)1252 assert rv.status_code == 4001253 assert rv.data == b""1254 assert rv.mimetype == "text/html"12551256 rv = flask.make_response(1257 flask.Response("", headers={"Content-Type": "text/html"}),1258 400,1259 [("X-Foo", "bar")],1260 )1261 assert rv.status_code == 4001262 assert rv.headers["Content-Type"] == "text/html"1263 assert rv.headers["X-Foo"] == "bar"12641265

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1266–1268why, one step back
1266def test_jsonify_no_prettyprint(app, req_ctx):
1267 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})1268 compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n'

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1269–1271why, one step back
1269 uncompressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}
12701271 rv = flask.make_response(flask.jsonify(uncompressed_msg), 200)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1272why, one step back
1272 assert rv.data == compressed_msg

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1273–1274why, one step back
1273
1274

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1275–1277why, one step back
1275def test_jsonify_prettyprint(app, req_ctx):
1276 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})1277 compressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1278why, one step back
1278 pretty_response = (

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1279why, one step back
1279 b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}\n'

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1280–1282why, one step back
1280 )
12811282 rv = flask.make_response(flask.jsonify(compressed_msg), 200)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1283why, one step back
1283 assert rv.data == pretty_response

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1284–1285why, one step back
1284
1285

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1286why, one step back
1286def test_jsonify_mimetype(app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1287–1291why, one step back
1287 app.config.update({"JSONIFY_MIMETYPE": "application/vnd.api+json"})
1288 msg = {"msg": {"submsg": "W00t"}}1289 rv = flask.make_response(flask.jsonify(msg), 200)1290 assert rv.mimetype == "application/vnd.api+json"1291

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

lines 1292–1295why, one step back
1292
1293@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")1294def test_json_dump_dataclass(app, req_ctx):1295 from dataclasses import make_dataclass

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

line 1296why, one step back
1296

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

lines 1297–1300why, one step back
1297 Data = make_dataclass("Data", [("name", str)])
1298 value = flask.json.dumps(Data("Flask"), app=app)1299 value = flask.json.loads(value, app=app)1300 assert value == {"name": "Flask"}

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1301why, one step back
1301

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

line 1302why, one step back
1302

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1303why, one step back
1303def test_jsonify_args_and_kwargs_check(app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1304–1308why, one step back
1304 with pytest.raises(TypeError) as e:
1305 flask.jsonify("fake args", kwargs="fake")1306 assert "behavior undefined" in str(e.value)13071308

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1309why, one step back
1309def test_url_generation(app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1310why, one step back
1310 @app.route("/hello/<name>", methods=["POST"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1311why, one step back
1311 def hello():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1312–1320why, one step back
1312 pass
13131314 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1315 assert (1316 flask.url_for("hello", name="test x", _external=True)1317 == "http://localhost/hello/test%20x"1318 )13191320

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1321–1322why, one step back
1321def test_build_error_handler(app):
1322 # Test base case, a URL which results in a BuildError.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1323–1325why, one step back
1323 with app.test_request_context():
1324 pytest.raises(BuildError, flask.url_for, "spam")1325

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1326why, one step back
1326 # Verify the error is re-raised if not the current exception.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1327why, one step back
1327 try:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1328why, one step back
1328 with app.test_request_context():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1329why, one step back
1329 flask.url_for("spam")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1330–1331why, one step back
1330 except BuildError as err:
1331 error = err

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1332–1333why, one step back
1332 try:
1333 raise RuntimeError("Test case where BuildError is not current.")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1334why, one step back
1334 except RuntimeError:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1335–1336why, one step back
1335 pytest.raises(BuildError, app.handle_url_build_error, error, "spam", {})
1336

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1337why, one step back
1337 # Test a custom handler.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1338why, one step back
1338 def handler(error, endpoint, values):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1339why, one step back
1339 # Just a test.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1340–1341why, one step back
1340 return "/test_handler/"
1341

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1342why, one step back
1342 app.url_build_error_handlers.append(handler)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1343–1346why, one step back
1343 with app.test_request_context():
1344 assert flask.url_for("spam") == "/test_handler/"13451346

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1347–1350why, one step back
1347def test_build_error_handler_reraise(app):
1348 # Test a custom handler which reraises the BuildError1349 def handler_raises_build_error(error, endpoint, values):1350 raise error

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1351why, one step back
1351

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1352why, one step back
1352 app.url_build_error_handlers.append(handler_raises_build_error)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1353–1357why, one step back
1353
1354 with app.test_request_context():1355 pytest.raises(BuildError, flask.url_for, "not.existing")13561357

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1358–1359why, one step back
1358def test_url_for_passes_special_values_to_build_error_handler(app):
1359 @app.url_build_error_handlers.append

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1360why, one step back
1360 def handler(error, endpoint, values):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1361why, one step back
1361 assert values == {

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1362–1372why, one step back
1362 "_external": False,
1363 "_anchor": None,1364 "_method": None,1365 "_scheme": None,1366 }1367 return "handled"13681369 with app.test_request_context():1370 flask.url_for("/")13711372

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1373why, one step back
1373def test_static_files(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1374–1381why, one step back
1374 rv = client.get("/static/index.html")
1375 assert rv.status_code == 2001376 assert rv.data.strip() == b"<h1>Hello World!</h1>"1377 with app.test_request_context():1378 assert flask.url_for("static", filename="index.html") == "/static/index.html"1379 rv.close()13801381

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1382why, one step back
1382def test_static_url_path():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1383–1392why, one step back
1383 app = flask.Flask(__name__, static_url_path="/foo")
1384 app.testing = True1385 rv = app.test_client().get("/foo/index.html")1386 assert rv.status_code == 2001387 rv.close()13881389 with app.test_request_context():1390 assert flask.url_for("static", filename="index.html") == "/foo/index.html"13911392

Merge pull request #3182 from qil026/issue-3134-url-joinDavid Lordbefore adoptiondbd3840

lines 1393–1403why, one step back
1393def test_static_url_path_with_ending_slash():
1394 app = flask.Flask(__name__, static_url_path="/foo/")1395 app.testing = True1396 rv = app.test_client().get("/foo/index.html")1397 assert rv.status_code == 2001398 rv.close()13991400 with app.test_request_context():1401 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14021403

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

line 1404why, one step back
1404def test_static_url_empty_path(app):

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

lines 1405–1406why, one step back
1405 app = flask.Flask(__name__, static_folder="", static_url_path="")
1406 rv = app.test_client().open("/static/index.html", method="GET")

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1407–1411why, one step back
1407 assert rv.status_code == 200
1408 rv.close()140914101411def test_static_url_empty_path_default(app):

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

lines 1412–1413why, one step back
1412 app = flask.Flask(__name__, static_folder="")
1413 rv = app.test_client().open("/static/index.html", method="GET")

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1414–1417why, one step back
1414 assert rv.status_code == 200
1415 rv.close()14161417

Merge remote-tracking branch 'origin/1.1.x'David Lordbefore adoption64ba434

lines 1418–1428why, one step back
1418def test_static_folder_with_ending_slash():
1419 app = flask.Flask(__name__, static_folder="static/")14201421 @app.route("/<path:path>")1422 def catch_all(path):1423 return path14241425 rv = app.test_client().get("/catch/all")1426 assert rv.data == b"catch/all"14271428

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1429why, one step back
1429def test_static_route_with_host_matching():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1430–1437why, one step back
1430 app = flask.Flask(__name__, host_matching=True, static_host="example.com")
1431 c = app.test_client()1432 rv = c.get("http://example.com/static/index.html")1433 assert rv.status_code == 2001434 rv.close()1435 with app.test_request_context():1436 rv = flask.url_for("static", filename="index.html", _external=True)1437 assert rv == "http://example.com/static/index.html"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1438why, one step back
1438 # Providing static_host without host_matching=True should error.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1439–1440why, one step back
1439 with pytest.raises(Exception):
1440 flask.Flask(__name__, static_host="example.com")

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

lines 1441–1442why, one step back
1441 # Providing host_matching=True with static_folder
1442 # but without static_host should error.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1443why, one step back
1443 with pytest.raises(Exception):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1444why, one step back
1444 flask.Flask(__name__, host_matching=True)

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

lines 1445–1446why, one step back
1445 # Providing host_matching=True without static_host
1446 # but with static_folder=None should not error.

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1447why, one step back
1447 flask.Flask(__name__, host_matching=True, static_folder=None)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1448–1449why, one step back
1448
1449

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1450why, one step back
1450def test_request_locals():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1451why, one step back
1451 assert repr(flask.g) == "<LocalProxy unbound>"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1452why, one step back
1452 assert not flask.g

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1453–1454why, one step back
1453
1454

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1455why, one step back
1455def test_server_name_subdomain():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1456–1460why, one step back
1456 app = flask.Flask(__name__, subdomain_matching=True)
1457 client = app.test_client()14581459 @app.route("/")1460 def index():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1461why, one step back
1461 return "default"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1462–1463why, one step back
1462
1463 @app.route("/", subdomain="foo")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1464why, one step back
1464 def subdomain():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1465why, one step back
1465 return "subdomain"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1466why, one step back
1466

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1467why, one step back
1467 app.config["SERVER_NAME"] = "dev.local:5000"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1468why, one step back
1468 rv = client.get("/")

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1469why, one step back
1469 assert rv.data == b"default"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1470why, one step back
1470

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1471–1472why, one step back
1471 rv = client.get("/", "http://dev.local:5000")
1472 assert rv.data == b"default"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1473why, one step back
1473

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1474–1475why, one step back
1474 rv = client.get("/", "https://dev.local:5000")
1475 assert rv.data == b"default"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1476why, one step back
1476

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1477–1478why, one step back
1477 app.config["SERVER_NAME"] = "dev.local:443"
1478 rv = client.get("/", "https://dev.local")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1479why, one step back
1479

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1480–1482why, one step back
1480 # Werkzeug 1.0 fixes matching https scheme with 443 port
1481 if rv.status_code != 404:1482 assert rv.data == b"default"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1483why, one step back
1483

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1484–1489why, one step back
1484 app.config["SERVER_NAME"] = "dev.local"
1485 rv = client.get("/", "https://dev.local")1486 assert rv.data == b"default"14871488 # suppress Werkzeug 1.0 warning about name mismatch1489 with pytest.warns(None):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1490–1492why, one step back
1490 rv = client.get("/", "http://foo.localhost")
1491 assert rv.status_code == 4041492

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1493–1494why, one step back
1493 rv = client.get("/", "http://foo.dev.local")
1494 assert rv.data == b"subdomain"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1495–1496why, one step back
1495
1496

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1497–1498why, one step back
1497def test_exception_propagation(app, client):
1498 def apprunner(config_key):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1499–1502why, one step back
1499 @app.route("/")
1500 def index():1501 1 // 01502

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1503–1505why, one step back
1503 if config_key is not None:
1504 app.config[config_key] = True1505 with pytest.raises(Exception):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1506–1509why, one step back
1506 client.get("/")
1507 else:1508 assert client.get("/").status_code == 5001509

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1510–1513why, one step back
1510 # we have to run this test in an isolated thread because if the
1511 # debug flag is set to true and an exception happens the context is1512 # not torn down. This causes other tests that run after this fail1513 # when they expect no exception on the stack.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1514why, one step back
1514 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1515–1517why, one step back
1515 t = Thread(target=apprunner, args=(config_key,))
1516 t.start()1517 t.join()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1518–1534why, one step back
1518
15191520@pytest.mark.parametrize("debug", [True, False])1521@pytest.mark.parametrize("use_debugger", [True, False])1522@pytest.mark.parametrize("use_reloader", [True, False])1523@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1524def test_werkzeug_passthrough_errors(1525 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1526):1527 rv = {}15281529 # Mocks werkzeug.serving.run_simple method1530 def run_simple_mock(*args, **kwargs):1531 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15321533 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1534 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptions

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1535why, one step back
1535 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1536–1537why, one step back
1536
1537

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1538why, one step back
1538def test_max_content_length(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1539–1541why, one step back
1539 app.config["MAX_CONTENT_LENGTH"] = 64
15401541 @app.before_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1542why, one step back
1542 def always_first():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1543why, one step back
1543 flask.request.form["myfile"]

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1544why, one step back
1544 AssertionError()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1545–1546why, one step back
1545
1546 @app.route("/accept", methods=["POST"])

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1547why, one step back
1547 def accept_file():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1548why, one step back
1548 flask.request.form["myfile"]

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1549why, one step back
1549 AssertionError()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1550why, one step back
1550

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1551–1552why, one step back
1551 @app.errorhandler(413)
1552 def catcher(error):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1553–1558why, one step back
1553 return "42"
15541555 rv = client.post("/accept", data={"myfile": "foo" * 100})1556 assert rv.data == b"42"15571558

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1559–1561why, one step back
1559def test_url_processors(app, client):
1560 @app.url_defaults1561 def add_language_code(endpoint, values):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1562–1566why, one step back
1562 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(
1563 endpoint, "lang_code"1564 ):1565 values.setdefault("lang_code", flask.g.lang_code)1566

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1567–1568why, one step back
1567 @app.url_value_preprocessor
1568 def pull_lang_code(endpoint, values):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1569–1575why, one step back
1569 flask.g.lang_code = values.pop("lang_code", None)
15701571 @app.route("/<lang_code>/")1572 def index():1573 return flask.url_for("about")15741575 @app.route("/<lang_code>/about")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1576why, one step back
1576 def about():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1577–1579why, one step back
1577 return flask.url_for("something_else")
15781579 @app.route("/foo")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1580why, one step back
1580 def something_else():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1581–1587why, one step back
1581 return flask.url_for("about", lang_code="en")
15821583 assert client.get("/de/").data == b"/de/about"1584 assert client.get("/de/about").data == b"/foo"1585 assert client.get("/foo").data == b"/en/about"15861587

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1588why, one step back
1588def test_inject_blueprint_url_defaults(app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1589–1590why, one step back
1589 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")
1590

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1591–1592why, one step back
1591 @bp.url_defaults
1592 def bp_defaults(endpoint, values):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1593–1595why, one step back
1593 values["page"] = "login"
15941595 @bp.route("/<page>")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1596why, one step back
1596 def view(page):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1597–1598why, one step back
1597 pass
1598

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1599why, one step back
1599 app.register_blueprint(bp)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1600why, one step back
1600

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1601why, one step back
1601 values = dict()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1602–1603why, one step back
1602 app.inject_url_defaults("foo.bar.baz.view", values)
1603 expected = dict(page="login")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1604why, one step back
1604 assert values == expected

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1605–1608why, one step back
1605
1606 with app.test_request_context("/somepage"):1607 url = flask.url_for("foo.bar.baz.view")1608 expected = "/login"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1609why, one step back
1609 assert url == expected

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1610–1611why, one step back
1610
1611

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1612why, one step back
1612def test_nonascii_pathinfo(app, client):

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1613why, one step back
1613 @app.route("/киртест")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1614–1616why, one step back
1614 def index():
1615 return "Hello World!"1616

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1617why, one step back
1617 rv = client.get("/киртест")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1618–1620why, one step back
1618 assert rv.data == b"Hello World!"
16191620

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1621why, one step back
1621def test_debug_mode_complains_after_first_request(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1622–1627why, one step back
1622 app.debug = True
16231624 @app.route("/")1625 def index():1626 return "Awesome"1627

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1628why, one step back
1628 assert not app.got_first_request

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1629why, one step back
1629 assert client.get("/").data == b"Awesome"

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1630why, one step back
1630 with pytest.raises(AssertionError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1631–1632why, one step back
1631
1632 @app.route("/foo")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1633why, one step back
1633 def broken():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1634–1635why, one step back
1634 return "Meh"
1635

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1636why, one step back
1636 assert "A setup function was called" in str(e.value)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1637–1640why, one step back
1637
1638 app.debug = False16391640 @app.route("/foo")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1641why, one step back
1641 def working():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1642–1647why, one step back
1642 return "Meh"
16431644 assert client.get("/foo").data == b"Meh"1645 assert app.got_first_request16461647

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1648why, one step back
1648def test_before_first_request_functions(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1649–1661why, one step back
1649 got = []
16501651 @app.before_first_request1652 def foo():1653 got.append(42)16541655 client.get("/")1656 assert got == [42]1657 client.get("/")1658 assert got == [42]1659 assert app.got_first_request16601661

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1662why, one step back
1662def test_before_first_request_functions_concurrent(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1663–1666why, one step back
1663 got = []
16641665 @app.before_first_request1666 def foo():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1667why, one step back
1667 time.sleep(0.2)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1668–1669why, one step back
1668 got.append(42)
1669

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1670why, one step back
1670 def get_and_assert():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1671why, one step back
1671 client.get("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1672why, one step back
1672 assert got == [42]

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1673why, one step back
1673

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1674–1677why, one step back
1674 t = Thread(target=get_and_assert)
1675 t.start()1676 get_and_assert()1677 t.join()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1678–1680why, one step back
1678 assert app.got_first_request
16791680

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1681why, one step back
1681def test_routing_redirect_debugging(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1682–1688why, one step back
1682 app.debug = True
16831684 @app.route("/foo/", methods=["GET", "POST"])1685 def foo():1686 return "success"16871688 with client:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1689why, one step back
1689 with pytest.raises(AssertionError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1690why, one step back
1690 client.post("/foo", data={})

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1691why, one step back
1691 assert "http://localhost/foo/" in str(e.value)

Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b

line 1692why, one step back
1692 assert "Make sure to directly send your POST-request to this URL" in str(

Merge branch '1.0.x'David Lordbefore adoptionb05a685

lines 1693–1694why, one step back
1693 e.value
1694 )

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1695–1704why, one step back
1695
1696 rv = client.get("/foo", data={}, follow_redirects=True)1697 assert rv.data == b"success"16981699 app.debug = False1700 with client:1701 rv = client.post("/foo", data={}, follow_redirects=True)1702 assert rv.data == b"success"17031704

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1705why, one step back
1705def test_route_decorator_custom_endpoint(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1706–1712why, one step back
1706 app.debug = True
17071708 @app.route("/foo/")1709 def foo():1710 return flask.request.endpoint17111712 @app.route("/bar/", endpoint="bar")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1713why, one step back
1713 def for_bar():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1714–1716why, one step back
1714 return flask.request.endpoint
17151716 @app.route("/bar/123", endpoint="123")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1717why, one step back
1717 def for_bar_foo():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1718–1729why, one step back
1718 return flask.request.endpoint
17191720 with app.test_request_context():1721 assert flask.url_for("foo") == "/foo/"1722 assert flask.url_for("bar") == "/bar/"1723 assert flask.url_for("123") == "/bar/123"17241725 assert client.get("/foo/").data == b"foo"1726 assert client.get("/bar/").data == b"bar"1727 assert client.get("/bar/123").data == b"123"17281729

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1730why, one step back
1730def test_preserve_only_once(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1731–1736why, one step back
1731 app.debug = True
17321733 @app.route("/fail")1734 def fail_func():1735 1 // 01736

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1737why, one step back
1737 for _x in range(3):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1738why, one step back
1738 with pytest.raises(ZeroDivisionError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1739–1740why, one step back
1739 client.get("/fail")
1740

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1741–1746why, one step back
1741 assert flask._request_ctx_stack.top is not None
1742 assert flask._app_ctx_stack.top is not None1743 # implicit appctx disappears too1744 flask._request_ctx_stack.top.pop()1745 assert flask._request_ctx_stack.top is None1746 assert flask._app_ctx_stack.top is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1747–1748why, one step back
1747
1748

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1749why, one step back
1749def test_preserve_remembers_exception(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1750why, one step back
1750 app.debug = True

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1751why, one step back
1751 errors = []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1752–1757why, one step back
1752
1753 @app.route("/fail")1754 def fail_func():1755 1 // 017561757 @app.route("/success")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1758why, one step back
1758 def success_func():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1759–1761why, one step back
1759 return "Okay"
17601761 @app.teardown_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1762–1763why, one step back
1762 def teardown_handler(exc):
1763 errors.append(exc)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1764why, one step back
1764

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1765–1766why, one step back
1765 # After this failure we did not yet call the teardown handler
1766 with pytest.raises(ZeroDivisionError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1767why, one step back
1767 client.get("/fail")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1768why, one step back
1768 assert errors == []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1769why, one step back
1769

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1770why, one step back
1770 # But this request triggers it, and it's an error

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1771why, one step back
1771 client.get("/success")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1772–1773why, one step back
1772 assert len(errors) == 2
1773 assert isinstance(errors[0], ZeroDivisionError)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1774why, one step back
1774

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1775why, one step back
1775 # At this point another request does nothing.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1776why, one step back
1776 client.get("/success")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1777–1778why, one step back
1777 assert len(errors) == 3
1778 assert errors[1] is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1779–1780why, one step back
1779
1780

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1781why, one step back
1781def test_get_method_on_g(app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1782–1783why, one step back
1782 assert flask.g.get("x") is None
1783 assert flask.g.get("x", 11) == 11

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1784why, one step back
1784 flask.g.x = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1785why, one step back
1785 assert flask.g.get("x") == 42

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1786why, one step back
1786 assert flask.g.x == 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1787–1788why, one step back
1787
1788

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1789–1791why, one step back
1789def test_g_iteration_protocol(app_ctx):
1790 flask.g.foo = 231791 flask.g.bar = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1792–1796why, one step back
1792 assert "foo" in flask.g
1793 assert "foos" not in flask.g1794 assert sorted(flask.g) == ["bar", "foo"]17951796

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1797why, one step back
1797def test_subdomain_basic_support():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1798–1802why, one step back
1798 app = flask.Flask(__name__, subdomain_matching=True)
1799 app.config["SERVER_NAME"] = "localhost.localdomain"1800 client = app.test_client()18011802 @app.route("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1803why, one step back
1803 def normal_index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1804–1806why, one step back
1804 return "normal index"
18051806 @app.route("/", subdomain="test")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1807why, one step back
1807 def test_index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1808–1816why, one step back
1808 return "test index"
18091810 rv = client.get("/", "http://localhost.localdomain/")1811 assert rv.data == b"normal index"18121813 rv = client.get("/", "http://test.localhost.localdomain/")1814 assert rv.data == b"test index"18151816

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1817why, one step back
1817def test_subdomain_matching():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1818–1823why, one step back
1818 app = flask.Flask(__name__, subdomain_matching=True)
1819 client = app.test_client()1820 app.config["SERVER_NAME"] = "localhost.localdomain"18211822 @app.route("/", subdomain="<user>")1823 def index(user):

f-strings everywhereDavid Lordbefore adoption2ae740d

line 1824why, one step back
1824 return f"index for {user}"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1825–1829why, one step back
1825
1826 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1827 assert rv.data == b"index for mitsuhiko"18281829

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1830why, one step back
1830def test_subdomain_matching_with_ports():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1831–1836why, one step back
1831 app = flask.Flask(__name__, subdomain_matching=True)
1832 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1833 client = app.test_client()18341835 @app.route("/", subdomain="<user>")1836 def index(user):

f-strings everywhereDavid Lordbefore adoption2ae740d

line 1837why, one step back
1837 return f"index for {user}"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1838–1843why, one step back
1838
1839 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1840 assert rv.data == b"index for mitsuhiko"184118421843@pytest.mark.parametrize("matching", (False, True))

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1844–1845why, one step back
1844def test_subdomain_matching_other_name(matching):
1845 app = flask.Flask(__name__, subdomain_matching=matching)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1846–1852why, one step back
1846 app.config["SERVER_NAME"] = "localhost.localdomain:3000"
1847 client = app.test_client()18481849 @app.route("/")1850 def index():1851 return "", 2041852

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1853–1857why, one step back
1853 # suppress Werkzeug 0.15 warning about name mismatch
1854 with pytest.warns(None):1855 # ip address can't match name1856 rv = client.get("/", "http://127.0.0.1:3000/")1857 assert rv.status_code == 404 if matching else 204

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1858why, one step back
1858

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1859why, one step back
1859 # allow all subdomains if matching is disabled

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1860–1863why, one step back
1860 rv = client.get("/", "http://www.localhost.localdomain:3000/")
1861 assert rv.status_code == 404 if matching else 20418621863

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1864why, one step back
1864def test_multi_route_rules(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1865–1867why, one step back
1865 @app.route("/")
1866 @app.route("/<test>/")1867 def index(test="a"):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1868why, one step back
1868 return test

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1869–1875why, one step back
1869
1870 rv = client.open("/")1871 assert rv.data == b"a"1872 rv = client.open("/b/")1873 assert rv.data == b"b"18741875

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1876why, one step back
1876def test_multi_route_class_views(app, client):

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1877why, one step back
1877 class View:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1878why, one step back
1878 def __init__(self, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1879–1882why, one step back
1879 app.add_url_rule("/", "index", self.index)
1880 app.add_url_rule("/<test>/", "index", self.index)18811882 def index(self, test="a"):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1883why, one step back
1883 return test

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1884why, one step back
1884

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1885why, one step back
1885 _ = View(app)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1886–1891why, one step back
1886 rv = client.open("/")
1887 assert rv.data == b"a"1888 rv = client.open("/b/")1889 assert rv.data == b"b"18901891

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1892why, one step back
1892def test_run_defaults(monkeypatch, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1893–1899why, one step back
1893 rv = {}
18941895 # Mocks werkzeug.serving.run_simple method1896 def run_simple_mock(*args, **kwargs):1897 rv["result"] = "running..."18981899 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1900why, one step back
1900 app.run()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1901–1903why, one step back
1901 assert rv["result"] == "running..."
19021903

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1904why, one step back
1904def test_run_server_port(monkeypatch, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1905–1907why, one step back
1905 rv = {}
19061907 # Mocks werkzeug.serving.run_simple method

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1908why, one step back
1908 def run_simple_mock(hostname, port, application, *args, **kwargs):

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1909why, one step back
1909 rv["result"] = f"running on {hostname}:{port} ..."

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1910–1912why, one step back
1910
1911 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1912 hostname, port = "localhost", 8000

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1913why, one step back
1913 app.run(hostname, port, debug=True)

apply pyupgradeDavid Lordbefore adoption524fd0b

line 1914why, one step back
1914 assert rv["result"] == f"running on {hostname}:{port} ..."

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1915–1917why, one step back
1915
19161917@pytest.mark.parametrize(

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1918why, one step back
1918 "host,port,server_name,expect_host,expect_port",

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1919why, one step back
1919 (

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

lines 1920–1926why, one step back
1920 (None, None, "pocoo.org:8080", "pocoo.org", 8080),
1921 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1922 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1923 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1924 ("localhost", 0, "localhost:8080", "localhost", 0),1925 (None, None, "localhost:8080", "localhost", 8080),1926 (None, None, "localhost:0", "localhost", 0),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1927–1928why, one step back
1927 ),
1928)

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

lines 1929–1931why, one step back
1929def test_run_from_config(
1930 monkeypatch, host, port, server_name, expect_host, expect_port, app1931):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1932–1934why, one step back
1932 def run_simple_mock(hostname, port, *args, **kwargs):
1933 assert hostname == expect_host1934 assert port == expect_port

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1935–1936why, one step back
1935
1936 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1937why, one step back
1937 app.config["SERVER_NAME"] = server_name

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1938why, one step back
1938 app.run(host, port)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1939–1940why, one step back
1939
1940

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1941why, one step back
1941def test_max_cookie_size(app, client, recwarn):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1942–1943why, one step back
1942 app.config["MAX_COOKIE_SIZE"] = 100
1943

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

lines 1944–1946why, one step back
1944 # outside app context, default to Werkzeug static value,
1945 # which is also the default config1946 response = flask.Response()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1947why, one step back
1947 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1948why, one step back
1948 assert response.max_cookie_size == default

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1949why, one step back
1949

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

lines 1950–1952why, one step back
1950 # inside app context, use app config
1951 with app.app_context():1952 assert flask.Response().max_cookie_size == 100

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1953–1957why, one step back
1953
1954 @app.route("/")1955 def index():1956 r = flask.Response("", status=204)1957 r.set_cookie("foo", "bar" * 100)

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1958why, one step back
1958 return r

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1959–1960why, one step back
1959
1960 client.get("/")

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

lines 1961–1962why, one step back
1961 assert len(recwarn) == 1
1962 w = recwarn.pop()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1963–1967why, one step back
1963 assert "cookie is too large" in str(w.message)
19641965 app.config["MAX_COOKIE_SIZE"] = 019661967 client.get("/")

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1968why, one step back
1968 assert len(recwarn) == 0