Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

2,010 lines · 54.0 KiB · Python

Last changed by

include samesite and secure when removing session cookie (#3726)Mathurshan Vimalesvaranbefore adoption22987b6

History of this file

Take it

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

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

line 1why, one step back
1import gc

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 2why, one step back
2import re

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

line 3why, one step back
3import sys

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 4–5why, one step back
4import time
5import uuid

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

line 6why, one step back
6import weakref

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 7why, one step back
7from datetime import datetime

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

line 8why, one step back
8from platform import python_implementation

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 9–12why, one step back
9from threading import Thread
1011import pytest12import werkzeug.serving

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

lines 13–15why, one step back
13from werkzeug.exceptions import BadRequest
14from werkzeug.exceptions import Forbidden15from werkzeug.exceptions import NotFound

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 16–21why, one step back
16from werkzeug.http import parse_date
17from werkzeug.routing import BuildError1819import flask2021

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

line 22why, one step back
22require_cpython_gc = pytest.mark.skipif(

update requirements (#3823)David Lordbefore adoption373f0dd

lines 23–24why, one step back
23 python_implementation() != "CPython",
24 reason="Requires CPython GC behavior",

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

lines 25–27why, one step back
25)
2627

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 28why, one step back
28def 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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 280why, one step back
280 class PrefixPathMiddleware:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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 #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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–324why, 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 cookie324

include samesite and secure when removing session cookie (#3726)Mathurshan Vimalesvaranbefore adoption22987b6

lines 325–337why, one step back
325 @app.route("/clear")
326 def clear():327 flask.session.pop("testing", None)328 return "Goodbye World"329330 rv = client.get("/clear", "http://www.example.com:8080/test/")331 cookie = rv.headers["set-cookie"].lower()332 assert "session=;" in cookie333 assert "domain=.example.com" in cookie334 assert "path=/" in cookie335 assert "secure" in cookie336 assert "samesite" in cookie337

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

line 338why, one step back
338

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 340–346why, one step back
340 @app.route("/")
341 def index():342 flask.session["testing"] = 42343 return "Hello World"344345 app.config.update(SESSION_COOKIE_SAMESITE="invalid")346

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 348–349why, one step back
348 client.get("/")
349

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 351–365why, one step back
351 rv = client.get("/")
352 cookie = rv.headers["set-cookie"].lower()353 assert "samesite" not in cookie354355 app.config.update(SESSION_COOKIE_SAMESITE="Strict")356 rv = client.get("/")357 cookie = rv.headers["set-cookie"].lower()358 assert "samesite=strict" in cookie359360 app.config.update(SESSION_COOKIE_SAMESITE="Lax")361 rv = client.get("/")362 cookie = rv.headers["set-cookie"].lower()363 assert "samesite=lax" in cookie364365

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 367–376why, one step back
367 app.config.update(SERVER_NAME="localhost:5000")
368369 @app.route("/")370 def index():371 flask.session["testing"] = 42372 return "testing"373374 rv = client.get("/", "http://localhost:5000/")375 assert "domain" not in rv.headers["set-cookie"].lower()376 w = recwarn.pop(UserWarning)

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

lines 378–379why, one step back
378
379

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 381–393why, one step back
381 app.config.update(SERVER_NAME="127.0.0.1:5000")
382383 @app.route("/")384 def index():385 flask.session["testing"] = 42386 return "testing"387388 rv = client.get("/", "http://127.0.0.1:5000/")389 assert "domain=127.0.0.1" in rv.headers["set-cookie"].lower()390 w = recwarn.pop(UserWarning)391 assert "cookie domain is an IP" in str(w.message)392393

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 396why, one step back
396

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 399–406why, one step back
399 assert e.value.args and "session is unavailable" in e.value.args[0]
400401 with app.test_request_context():402 assert flask.session.get("missing_key") is None403 expect_exception(flask.session.__setitem__, "foo", 42)404 expect_exception(flask.session.pop, "foo")405406

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 409–412why, one step back
409
410 @app.route("/")411 def index():412 flask.session["test"] = 42

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 414–417why, one step back
414 return ""
415416 @app.route("/test")417 def test():

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 423–427why, one step back
423 expires = parse_date(match.group())
424 expected = datetime.utcnow() + app.permanent_session_lifetime425 assert expires.year == expected.year426 assert expires.month == expected.month427 assert expires.day == expected.day

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

lines 428–431why, one step back
428
429 rv = client.get("/test")430 assert rv.data == b"True"431

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 432why, one step back
432 permanent = False

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 437–438why, one step back
437
438

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 442–452why, one step back
442 flask.session["foo"] = 42
443 return response444445 @app.route("/")446 def dump_session_contents():447 return repr(flask.session.get("foo"))448449 assert client.get("/").data == b"None"450 assert client.get("/").data == b"42"451452

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 456–470why, one step back
456
457 @app.route("/")458 def dump_session_contents():459 flask.session["t"] = (1, 2, 3)460 flask.session["b"] = b"\xff"461 flask.session["m"] = flask.Markup("<html>")462 flask.session["u"] = the_uuid463 flask.session["d"] = now464 flask.session["t_tag"] = {" t": "not-a-tuple"}465 flask.session["di_t_tag"] = {" t__": "not-a-tuple"}466 flask.session["di_tag"] = {" di": "not-a-dict"}467 return "", 204468469 with client:470 client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 472–483why, one step back
472 assert s["t"] == (1, 2, 3)
473 assert type(s["b"]) == bytes474 assert s["b"] == b"\xff"475 assert type(s["m"]) == flask.Markup476 assert s["m"] == flask.Markup("<html>")477 assert s["u"] == the_uuid478 assert s["d"] == now479 assert s["t_tag"] == {" t": "not-a-tuple"}480 assert s["di_t_tag"] == {" t__": "not-a-tuple"}481 assert s["di_tag"] == {" di": "not-a-dict"}482483

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 485–487why, one step back
485 is_permanent = True
486487 @app.route("/bump")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 499–504why, one step back
499 assert c.get("/bump").data == b"1"
500 assert c.get("/bump").data == b"2"501 assert c.get("/bump").data == b"3"502503 rv = c.get("/read")504 set_cookie = rv.headers.get("set-cookie")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 506–509why, one step back
506 assert rv.data == b"3"
507508 is_permanent = True509 app.config["SESSION_REFRESH_EACH_REQUEST"] = True

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 511–524why, one step back
511
512 is_permanent = True513 app.config["SESSION_REFRESH_EACH_REQUEST"] = False514 run_test(expect_header=False)515516 is_permanent = False517 app.config["SESSION_REFRESH_EACH_REQUEST"] = True518 run_test(expect_header=False)519520 is_permanent = False521 app.config["SESSION_REFRESH_EACH_REQUEST"] = False522 run_test(expect_header=False)523524

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 528–535why, one step back
528 flask.session["test"] = "test"
529 return ""530531 @app.route("/get")532 def get():533 return flask.session.get("test")534535 @app.route("/getitem")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 537–539why, one step back
537 return flask.session["test"]
538539 @app.route("/setdefault")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 545–550why, one step back
545 response = flask.Response()
546 response.vary.add("Cookie")547 flask.session["test"] = "test"548 return response549550 @app.route("/vary-header-set")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 552–557why, one step back
552 response = flask.Response()
553 response.vary.update(("Accept-Encoding", "Accept-Language"))554 flask.session["test"] = "test"555 return response556557 @app.route("/no-vary-header")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 559–561why, one step back
559 return ""
560561 def expect(path, header_value="Cookie"):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 563why, one step back
563

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 566–579why, one step back
566 assert len(rv.headers.get_all("Vary")) == 1
567 assert rv.headers["Vary"] == header_value568 else:569 assert "Vary" not in rv.headers570571 expect("/set")572 expect("/get")573 expect("/getitem")574 expect("/setdefault")575 expect("/vary-cookie-header-set")576 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")577 expect("/no-vary-header", None)578579

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 586–588why, one step back
586 assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]
587588

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 589–594why, one step back
589def test_extended_flashing(app):
590 # Be sure app.testing=True below, else tests can fail silently.591 #592 # Specifically, if app.testing is not set to True, the AssertionErrors593 # in the view functions will cause a 500 response to the test client594 # instead of propagating exceptions.

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

lines 595–597why, one step back
595
596 @app.route("/")597 def index():

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

lines 598–600why, one step back
598 flask.flash("Hello World")
599 flask.flash("Hello World", "error")600 flask.flash(flask.Markup("<em>Testing</em>"), "warning")

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

lines 601–604why, one step back
601 return ""
602603 @app.route("/test/")604 def test():

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

lines 607–609why, one step back
607 "Hello World",
608 "Hello World",609 flask.Markup("<em>Testing</em>"),

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

lines 610–613why, one step back
610 ]
611 return ""612613 @app.route("/test_with_categories/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 614–616why, one step back
614 def test_with_categories():
615 messages = flask.get_flashed_messages(with_categories=True)616 assert len(messages) == 3

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

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

lines 618–620why, one step back
618 ("message", "Hello World"),
619 ("error", "Hello World"),620 ("warning", flask.Markup("<em>Testing</em>")),

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

lines 621–624why, one step back
621 ]
622 return ""623624 @app.route("/test_filter/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 626–628why, one step back
626 messages = flask.get_flashed_messages(
627 category_filter=["message"], with_categories=True628 )

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

lines 630–632why, one step back
630 return ""
631632 @app.route("/test_filters/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 634–637why, one step back
634 messages = flask.get_flashed_messages(
635 category_filter=["message", "warning"], with_categories=True636 )637 assert list(messages) == [

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

lines 640–643why, one step back
640 ]
641 return ""642643 @app.route("/test_filters_without_returning_categories/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

lines 649–650why, one step back
649 return ""
650

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 652–669why, one step back
652
653 client = app.test_client()654 client.get("/")655 client.get("/test_with_categories/")656657 client = app.test_client()658 client.get("/")659 client.get("/test_filter/")660661 client = app.test_client()662 client.get("/")663 client.get("/test_filters/")664665 client = app.test_client()666 client.get("/")667 client.get("/test_filters_without_returning_categories/")668669

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 671–694why, one step back
671 evts = []
672673 @app.before_request674 def before_request():675 evts.append("before")676677 @app.after_request678 def after_request(response):679 response.data += b"|after"680 evts.append("after")681 return response682683 @app.route("/")684 def index():685 assert "before" in evts686 assert "after" not in evts687 return "request"688689 assert "after" not in evts690 rv = client.get("/").data691 assert "after" in evts692 assert rv == b"request|after"693694

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 696–698why, one step back
696 evts = []
697698 @app.before_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 701–702why, one step back
701
702 @app.before_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 703–705why, one step back
703 def before_request2():
704 evts.append(2)705 return "hello"

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

lines 706–707why, one step back
706
707 @app.before_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 708–710why, one step back
708 def before_request3():
709 evts.append(3)710 return "bye"

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

lines 711–714why, one step back
711
712 @app.route("/")713 def index():714 evts.append("index")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 716–718why, one step back
716
717 rv = client.get("/").data.strip()718 assert rv == b"hello"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 720–721why, one step back
720
721

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 728why, one step back
728 return response

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

lines 729–732why, one step back
729
730 return "Test"731732 resp = client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 734–736why, one step back
734 assert resp.headers["X-Foo"] == "a header"
735736

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 738–754why, one step back
738 called = []
739740 @app.teardown_request741 def teardown_request(exc):742 called.append(True)743 return "Ignored"744745 @app.route("/")746 def root():747 return "Response"748749 rv = client.get("/")750 assert rv.status_code == 200751 assert b"Response" in rv.data752 assert len(called) == 1753754

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 756–772why, one step back
756 called = []
757758 @app.teardown_request759 def teardown_request(exc):760 called.append(True)761 return "Ignored"762763 @app.route("/")764 def root():765 return "Response"766767 rv = client.get("/")768 assert rv.status_code == 200769 assert b"Response" in rv.data770 assert len(called) == 1771772

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 774–777why, one step back
774 called = []
775 app.testing = False776777 @app.teardown_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

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

line 786why, one step back
786 except Exception:

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

lines 787–789why, one step back
787 pass
788789 @app.teardown_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 791–797why, one step back
791 assert type(exc) == ZeroDivisionError
792 called.append(True)793 # This raises a new error and blows away sys.exc_info(), so we can794 # test that all teardown_requests get passed the same original795 # exception.796 try:797 raise TypeError()

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

line 798why, one step back
798 except Exception:

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

lines 799–801why, one step back
799 pass
800801 @app.route("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 803–807why, one step back
803 1 // 0
804805 rv = client.get("/")806 assert rv.status_code == 500807 assert b"Internal Server Error" in rv.data

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 809–810why, one step back
809
810

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 812–814why, one step back
812 called = []
813814 @app.before_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 817–818why, one step back
817
818 @app.before_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 821–822why, one step back
821
822 @app.after_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 825–827why, one step back
825 return response
826827 @app.after_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 830–832why, one step back
830 return response
831832 @app.teardown_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 835–836why, one step back
835
836 @app.teardown_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 839–845why, one step back
839
840 @app.route("/")841 def index():842 return "42"843844 rv = client.get("/")845 assert rv.data == b"42"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 847–848why, one step back
847
848

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 850–852why, one step back
850 app.testing = False
851852 @app.errorhandler(404)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 854–859why, one step back
854 return "not found", 404
855856 @app.errorhandler(500)857 def internal_server_error(e):858 return "internal server error", 500859

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 862–868why, one step back
862 return "forbidden", 403
863864 @app.route("/")865 def index():866 flask.abort(404)867868 @app.route("/error")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 870–872why, one step back
870 1 // 0
871872 @app.route("/forbidden")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 874–882why, one step back
874 flask.abort(403)
875876 rv = client.get("/")877 assert rv.status_code == 404878 assert rv.data == b"not found"879 rv = client.get("/error")880 assert rv.status_code == 500881 assert b"internal server error" == rv.data882 rv = client.get("/forbidden")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 884–886why, one step back
884 assert b"forbidden" == rv.data
885886

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 889–893why, one step back
889 app.register_error_handler(999, lambda e: ("999", 999))
890891 assert "Use a subclass" in exc_info.value.args[0]892893

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 895–905why, one step back
895 app.testing = False
896897 @app.errorhandler(500)898 def internal_server_error(e):899 return "internal server error", 500900901 @app.route("/")902 def broken_func():903 1 // 0904905 @app.after_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 908why, one step back
908 return resp

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

lines 909–914why, one step back
909
910 resp = client.get("/")911 assert resp.mimetype == "text/x-special"912 assert resp.data == b"internal server error"913914

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 916–919why, one step back
916 app.testing = False
917918 @app.route("/")919 def broken_func():

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 921why, one step back
921

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 923–924why, one step back
923 client.get("/")
924

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 925–927why, one step back
925 ctx = flask._request_ctx_stack.top
926 assert ctx.preserved927 assert type(ctx._preserved_exc) is KeyboardInterrupt

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

lines 928–929why, one step back
928
929

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 933–935why, one step back
933 flask.g.something = "value"
934935 @app.errorhandler(404)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 938–943why, one step back
938
939 rv = client.get("/")940 assert rv.status_code == 404941 assert rv.data == b"value"942943

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 946–947why, one step back
946 pass
947

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 948–950why, one step back
948 @app.errorhandler(MyException)
949 def handle_my_exception(e):950 assert isinstance(e, MyException)

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

lines 951–954why, one step back
951 return "42"
952953 @app.route("/")954 def index():

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 956–959why, one step back
956
957 assert client.get("/").data == b"42"958959

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 962–963why, one step back
962 pass
963

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 967–968why, one step back
967 return "banana"
968

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 971–972why, one step back
971 assert not isinstance(e, ForbiddenSubclass)
972 assert isinstance(e, Forbidden)

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

lines 973–975why, one step back
973 return "apple"
974975 @app.route("/1")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 976–977why, one step back
976 def index1():
977 raise ForbiddenSubclass()

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

lines 978–983why, one step back
978
979 @app.route("/2")980 def index2():981 flask.abort(403)982983 @app.route("/3")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 984–985why, one step back
984 def index3():
985 raise Forbidden()

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

lines 986–991why, one step back
986
987 assert client.get("/1").data == b"banana"988 assert client.get("/2").data == b"apple"989 assert client.get("/3").data == b"apple"990991

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 994–995why, one step back
994 pass
995

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 997–998why, one step back
997 pass
998

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1000–1001why, one step back
1000 pass
1001

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1004–1005why, one step back
1004 return "E2"
1005

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1008–1010why, one step back
1008 return "Exception"
10091010 @app.route("/E1")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1011–1012why, one step back
1011 def raise_e1():
1012 raise E1

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1015–1016why, one step back
1015 def raise_e3():
1016 raise E3

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

lines 1017–1024why, one step back
1017
1018 rv = client.get("/E1")1019 assert rv.data == b"Exception"10201021 rv = client.get("/E3")1022 assert rv.data == b"E2"10231024

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1026–1030why, one step back
1026 @app.route("/key")
1027 def fail():1028 flask.request.form["missing_key"]10291030 @app.route("/abort")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1033–1040why, one step back
1033
1034 rv = client.get("/key")1035 assert rv.status_code == 4001036 assert b"missing_key" not in rv.data1037 rv = client.get("/abort")1038 assert rv.status_code == 40010391040 app.debug = True

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1044–1049why, one step back
1044 assert "missing_key" in e.value.get_description()
1045 rv = client.get("/abort")1046 assert rv.status_code == 40010471048 app.debug = False1049 app.config["TRAP_BAD_REQUEST_ERRORS"] = True

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1053–1055why, one step back
1053 client.get("/abort")
10541055

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1057–1062why, one step back
1057 app.config["TRAP_HTTP_EXCEPTIONS"] = True
10581059 @app.route("/fail")1060 def fail():1061 flask.abort(404)1062

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1064–1066why, one step back
1064 client.get("/fail")
10651066

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1068–1071why, one step back
1068 app.testing = False
10691070 @app.before_request1071 def before_request():

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

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

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

lines 1073–1076why, one step back
1073 1 // 0
10741075 @app.after_request1076 def after_request(response):

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

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

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

lines 1078–1088why, one step back
1078 1 // 0
1079 return response10801081 @app.route("/")1082 def index():1083 return "Foo"10841085 @app.errorhandler(500)1086 def internal_server_error(e):1087 return "Hello Server Error", 5001088

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

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1092–1094why, one step back
1092 assert rv.data == b"Hello Server Error"
10931094

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1097–1103why, one step back
1097
1098 app.debug = True10991100 @app.route("/fail", methods=["POST"])1101 def index():1102 return flask.request.files["foo"].filename1103

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 1107why, one step back
1107 with client:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

lines 1112–1113why, one step back
1112
1113

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1125–1131why, one step back
1125 return (
1126 "Meh",1127 400,1128 {"X-Foo": "Testing", "Content-Type": "text/plain; charset=utf-8"},1129 )11301131 @app.route("/text_headers")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1137–1139why, one step back
1137 return "Hi, status!", 400
11381139 @app.route("/response_headers")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 1141why, one step back
1141 return (

Merge pull request #3684 from MLH-Fellowship/3628-duplicate-headersDavid Lordbefore adoption2fa8eb3

lines 1142–1145why, one step back
1142 flask.Response(
1143 "Hello world", 404, {"Content-Type": "text/html", "X-Foo": "Baz"}1144 ),1145 {"Content-Type": "text/plain", "X-Foo": "Bar", "X-Bar": "Foo"},

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

lines 1146–1148why, one step back
1146 )
11471148 @app.route("/response_status")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1150–1152why, one step back
1150 return app.response_class("Hello world", 400), 500
11511152 @app.route("/wsgi")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1153–1154why, one step back
1153 def from_wsgi():
1154 return NotFound()

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

line 1155why, one step back
1155

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

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

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

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

line 1159why, one step back
1159

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1162why, one step back
1162

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

lines 1163–1181why, one step back
1163 rv = client.get("/full_tuple")
1164 assert rv.data == b"Meh"1165 assert rv.headers["X-Foo"] == "Testing"1166 assert rv.status_code == 4001167 assert rv.mimetype == "text/plain"11681169 rv = client.get("/text_headers")1170 assert rv.data == b"Hello"1171 assert rv.headers["X-Foo"] == "Test"1172 assert rv.status_code == 2001173 assert rv.mimetype == "text/plain"11741175 rv = client.get("/text_status")1176 assert rv.data == b"Hi, status!"1177 assert rv.status_code == 4001178 assert rv.mimetype == "text/html"11791180 rv = client.get("/response_headers")1181 assert rv.data == b"Hello world"

Merge pull request #3684 from MLH-Fellowship/3628-duplicate-headersDavid Lordbefore adoption2fa8eb3

lines 1182–1183why, one step back
1182 assert rv.content_type == "text/plain"
1183 assert rv.headers.getlist("X-Foo") == ["Bar"]

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

lines 1184–1193why, one step back
1184 assert rv.headers["X-Bar"] == "Foo"
1185 assert rv.status_code == 40411861187 rv = client.get("/response_status")1188 assert rv.data == b"Hello world"1189 assert rv.status_code == 50011901191 rv = client.get("/wsgi")1192 assert b"Not Found" in rv.data1193 assert rv.status_code == 404

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1194why, one step back
1194

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

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

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

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

lines 1198–1199why, one step back
1198
1199

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1201–1204why, one step back
1201 app = flask.Flask(__name__)
1202 app.testing = True12031204 @app.route("/none")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1206–1208why, one step back
1206 pass
12071208 @app.route("/small_tuple")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1210–1212why, one step back
1210 return ("Hello",)
12111212 @app.route("/large_tuple")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1217–1218why, one step back
1217 def from_bad_type():
1218 return True

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1221–1222why, one step back
1221 def from_bad_wsgi():
1222 return lambda: None

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

lines 1223–1227why, one step back
1223
1224 c = app.test_client()12251226 with pytest.raises(TypeError) as e:1227 c.get("/none")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

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

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

lines 1230–1232why, one step back
1230
1231 with pytest.raises(TypeError) as e:1232 c.get("/small_tuple")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

lines 1234–1238why, one step back
1234
1235 pytest.raises(TypeError, c.get, "/large_tuple")12361237 with pytest.raises(TypeError) as e:1238 c.get("/bad_type")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

line 1240why, one step back
1240

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

lines 1241–1243why, one step back
1241 pytest.raises(TypeError, c.get, "/bad_wsgi")
12421243

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1246–1260why, one step back
1246 assert rv.status_code == 200
1247 assert rv.data == b""1248 assert rv.mimetype == "text/html"12491250 rv = flask.make_response("Awesome")1251 assert rv.status_code == 2001252 assert rv.data == b"Awesome"1253 assert rv.mimetype == "text/html"12541255 rv = flask.make_response("W00t", 404)1256 assert rv.status_code == 4041257 assert rv.data == b"W00t"1258 assert rv.mimetype == "text/html"12591260

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1265–1281why, one step back
1265 assert rv.mimetype == "application/json"
12661267 rv = flask.make_response(flask.Response(""), 400)1268 assert rv.status_code == 4001269 assert rv.data == b""1270 assert rv.mimetype == "text/html"12711272 rv = flask.make_response(1273 flask.Response("", headers={"Content-Type": "text/html"}),1274 400,1275 [("X-Foo", "bar")],1276 )1277 assert rv.status_code == 4001278 assert rv.headers["Content-Type"] == "text/html"1279 assert rv.headers["X-Foo"] == "bar"12801281

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1289–1290why, one step back
1289
1290

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 1294why, one step back
1294 pretty_response = (

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1296–1298why, one step back
1296 )
12971298 rv = flask.make_response(flask.jsonify(compressed_msg), 200)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1300–1301why, one step back
1300
1301

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1303–1307why, one step back
1303 app.config.update({"JSONIFY_MIMETYPE": "application/vnd.api+json"})
1304 msg = {"msg": {"submsg": "W00t"}}1305 rv = flask.make_response(flask.jsonify(msg), 200)1306 assert rv.mimetype == "application/vnd.api+json"1307

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

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

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

line 1312why, one step back
1312

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

lines 1313–1316why, one step back
1313 Data = make_dataclass("Data", [("name", str)])
1314 value = flask.json.dumps(Data("Flask"), app=app)1315 value = flask.json.loads(value, app=app)1316 assert value == {"name": "Flask"}

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

line 1317why, one step back
1317

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

line 1318why, one step back
1318

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1320–1324why, one step back
1320 with pytest.raises(TypeError) as e:
1321 flask.jsonify("fake args", kwargs="fake")1322 assert "behavior undefined" in str(e.value)13231324

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1328–1336why, one step back
1328 pass
13291330 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1331 assert (1332 flask.url_for("hello", name="test x", _external=True)1333 == "http://localhost/hello/test%20x"1334 )13351336

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1339–1341why, one step back
1339 with app.test_request_context():
1340 pytest.raises(BuildError, flask.url_for, "spam")1341

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

line 1343why, one step back
1343 try:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1346–1347why, one step back
1346 except BuildError as err:
1347 error = err

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1350why, one step back
1350 except RuntimeError:

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1356–1357why, one step back
1356 return "/test_handler/"
1357

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1359–1362why, one step back
1359 with app.test_request_context():
1360 assert flask.url_for("spam") == "/test_handler/"13611362

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1363–1366why, one step back
1363def test_build_error_handler_reraise(app):
1364 # Test a custom handler which reraises the BuildError1365 def handler_raises_build_error(error, endpoint, values):1366 raise error

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

line 1367why, one step back
1367

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1369–1373why, one step back
1369
1370 with app.test_request_context():1371 pytest.raises(BuildError, flask.url_for, "not.existing")13721373

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

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

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

lines 1378–1388why, one step back
1378 "_external": False,
1379 "_anchor": None,1380 "_method": None,1381 "_scheme": None,1382 }1383 return "handled"13841385 with app.test_request_context():1386 flask.url_for("/")13871388

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1389why, one step back
1389def test_static_files(app, client):

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

lines 1390–1397why, one step back
1390 rv = client.get("/static/index.html")
1391 assert rv.status_code == 2001392 assert rv.data.strip() == b"<h1>Hello World!</h1>"1393 with app.test_request_context():1394 assert flask.url_for("static", filename="index.html") == "/static/index.html"1395 rv.close()13961397

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1398why, one step back
1398def test_static_url_path():

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

lines 1399–1408why, one step back
1399 app = flask.Flask(__name__, static_url_path="/foo")
1400 app.testing = True1401 rv = app.test_client().get("/foo/index.html")1402 assert rv.status_code == 2001403 rv.close()14041405 with app.test_request_context():1406 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14071408

Merge pull request #3182 from qil026/issue-3134-url-joinDavid Lordbefore adoptiondbd3840

lines 1409–1419why, one step back
1409def test_static_url_path_with_ending_slash():
1410 app = flask.Flask(__name__, static_url_path="/foo/")1411 app.testing = True1412 rv = app.test_client().get("/foo/index.html")1413 assert rv.status_code == 2001414 rv.close()14151416 with app.test_request_context():1417 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14181419

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

line 1420why, one step back
1420def test_static_url_empty_path(app):

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

lines 1421–1422why, one step back
1421 app = flask.Flask(__name__, static_folder="", static_url_path="")
1422 rv = app.test_client().open("/static/index.html", method="GET")

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1423–1427why, one step back
1423 assert rv.status_code == 200
1424 rv.close()142514261427def test_static_url_empty_path_default(app):

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

lines 1428–1429why, one step back
1428 app = flask.Flask(__name__, static_folder="")
1429 rv = app.test_client().open("/static/index.html", method="GET")

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1430–1433why, one step back
1430 assert rv.status_code == 200
1431 rv.close()14321433

Merge pull request #3579 from jab/pathlib-for-static_folderJoshua Bronsonbefore adoptioncf5b1d0

lines 1434–1443why, one step back
1434@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python >= 3.6")
1435def test_static_folder_with_pathlib_path(app):1436 from pathlib import Path14371438 app = flask.Flask(__name__, static_folder=Path("static"))1439 rv = app.test_client().open("/static/index.html", method="GET")1440 assert rv.status_code == 2001441 rv.close()14421443

Merge remote-tracking branch 'origin/1.1.x'David Lordbefore adoption64ba434

lines 1444–1454why, one step back
1444def test_static_folder_with_ending_slash():
1445 app = flask.Flask(__name__, static_folder="static/")14461447 @app.route("/<path:path>")1448 def catch_all(path):1449 return path14501451 rv = app.test_client().get("/catch/all")1452 assert rv.data == b"catch/all"14531454

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1455why, one step back
1455def test_static_route_with_host_matching():

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

lines 1456–1463why, one step back
1456 app = flask.Flask(__name__, host_matching=True, static_host="example.com")
1457 c = app.test_client()1458 rv = c.get("http://example.com/static/index.html")1459 assert rv.status_code == 2001460 rv.close()1461 with app.test_request_context():1462 rv = flask.url_for("static", filename="index.html", _external=True)1463 assert rv == "http://example.com/static/index.html"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1464why, one step back
1464 # Providing static_host without host_matching=True should error.

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

lines 1465–1466why, one step back
1465 with pytest.raises(Exception):
1466 flask.Flask(__name__, static_host="example.com")

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

lines 1467–1468why, one step back
1467 # Providing host_matching=True with static_folder
1468 # but without static_host should error.

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

line 1469why, one step back
1469 with pytest.raises(Exception):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1470why, one step back
1470 flask.Flask(__name__, host_matching=True)

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

lines 1471–1472why, one step back
1471 # Providing host_matching=True without static_host
1472 # but with static_folder=None should not error.

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1473why, one step back
1473 flask.Flask(__name__, host_matching=True, static_folder=None)

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

lines 1474–1475why, one step back
1474
1475

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1476why, one step back
1476def test_request_locals():

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

line 1477why, one step back
1477 assert repr(flask.g) == "<LocalProxy unbound>"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1478why, one step back
1478 assert not flask.g

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

lines 1479–1480why, one step back
1479
1480

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1481why, one step back
1481def test_server_name_subdomain():

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

lines 1482–1486why, one step back
1482 app = flask.Flask(__name__, subdomain_matching=True)
1483 client = app.test_client()14841485 @app.route("/")1486 def index():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1487why, one step back
1487 return "default"

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

lines 1488–1489why, one step back
1488
1489 @app.route("/", subdomain="foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1490why, one step back
1490 def subdomain():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1491why, one step back
1491 return "subdomain"

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

line 1492why, one step back
1492

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1493why, one step back
1493 app.config["SERVER_NAME"] = "dev.local:5000"

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

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

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1495why, one step back
1495 assert rv.data == b"default"

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

line 1496why, one step back
1496

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1497–1498why, one step back
1497 rv = client.get("/", "http://dev.local:5000")
1498 assert rv.data == b"default"

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

line 1499why, one step back
1499

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1500–1501why, one step back
1500 rv = client.get("/", "https://dev.local:5000")
1501 assert rv.data == b"default"

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

line 1502why, one step back
1502

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1503–1504why, one step back
1503 app.config["SERVER_NAME"] = "dev.local:443"
1504 rv = client.get("/", "https://dev.local")

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

line 1505why, one step back
1505

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1506–1508why, one step back
1506 # Werkzeug 1.0 fixes matching https scheme with 443 port
1507 if rv.status_code != 404:1508 assert rv.data == b"default"

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

line 1509why, one step back
1509

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1510–1515why, one step back
1510 app.config["SERVER_NAME"] = "dev.local"
1511 rv = client.get("/", "https://dev.local")1512 assert rv.data == b"default"15131514 # suppress Werkzeug 1.0 warning about name mismatch1515 with pytest.warns(None):

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

lines 1516–1518why, one step back
1516 rv = client.get("/", "http://foo.localhost")
1517 assert rv.status_code == 4041518

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1519–1520why, one step back
1519 rv = client.get("/", "http://foo.dev.local")
1520 assert rv.data == b"subdomain"

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

lines 1521–1522why, one step back
1521
1522

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1523–1524why, one step back
1523def test_exception_propagation(app, client):
1524 def apprunner(config_key):

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

lines 1525–1528why, one step back
1525 @app.route("/")
1526 def index():1527 1 // 01528

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1529–1531why, one step back
1529 if config_key is not None:
1530 app.config[config_key] = True1531 with pytest.raises(Exception):

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

lines 1532–1535why, one step back
1532 client.get("/")
1533 else:1534 assert client.get("/").status_code == 5001535

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1536–1539why, one step back
1536 # we have to run this test in an isolated thread because if the
1537 # debug flag is set to true and an exception happens the context is1538 # not torn down. This causes other tests that run after this fail1539 # when they expect no exception on the stack.

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

line 1540why, one step back
1540 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1541–1543why, one step back
1541 t = Thread(target=apprunner, args=(config_key,))
1542 t.start()1543 t.join()

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

lines 1544–1560why, one step back
1544
15451546@pytest.mark.parametrize("debug", [True, False])1547@pytest.mark.parametrize("use_debugger", [True, False])1548@pytest.mark.parametrize("use_reloader", [True, False])1549@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1550def test_werkzeug_passthrough_errors(1551 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1552):1553 rv = {}15541555 # Mocks werkzeug.serving.run_simple method1556 def run_simple_mock(*args, **kwargs):1557 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15581559 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1560 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptions

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1561why, one step back
1561 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)

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

lines 1562–1563why, one step back
1562
1563

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1564why, one step back
1564def test_max_content_length(app, client):

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

lines 1565–1567why, one step back
1565 app.config["MAX_CONTENT_LENGTH"] = 64
15661567 @app.before_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1568why, one step back
1568 def always_first():

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

line 1569why, one step back
1569 flask.request.form["myfile"]

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

line 1570why, one step back
1570 AssertionError()

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

lines 1571–1572why, one step back
1571
1572 @app.route("/accept", methods=["POST"])

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1573why, one step back
1573 def accept_file():

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

line 1574why, one step back
1574 flask.request.form["myfile"]

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

line 1575why, one step back
1575 AssertionError()

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

line 1576why, one step back
1576

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1577–1578why, one step back
1577 @app.errorhandler(413)
1578 def catcher(error):

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

lines 1579–1584why, one step back
1579 return "42"
15801581 rv = client.post("/accept", data={"myfile": "foo" * 100})1582 assert rv.data == b"42"15831584

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1585–1587why, one step back
1585def test_url_processors(app, client):
1586 @app.url_defaults1587 def add_language_code(endpoint, values):

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

lines 1588–1592why, one step back
1588 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(
1589 endpoint, "lang_code"1590 ):1591 values.setdefault("lang_code", flask.g.lang_code)1592

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1593–1594why, one step back
1593 @app.url_value_preprocessor
1594 def pull_lang_code(endpoint, values):

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

lines 1595–1601why, one step back
1595 flask.g.lang_code = values.pop("lang_code", None)
15961597 @app.route("/<lang_code>/")1598 def index():1599 return flask.url_for("about")16001601 @app.route("/<lang_code>/about")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1602why, one step back
1602 def about():

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

lines 1603–1605why, one step back
1603 return flask.url_for("something_else")
16041605 @app.route("/foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1606why, one step back
1606 def something_else():

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

lines 1607–1613why, one step back
1607 return flask.url_for("about", lang_code="en")
16081609 assert client.get("/de/").data == b"/de/about"1610 assert client.get("/de/about").data == b"/foo"1611 assert client.get("/foo").data == b"/en/about"16121613

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1614why, one step back
1614def test_inject_blueprint_url_defaults(app):

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

lines 1615–1616why, one step back
1615 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")
1616

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1617–1618why, one step back
1617 @bp.url_defaults
1618 def bp_defaults(endpoint, values):

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

lines 1619–1621why, one step back
1619 values["page"] = "login"
16201621 @bp.route("/<page>")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1622why, one step back
1622 def view(page):

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

lines 1623–1624why, one step back
1623 pass
1624

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1625why, one step back
1625 app.register_blueprint(bp)

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

line 1626why, one step back
1626

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1627why, one step back
1627 values = dict()

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

lines 1628–1629why, one step back
1628 app.inject_url_defaults("foo.bar.baz.view", values)
1629 expected = dict(page="login")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1630why, one step back
1630 assert values == expected

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

lines 1631–1634why, one step back
1631
1632 with app.test_request_context("/somepage"):1633 url = flask.url_for("foo.bar.baz.view")1634 expected = "/login"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1635why, one step back
1635 assert url == expected

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

lines 1636–1637why, one step back
1636
1637

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1638why, one step back
1638def test_nonascii_pathinfo(app, client):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1639why, one step back
1639 @app.route("/киртест")

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

lines 1640–1642why, one step back
1640 def index():
1641 return "Hello World!"1642

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1643why, one step back
1643 rv = client.get("/киртест")

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

lines 1644–1646why, one step back
1644 assert rv.data == b"Hello World!"
16451646

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1647why, one step back
1647def test_debug_mode_complains_after_first_request(app, client):

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

lines 1648–1653why, one step back
1648 app.debug = True
16491650 @app.route("/")1651 def index():1652 return "Awesome"1653

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1654why, one step back
1654 assert not app.got_first_request

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

line 1655why, one step back
1655 assert client.get("/").data == b"Awesome"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1656why, one step back
1656 with pytest.raises(AssertionError) as e:

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

lines 1657–1658why, one step back
1657
1658 @app.route("/foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1659why, one step back
1659 def broken():

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

lines 1660–1661why, one step back
1660 return "Meh"
1661

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1662why, one step back
1662 assert "A setup function was called" in str(e.value)

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

lines 1663–1666why, one step back
1663
1664 app.debug = False16651666 @app.route("/foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1667why, one step back
1667 def working():

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

lines 1668–1673why, one step back
1668 return "Meh"
16691670 assert client.get("/foo").data == b"Meh"1671 assert app.got_first_request16721673

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1674why, one step back
1674def test_before_first_request_functions(app, client):

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

lines 1675–1687why, one step back
1675 got = []
16761677 @app.before_first_request1678 def foo():1679 got.append(42)16801681 client.get("/")1682 assert got == [42]1683 client.get("/")1684 assert got == [42]1685 assert app.got_first_request16861687

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1688why, one step back
1688def test_before_first_request_functions_concurrent(app, client):

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

lines 1689–1692why, one step back
1689 got = []
16901691 @app.before_first_request1692 def foo():

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1693why, one step back
1693 time.sleep(0.2)

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

lines 1694–1695why, one step back
1694 got.append(42)
1695

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1696why, one step back
1696 def get_and_assert():

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

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

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1698why, one step back
1698 assert got == [42]

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

line 1699why, one step back
1699

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1700–1703why, one step back
1700 t = Thread(target=get_and_assert)
1701 t.start()1702 get_and_assert()1703 t.join()

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

lines 1704–1706why, one step back
1704 assert app.got_first_request
17051706

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1707why, one step back
1707def test_routing_redirect_debugging(app, client):

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

lines 1708–1714why, one step back
1708 app.debug = True
17091710 @app.route("/foo/", methods=["GET", "POST"])1711 def foo():1712 return "success"17131714 with client:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1715why, one step back
1715 with pytest.raises(AssertionError) as e:

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

line 1716why, one step back
1716 client.post("/foo", data={})

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1717why, one step back
1717 assert "http://localhost/foo/" in str(e.value)

Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b

line 1718why, one step back
1718 assert "Make sure to directly send your POST-request to this URL" in str(

Merge branch '1.0.x'David Lordbefore adoptionb05a685

lines 1719–1720why, one step back
1719 e.value
1720 )

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

lines 1721–1730why, one step back
1721
1722 rv = client.get("/foo", data={}, follow_redirects=True)1723 assert rv.data == b"success"17241725 app.debug = False1726 with client:1727 rv = client.post("/foo", data={}, follow_redirects=True)1728 assert rv.data == b"success"17291730

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1731why, one step back
1731def test_route_decorator_custom_endpoint(app, client):

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

lines 1732–1738why, one step back
1732 app.debug = True
17331734 @app.route("/foo/")1735 def foo():1736 return flask.request.endpoint17371738 @app.route("/bar/", endpoint="bar")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1739why, one step back
1739 def for_bar():

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

lines 1740–1742why, one step back
1740 return flask.request.endpoint
17411742 @app.route("/bar/123", endpoint="123")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1743why, one step back
1743 def for_bar_foo():

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

lines 1744–1755why, one step back
1744 return flask.request.endpoint
17451746 with app.test_request_context():1747 assert flask.url_for("foo") == "/foo/"1748 assert flask.url_for("bar") == "/bar/"1749 assert flask.url_for("123") == "/bar/123"17501751 assert client.get("/foo/").data == b"foo"1752 assert client.get("/bar/").data == b"bar"1753 assert client.get("/bar/123").data == b"123"17541755

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1756why, one step back
1756def test_preserve_only_once(app, client):

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

lines 1757–1762why, one step back
1757 app.debug = True
17581759 @app.route("/fail")1760 def fail_func():1761 1 // 01762

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

line 1763why, one step back
1763 for _x in range(3):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1764why, one step back
1764 with pytest.raises(ZeroDivisionError):

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

lines 1765–1766why, one step back
1765 client.get("/fail")
1766

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1767–1772why, one step back
1767 assert flask._request_ctx_stack.top is not None
1768 assert flask._app_ctx_stack.top is not None1769 # implicit appctx disappears too1770 flask._request_ctx_stack.top.pop()1771 assert flask._request_ctx_stack.top is None1772 assert flask._app_ctx_stack.top is None

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

lines 1773–1774why, one step back
1773
1774

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1775why, one step back
1775def test_preserve_remembers_exception(app, client):

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

line 1776why, one step back
1776 app.debug = True

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1777why, one step back
1777 errors = []

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

lines 1778–1783why, one step back
1778
1779 @app.route("/fail")1780 def fail_func():1781 1 // 017821783 @app.route("/success")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1784why, one step back
1784 def success_func():

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

lines 1785–1787why, one step back
1785 return "Okay"
17861787 @app.teardown_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1788–1789why, one step back
1788 def teardown_handler(exc):
1789 errors.append(exc)

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

line 1790why, one step back
1790

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1791–1792why, one step back
1791 # After this failure we did not yet call the teardown handler
1792 with pytest.raises(ZeroDivisionError):

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

line 1793why, one step back
1793 client.get("/fail")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1794why, one step back
1794 assert errors == []

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

line 1795why, one step back
1795

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1796why, one step back
1796 # But this request triggers it, and it's an error

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

line 1797why, one step back
1797 client.get("/success")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1798–1799why, one step back
1798 assert len(errors) == 2
1799 assert isinstance(errors[0], ZeroDivisionError)

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

line 1800why, one step back
1800

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1801why, one step back
1801 # At this point another request does nothing.

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

line 1802why, one step back
1802 client.get("/success")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1803–1804why, one step back
1803 assert len(errors) == 3
1804 assert errors[1] is None

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

lines 1805–1806why, one step back
1805
1806

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1807why, one step back
1807def test_get_method_on_g(app_ctx):

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

lines 1808–1809why, one step back
1808 assert flask.g.get("x") is None
1809 assert flask.g.get("x", 11) == 11

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1810why, one step back
1810 flask.g.x = 42

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

line 1811why, one step back
1811 assert flask.g.get("x") == 42

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1812why, one step back
1812 assert flask.g.x == 42

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

lines 1813–1814why, one step back
1813
1814

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1815–1817why, one step back
1815def test_g_iteration_protocol(app_ctx):
1816 flask.g.foo = 231817 flask.g.bar = 42

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

lines 1818–1822why, one step back
1818 assert "foo" in flask.g
1819 assert "foos" not in flask.g1820 assert sorted(flask.g) == ["bar", "foo"]18211822

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1823why, one step back
1823def test_subdomain_basic_support():

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

lines 1824–1828why, one step back
1824 app = flask.Flask(__name__, subdomain_matching=True)
1825 app.config["SERVER_NAME"] = "localhost.localdomain"1826 client = app.test_client()18271828 @app.route("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1829why, one step back
1829 def normal_index():

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

lines 1830–1832why, one step back
1830 return "normal index"
18311832 @app.route("/", subdomain="test")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1833why, one step back
1833 def test_index():

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

lines 1834–1842why, one step back
1834 return "test index"
18351836 rv = client.get("/", "http://localhost.localdomain/")1837 assert rv.data == b"normal index"18381839 rv = client.get("/", "http://test.localhost.localdomain/")1840 assert rv.data == b"test index"18411842

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1843why, one step back
1843def test_subdomain_matching():

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

lines 1844–1849why, one step back
1844 app = flask.Flask(__name__, subdomain_matching=True)
1845 client = app.test_client()1846 app.config["SERVER_NAME"] = "localhost.localdomain"18471848 @app.route("/", subdomain="<user>")1849 def index(user):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1850why, one step back
1850 return f"index for {user}"

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

lines 1851–1855why, one step back
1851
1852 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1853 assert rv.data == b"index for mitsuhiko"18541855

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1856why, one step back
1856def test_subdomain_matching_with_ports():

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

lines 1857–1862why, one step back
1857 app = flask.Flask(__name__, subdomain_matching=True)
1858 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1859 client = app.test_client()18601861 @app.route("/", subdomain="<user>")1862 def index(user):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1863why, one step back
1863 return f"index for {user}"

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

lines 1864–1869why, one step back
1864
1865 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1866 assert rv.data == b"index for mitsuhiko"186718681869@pytest.mark.parametrize("matching", (False, True))

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1870–1871why, one step back
1870def test_subdomain_matching_other_name(matching):
1871 app = flask.Flask(__name__, subdomain_matching=matching)

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

lines 1872–1878why, one step back
1872 app.config["SERVER_NAME"] = "localhost.localdomain:3000"
1873 client = app.test_client()18741875 @app.route("/")1876 def index():1877 return "", 2041878

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1879–1883why, one step back
1879 # suppress Werkzeug 0.15 warning about name mismatch
1880 with pytest.warns(None):1881 # ip address can't match name1882 rv = client.get("/", "http://127.0.0.1:3000/")1883 assert rv.status_code == 404 if matching else 204

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

line 1884why, one step back
1884

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1885why, one step back
1885 # allow all subdomains if matching is disabled

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

lines 1886–1889why, one step back
1886 rv = client.get("/", "http://www.localhost.localdomain:3000/")
1887 assert rv.status_code == 404 if matching else 20418881889

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1890why, one step back
1890def test_multi_route_rules(app, client):

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

lines 1891–1893why, one step back
1891 @app.route("/")
1892 @app.route("/<test>/")1893 def index(test="a"):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1894why, one step back
1894 return test

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

lines 1895–1901why, one step back
1895
1896 rv = client.open("/")1897 assert rv.data == b"a"1898 rv = client.open("/b/")1899 assert rv.data == b"b"19001901

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1902why, one step back
1902def test_multi_route_class_views(app, client):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1903why, one step back
1903 class View:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1904why, one step back
1904 def __init__(self, app):

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

lines 1905–1908why, one step back
1905 app.add_url_rule("/", "index", self.index)
1906 app.add_url_rule("/<test>/", "index", self.index)19071908 def index(self, test="a"):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1909why, one step back
1909 return test

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

line 1910why, one step back
1910

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1911why, one step back
1911 _ = View(app)

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

lines 1912–1917why, one step back
1912 rv = client.open("/")
1913 assert rv.data == b"a"1914 rv = client.open("/b/")1915 assert rv.data == b"b"19161917

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1918why, one step back
1918def test_run_defaults(monkeypatch, app):

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

lines 1919–1925why, one step back
1919 rv = {}
19201921 # Mocks werkzeug.serving.run_simple method1922 def run_simple_mock(*args, **kwargs):1923 rv["result"] = "running..."19241925 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1926why, one step back
1926 app.run()

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

lines 1927–1929why, one step back
1927 assert rv["result"] == "running..."
19281929

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1930why, one step back
1930def test_run_server_port(monkeypatch, app):

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

lines 1931–1933why, one step back
1931 rv = {}
19321933 # Mocks werkzeug.serving.run_simple method

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1934why, one step back
1934 def run_simple_mock(hostname, port, application, *args, **kwargs):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1935why, one step back
1935 rv["result"] = f"running on {hostname}:{port} ..."

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

lines 1936–1938why, one step back
1936
1937 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1938 hostname, port = "localhost", 8000

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1939why, one step back
1939 app.run(hostname, port, debug=True)

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1940why, one step back
1940 assert rv["result"] == f"running on {hostname}:{port} ..."

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

lines 1941–1943why, one step back
1941
19421943@pytest.mark.parametrize(

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1944why, one step back
1944 "host,port,server_name,expect_host,expect_port",

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

line 1945why, one step back
1945 (

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

lines 1946–1952why, one step back
1946 (None, None, "pocoo.org:8080", "pocoo.org", 8080),
1947 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1948 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1949 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1950 ("localhost", 0, "localhost:8080", "localhost", 0),1951 (None, None, "localhost:8080", "localhost", 8080),1952 (None, None, "localhost:0", "localhost", 0),

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

lines 1953–1954why, one step back
1953 ),
1954)

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

lines 1955–1957why, one step back
1955def test_run_from_config(
1956 monkeypatch, host, port, server_name, expect_host, expect_port, app1957):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1958–1960why, one step back
1958 def run_simple_mock(hostname, port, *args, **kwargs):
1959 assert hostname == expect_host1960 assert port == expect_port

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

lines 1961–1962why, one step back
1961
1962 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1963why, one step back
1963 app.config["SERVER_NAME"] = server_name

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1964why, one step back
1964 app.run(host, port)

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

lines 1965–1966why, one step back
1965
1966

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1967why, one step back
1967def test_max_cookie_size(app, client, recwarn):

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

lines 1968–1969why, one step back
1968 app.config["MAX_COOKIE_SIZE"] = 100
1969

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1970–1972why, one step back
1970 # outside app context, default to Werkzeug static value,
1971 # which is also the default config1972 response = flask.Response()

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

line 1973why, one step back
1973 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1974why, one step back
1974 assert response.max_cookie_size == default

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

line 1975why, one step back
1975

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1976–1978why, one step back
1976 # inside app context, use app config
1977 with app.app_context():1978 assert flask.Response().max_cookie_size == 100

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

lines 1979–1983why, one step back
1979
1980 @app.route("/")1981 def index():1982 r = flask.Response("", status=204)1983 r.set_cookie("foo", "bar" * 100)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1984why, one step back
1984 return r

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

lines 1985–1986why, one step back
1985
1986 client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1987–1988why, one step back
1987 assert len(recwarn) == 1
1988 w = recwarn.pop()

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

lines 1989–1993why, one step back
1989 assert "cookie is too large" in str(w.message)
19901991 app.config["MAX_COOKIE_SIZE"] = 019921993 client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1994why, one step back
1994 assert len(recwarn) == 0

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

lines 1995–2010why, one step back
1995
19961997@require_cpython_gc1998def test_app_freed_on_zero_refcount():1999 # A Flask instance should not create a reference cycle that prevents CPython2000 # from freeing it when all external references to it are released (see #3761).

The first 2,000 of 2,010 lines.