Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

1,996 lines · 53.6 KiB · Python

Last changed by

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

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

lines 22–26why, one step back
22require_cpython_gc = pytest.mark.skipif(
23 python_implementation() != "CPython", reason="Requires CPython GC behavior",24)2526

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

line 27why, one step back
27def test_options_work(app, client):

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

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

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

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

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

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

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

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

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

lines 44–49why, one step back
44 return "Aha!"
4546 rv = client.open("/", method="OPTIONS")47 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]4849

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 73–79why, one step back
73 def index():
74 return flask.request.method7576 def more():77 return flask.request.method7879 app.add_url_rule("/", view_func=index, provide_automatic_options=False)

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

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

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

lines 81–91why, one step back
81 "/more",
82 view_func=more,83 methods=["GET", "POST"],84 provide_automatic_options=False,85 )86 assert client.get("/").data == b"GET"8788 rv = client.post("/")89 assert rv.status_code == 40590 assert sorted(rv.allow) == ["GET", "HEAD"]91

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

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

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

lines 93–104why, one step back
93 assert rv.status_code == 405
9495 rv = client.head("/")96 assert rv.status_code == 20097 assert not rv.data # head truncates98 assert client.post("/more").data == b"POST"99 assert client.get("/more").data == b"GET"100101 rv = client.delete("/more")102 assert rv.status_code == 405103 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]104

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

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

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

lines 106–108why, one step back
106 assert rv.status_code == 405
107108

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

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

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

lines 110–131why, one step back
110 @app.route("/")
111 def index():112 return flask.request.method113114 @app.route("/more", methods=["GET", "POST"])115 def more():116 return flask.request.method117118 assert client.get("/").data == b"GET"119 rv = client.post("/")120 assert rv.status_code == 405121 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]122 rv = client.head("/")123 assert rv.status_code == 200124 assert not rv.data # head truncates125 assert client.post("/more").data == b"POST"126 assert client.get("/more").data == b"GET"127 rv = client.delete("/more")128 assert rv.status_code == 405129 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]130131

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

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

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

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

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

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

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

lines 138–139why, one step back
138
139

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

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

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

lines 142–148why, one step back
142
143 def index():144 return flask.request.method145146 def more():147 return flask.request.method148

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

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

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

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

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

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

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

lines 157–172why, one step back
157 app.add_url_rule("/options", "options", options, methods=["options"])
158159 assert client.get("/").data == b"GET"160 rv = client.post("/")161 assert rv.status_code == 405162 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]163 rv = client.head("/")164 assert rv.status_code == 200165 assert not rv.data # head truncates166 assert client.post("/more").data == b"POST"167 assert client.get("/more").data == b"GET"168 rv = client.delete("/more")169 assert rv.status_code == 405170 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]171 rv = client.open("/options", method="OPTIONS")172 assert rv.status_code == 200

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

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

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

lines 174–175why, one step back
174
175

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

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

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

lines 177–195why, one step back
177 from werkzeug.routing import Submount, Rule
178179 app.url_map.add(180 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])181 )182183 def bar():184 return "bar"185186 def index():187 return "index"188189 app.view_functions["bar"] = bar190 app.view_functions["index"] = index191192 assert client.get("/foo/").data == b"index"193 assert client.get("/foo/bar").data == b"bar"194195

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

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

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

lines 197–214why, one step back
197 from werkzeug.routing import Submount, Rule
198199 app.url_map.add(200 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])201 )202203 @app.endpoint("bar")204 def bar():205 return "bar"206207 @app.endpoint("index")208 def index():209 return "index"210211 assert client.get("/foo/").data == b"index"212 assert client.get("/foo/bar").data == b"bar"213214

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

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

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

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

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

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

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

lines 218–221why, one step back
218 assert not flask.session.accessed
219 assert not flask.session.modified220 flask.session["value"] = flask.request.form["value"]221 assert flask.session.accessed

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

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

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

lines 223–231why, one step back
223 return "value set"
224225 @app.route("/get")226 def get():227 assert not flask.session.accessed228 assert not flask.session.modified229 v = flask.session.get("value", "None")230 assert flask.session.accessed231 assert not flask.session.modified

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

line 232why, one step back
232 return v

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

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

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

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

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

lines 239–250why, one step back
239 app.config.update(SERVER_NAME="example.com")
240241 @app.route("/")242 def index():243 flask.session["testing"] = 42244 return "Hello World"245246 rv = client.get("/", "http://example.com/")247 assert "domain=.example.com" in rv.headers["set-cookie"].lower()248 assert "httponly" in rv.headers["set-cookie"].lower()249250

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

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

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

lines 252–263why, one step back
252 app.config.update(SERVER_NAME="example.com:8080")
253254 @app.route("/")255 def index():256 flask.session["testing"] = 42257 return "Hello World"258259 rv = client.get("/", "http://example.com:8080/")260 assert "domain=.example.com" in rv.headers["set-cookie"].lower()261 assert "httponly" in rv.headers["set-cookie"].lower()262263

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

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

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

lines 265–277why, one step back
265 app.config.update(SERVER_NAME="example.com:8080", APPLICATION_ROOT="/foo")
266267 @app.route("/")268 def index():269 flask.session["testing"] = 42270 return "Hello World"271272 rv = client.get("/", "http://example.com:8080/foo")273 assert "domain=example.com" in rv.headers["set-cookie"].lower()274 assert "path=/foo" in rv.headers["set-cookie"].lower()275 assert "httponly" in rv.headers["set-cookie"].lower()276277

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

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

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

line 279why, one step back
279 class PrefixPathMiddleware:

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

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

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

line 283why, one step back
283

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

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

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

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

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

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

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

lines 287–299why, one step back
287
288 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, "/bar")289 app.config.update(APPLICATION_ROOT="/bar")290291 @app.route("/")292 def index():293 flask.session["testing"] = 42294 return "Hello World"295296 rv = client.get("/", "http://example.com:8080/")297 assert "path=/bar" in rv.headers["set-cookie"].lower()298299

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

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

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

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

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

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

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

lines 307–324why, one step back
307 SESSION_COOKIE_SAMESITE="Lax",
308 SESSION_COOKIE_PATH="/",309 )310311 @app.route("/")312 def index():313 flask.session["testing"] = 42314 return "Hello World"315316 rv = client.get("/", "http://www.example.com:8080/test/")317 cookie = rv.headers["set-cookie"].lower()318 assert "domain=.example.com" in cookie319 assert "path=/" in cookie320 assert "secure" in cookie321 assert "httponly" not in cookie322 assert "samesite" in cookie323324

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

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

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

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

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

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

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

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

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

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

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

lines 337–351why, one step back
337 rv = client.get("/")
338 cookie = rv.headers["set-cookie"].lower()339 assert "samesite" not in cookie340341 app.config.update(SESSION_COOKIE_SAMESITE="Strict")342 rv = client.get("/")343 cookie = rv.headers["set-cookie"].lower()344 assert "samesite=strict" in cookie345346 app.config.update(SESSION_COOKIE_SAMESITE="Lax")347 rv = client.get("/")348 cookie = rv.headers["set-cookie"].lower()349 assert "samesite=lax" in cookie350351

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

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

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

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

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

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

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

lines 364–365why, one step back
364
365

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

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

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

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

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

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

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

line 382why, one step back
382

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

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

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

lines 385–392why, one step back
385 assert e.value.args and "session is unavailable" in e.value.args[0]
386387 with app.test_request_context():388 assert flask.session.get("missing_key") is None389 expect_exception(flask.session.__setitem__, "foo", 42)390 expect_exception(flask.session.pop, "foo")391392

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

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

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

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

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

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

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

lines 400–403why, one step back
400 return ""
401402 @app.route("/test")403 def test():

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

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

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

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

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

lines 409–413why, one step back
409 expires = parse_date(match.group())
410 expected = datetime.utcnow() + app.permanent_session_lifetime411 assert expires.year == expected.year412 assert expires.month == expected.month413 assert expires.day == expected.day

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

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

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

line 418why, one step back
418 permanent = False

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

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

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

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

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

lines 423–424why, one step back
423
424

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

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

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

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

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

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

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

lines 428–438why, one step back
428 flask.session["foo"] = 42
429 return response430431 @app.route("/")432 def dump_session_contents():433 return repr(flask.session.get("foo"))434435 assert client.get("/").data == b"None"436 assert client.get("/").data == b"42"437438

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

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

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

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

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

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

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

lines 458–469why, one step back
458 assert s["t"] == (1, 2, 3)
459 assert type(s["b"]) == bytes460 assert s["b"] == b"\xff"461 assert type(s["m"]) == flask.Markup462 assert s["m"] == flask.Markup("<html>")463 assert s["u"] == the_uuid464 assert s["d"] == now465 assert s["t_tag"] == {" t": "not-a-tuple"}466 assert s["di_t_tag"] == {" t__": "not-a-tuple"}467 assert s["di_tag"] == {" di": "not-a-dict"}468469

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

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

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

lines 471–473why, one step back
471 is_permanent = True
472473 @app.route("/bump")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 492–495why, one step back
492 assert rv.data == b"3"
493494 is_permanent = True495 app.config["SESSION_REFRESH_EACH_REQUEST"] = True

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

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

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

lines 497–510why, one step back
497
498 is_permanent = True499 app.config["SESSION_REFRESH_EACH_REQUEST"] = False500 run_test(expect_header=False)501502 is_permanent = False503 app.config["SESSION_REFRESH_EACH_REQUEST"] = True504 run_test(expect_header=False)505506 is_permanent = False507 app.config["SESSION_REFRESH_EACH_REQUEST"] = False508 run_test(expect_header=False)509510

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

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

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

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

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

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

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

lines 514–521why, one step back
514 flask.session["test"] = "test"
515 return ""516517 @app.route("/get")518 def get():519 return flask.session.get("test")520521 @app.route("/getitem")

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

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

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

lines 523–525why, one step back
523 return flask.session["test"]
524525 @app.route("/setdefault")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 545–547why, one step back
545 return ""
546547 def expect(path, header_value="Cookie"):

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

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

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

line 549why, one step back
549

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

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

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

lines 552–565why, one step back
552 assert len(rv.headers.get_all("Vary")) == 1
553 assert rv.headers["Vary"] == header_value554 else:555 assert "Vary" not in rv.headers556557 expect("/set")558 expect("/get")559 expect("/getitem")560 expect("/setdefault")561 expect("/vary-cookie-header-set")562 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")563 expect("/no-vary-header", None)564565

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

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

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

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

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

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

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

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

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

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

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

lines 572–574why, one step back
572 assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]
573574

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

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

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

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

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

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

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

lines 587–590why, one step back
587 return ""
588589 @app.route("/test/")590 def test():

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

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

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

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

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

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

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

lines 596–599why, one step back
596 ]
597 return ""598599 @app.route("/test_with_categories/")

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

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

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

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

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

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

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

lines 607–610why, one step back
607 ]
608 return ""609610 @app.route("/test_filter/")

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

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

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

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

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

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

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

lines 616–618why, one step back
616 return ""
617618 @app.route("/test_filters/")

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

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

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

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

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

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

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

lines 626–629why, one step back
626 ]
627 return ""628629 @app.route("/test_filters_without_returning_categories/")

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 638–655why, one step back
638
639 client = app.test_client()640 client.get("/")641 client.get("/test_with_categories/")642643 client = app.test_client()644 client.get("/")645 client.get("/test_filter/")646647 client = app.test_client()648 client.get("/")649 client.get("/test_filters/")650651 client = app.test_client()652 client.get("/")653 client.get("/test_filters_without_returning_categories/")654655

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

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

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

lines 657–680why, one step back
657 evts = []
658659 @app.before_request660 def before_request():661 evts.append("before")662663 @app.after_request664 def after_request(response):665 response.data += b"|after"666 evts.append("after")667 return response668669 @app.route("/")670 def index():671 assert "before" in evts672 assert "after" not in evts673 return "request"674675 assert "after" not in evts676 rv = client.get("/").data677 assert "after" in evts678 assert rv == b"request|after"679680

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

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

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

lines 682–684why, one step back
682 evts = []
683684 @app.before_request

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 706–707why, one step back
706
707

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

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

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

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

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

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

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

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

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

line 714why, one step back
714 return response

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

lines 715–718why, one step back
715
716 return "Test"717718 resp = client.get("/")

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

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

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

lines 720–722why, one step back
720 assert resp.headers["X-Foo"] == "a header"
721722

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

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

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

lines 724–740why, one step back
724 called = []
725726 @app.teardown_request727 def teardown_request(exc):728 called.append(True)729 return "Ignored"730731 @app.route("/")732 def root():733 return "Response"734735 rv = client.get("/")736 assert rv.status_code == 200737 assert b"Response" in rv.data738 assert len(called) == 1739740

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

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

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

lines 742–758why, one step back
742 called = []
743744 @app.teardown_request745 def teardown_request(exc):746 called.append(True)747 return "Ignored"748749 @app.route("/")750 def root():751 return "Response"752753 rv = client.get("/")754 assert rv.status_code == 200755 assert b"Response" in rv.data756 assert len(called) == 1757758

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

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

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

lines 760–763why, one step back
760 called = []
761 app.testing = False762763 @app.teardown_request

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

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

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

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

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

line 772why, one step back
772 except Exception:

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

lines 773–775why, one step back
773 pass
774775 @app.teardown_request

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

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

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

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

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

line 784why, one step back
784 except Exception:

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

lines 785–787why, one step back
785 pass
786787 @app.route("/")

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

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

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

lines 789–793why, one step back
789 1 // 0
790791 rv = client.get("/")792 assert rv.status_code == 500793 assert b"Internal Server Error" in rv.data

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

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

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

lines 795–796why, one step back
795
796

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

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

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

lines 798–800why, one step back
798 called = []
799800 @app.before_request

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

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

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

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

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

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

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

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

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

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

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

lines 811–813why, one step back
811 return response
812813 @app.after_request

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

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

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

lines 816–818why, one step back
816 return response
817818 @app.teardown_request

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

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

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

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

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

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

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

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

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

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

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

lines 833–834why, one step back
833
834

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

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

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

lines 836–838why, one step back
836 app.testing = False
837838 @app.errorhandler(404)

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

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

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

lines 840–845why, one step back
840 return "not found", 404
841842 @app.errorhandler(500)843 def internal_server_error(e):844 return "internal server error", 500845

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

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

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

lines 848–854why, one step back
848 return "forbidden", 403
849850 @app.route("/")851 def index():852 flask.abort(404)853854 @app.route("/error")

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

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

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

lines 856–858why, one step back
856 1 // 0
857858 @app.route("/forbidden")

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

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

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

lines 860–868why, one step back
860 flask.abort(403)
861862 rv = client.get("/")863 assert rv.status_code == 404864 assert rv.data == b"not found"865 rv = client.get("/error")866 assert rv.status_code == 500867 assert b"internal server error" == rv.data868 rv = client.get("/forbidden")

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

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

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

lines 870–872why, one step back
870 assert b"forbidden" == rv.data
871872

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

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

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

lines 875–879why, one step back
875 app.register_error_handler(999, lambda e: ("999", 999))
876877 assert "Use a subclass" in exc_info.value.args[0]878879

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

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

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

lines 881–891why, one step back
881 app.testing = False
882883 @app.errorhandler(500)884 def internal_server_error(e):885 return "internal server error", 500886887 @app.route("/")888 def broken_func():889 1 // 0890891 @app.after_request

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

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

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

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

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

line 894why, one step back
894 return resp

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

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

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

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

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

lines 902–905why, one step back
902 app.testing = False
903904 @app.route("/")905 def broken_func():

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

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

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

line 907why, one step back
907

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

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

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

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

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

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

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

lines 914–915why, one step back
914
915

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

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

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

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

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

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

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

lines 919–921why, one step back
919 flask.g.something = "value"
920921 @app.errorhandler(404)

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

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

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

lines 924–929why, one step back
924
925 rv = client.get("/")926 assert rv.status_code == 404927 assert rv.data == b"value"928929

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

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

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

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

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

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

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

lines 937–940why, one step back
937 return "42"
938939 @app.route("/")940 def index():

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

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

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

lines 942–945why, one step back
942
943 assert client.get("/").data == b"42"944945

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 959–961why, one step back
959 return "apple"
960961 @app.route("/1")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 994–996why, one step back
994 return "Exception"
995996 @app.route("/E1")

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

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

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

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

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

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

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

lines 1003–1010why, one step back
1003
1004 rv = client.get("/E1")1005 assert rv.data == b"Exception"10061007 rv = client.get("/E3")1008 assert rv.data == b"E2"10091010

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

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

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

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

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

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

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

lines 1019–1026why, one step back
1019
1020 rv = client.get("/key")1021 assert rv.status_code == 4001022 assert b"missing_key" not in rv.data1023 rv = client.get("/abort")1024 assert rv.status_code == 40010251026 app.debug = True

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1039–1041why, one step back
1039 client.get("/abort")
10401041

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

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

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

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

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

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

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

lines 1050–1052why, one step back
1050 client.get("/fail")
10511052

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

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

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

lines 1054–1057why, one step back
1054 app.testing = False
10551056 @app.before_request1057 def before_request():

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

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

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

lines 1059–1062why, one step back
1059 1 // 0
10601061 @app.after_request1062 def after_request(response):

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

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

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

lines 1064–1074why, one step back
1064 1 // 0
1065 return response10661067 @app.route("/")1068 def index():1069 return "Foo"10701071 @app.errorhandler(500)1072 def internal_server_error(e):1073 return "Hello Server Error", 5001074

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

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

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

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

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

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

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

lines 1078–1080why, one step back
1078 assert rv.data == b"Hello Server Error"
10791080

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

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

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

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

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

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

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

line 1093why, one step back
1093 with client:

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

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

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

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

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

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

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

lines 1098–1099why, one step back
1098
1099

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1123–1125why, one step back
1123 return "Hi, status!", 400
11241125 @app.route("/response_headers")

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

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

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

line 1127why, one step back
1127 return (

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

lines 1128–1131why, one step back
1128 flask.Response(
1129 "Hello world", 404, {"Content-Type": "text/html", "X-Foo": "Baz"}1130 ),1131 {"Content-Type": "text/plain", "X-Foo": "Bar", "X-Bar": "Foo"},

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

lines 1132–1134why, one step back
1132 )
11331134 @app.route("/response_status")

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

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

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

lines 1136–1138why, one step back
1136 return app.response_class("Hello world", 400), 500
11371138 @app.route("/wsgi")

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

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

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

line 1141why, one step back
1141

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

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

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

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

line 1145why, one step back
1145

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

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1148why, one step back
1148

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

lines 1149–1167why, one step back
1149 rv = client.get("/full_tuple")
1150 assert rv.data == b"Meh"1151 assert rv.headers["X-Foo"] == "Testing"1152 assert rv.status_code == 4001153 assert rv.mimetype == "text/plain"11541155 rv = client.get("/text_headers")1156 assert rv.data == b"Hello"1157 assert rv.headers["X-Foo"] == "Test"1158 assert rv.status_code == 2001159 assert rv.mimetype == "text/plain"11601161 rv = client.get("/text_status")1162 assert rv.data == b"Hi, status!"1163 assert rv.status_code == 4001164 assert rv.mimetype == "text/html"11651166 rv = client.get("/response_headers")1167 assert rv.data == b"Hello world"

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

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

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

lines 1170–1179why, one step back
1170 assert rv.headers["X-Bar"] == "Foo"
1171 assert rv.status_code == 40411721173 rv = client.get("/response_status")1174 assert rv.data == b"Hello world"1175 assert rv.status_code == 50011761177 rv = client.get("/wsgi")1178 assert b"Not Found" in rv.data1179 assert rv.status_code == 404

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1180why, one step back
1180

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

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

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

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

lines 1184–1185why, one step back
1184
1185

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

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

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

lines 1187–1190why, one step back
1187 app = flask.Flask(__name__)
1188 app.testing = True11891190 @app.route("/none")

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1203–1204why, one step back
1203 def from_bad_type():
1204 return True

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

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

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

lines 1207–1208why, one step back
1207 def from_bad_wsgi():
1208 return lambda: None

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

lines 1209–1213why, one step back
1209
1210 c = app.test_client()12111212 with pytest.raises(TypeError) as e:1213 c.get("/none")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

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

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

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

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

lines 1220–1224why, one step back
1220
1221 pytest.raises(TypeError, c.get, "/large_tuple")12221223 with pytest.raises(TypeError) as e:1224 c.get("/bad_type")

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

line 1226why, one step back
1226

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

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

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

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

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

lines 1232–1246why, one step back
1232 assert rv.status_code == 200
1233 assert rv.data == b""1234 assert rv.mimetype == "text/html"12351236 rv = flask.make_response("Awesome")1237 assert rv.status_code == 2001238 assert rv.data == b"Awesome"1239 assert rv.mimetype == "text/html"12401241 rv = flask.make_response("W00t", 404)1242 assert rv.status_code == 4041243 assert rv.data == b"W00t"1244 assert rv.mimetype == "text/html"12451246

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

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

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

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

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

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

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

lines 1251–1267why, one step back
1251 assert rv.mimetype == "application/json"
12521253 rv = flask.make_response(flask.Response(""), 400)1254 assert rv.status_code == 4001255 assert rv.data == b""1256 assert rv.mimetype == "text/html"12571258 rv = flask.make_response(1259 flask.Response("", headers={"Content-Type": "text/html"}),1260 400,1261 [("X-Foo", "bar")],1262 )1263 assert rv.status_code == 4001264 assert rv.headers["Content-Type"] == "text/html"1265 assert rv.headers["X-Foo"] == "bar"12661267

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

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

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

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

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

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

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

lines 1275–1276why, one step back
1275
1276

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

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

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

line 1280why, one step back
1280 pretty_response = (

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

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

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

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

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

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

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

lines 1286–1287why, one step back
1286
1287

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

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

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

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

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

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

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

line 1298why, one step back
1298

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

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

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

line 1303why, one step back
1303

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

line 1304why, one step back
1304

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

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

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

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

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

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

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

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

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

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

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

lines 1314–1322why, one step back
1314 pass
13151316 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1317 assert (1318 flask.url_for("hello", name="test x", _external=True)1319 == "http://localhost/hello/test%20x"1320 )13211322

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

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

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

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

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

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

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

line 1329why, one step back
1329 try:

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

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

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

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

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

lines 1332–1333why, one step back
1332 except BuildError as err:
1333 error = err

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

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

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

line 1336why, one step back
1336 except RuntimeError:

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

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

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

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

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

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

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

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

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

lines 1342–1343why, one step back
1342 return "/test_handler/"
1343

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

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

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

lines 1345–1348why, one step back
1345 with app.test_request_context():
1346 assert flask.url_for("spam") == "/test_handler/"13471348

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

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

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

line 1353why, one step back
1353

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

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

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

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

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

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

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

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

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

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

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

lines 1364–1374why, one step back
1364 "_external": False,
1365 "_anchor": None,1366 "_method": None,1367 "_scheme": None,1368 }1369 return "handled"13701371 with app.test_request_context():1372 flask.url_for("/")13731374

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

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

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

lines 1376–1383why, one step back
1376 rv = client.get("/static/index.html")
1377 assert rv.status_code == 2001378 assert rv.data.strip() == b"<h1>Hello World!</h1>"1379 with app.test_request_context():1380 assert flask.url_for("static", filename="index.html") == "/static/index.html"1381 rv.close()13821383

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

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

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

lines 1385–1394why, one step back
1385 app = flask.Flask(__name__, static_url_path="/foo")
1386 app.testing = True1387 rv = app.test_client().get("/foo/index.html")1388 assert rv.status_code == 2001389 rv.close()13901391 with app.test_request_context():1392 assert flask.url_for("static", filename="index.html") == "/foo/index.html"13931394

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

lines 1395–1405why, one step back
1395def test_static_url_path_with_ending_slash():
1396 app = flask.Flask(__name__, static_url_path="/foo/")1397 app.testing = True1398 rv = app.test_client().get("/foo/index.html")1399 assert rv.status_code == 2001400 rv.close()14011402 with app.test_request_context():1403 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14041405

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

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

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

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

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1409–1413why, one step back
1409 assert rv.status_code == 200
1410 rv.close()141114121413def test_static_url_empty_path_default(app):

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

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

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1416–1419why, one step back
1416 assert rv.status_code == 200
1417 rv.close()14181419

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

lines 1420–1429why, one step back
1420@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python >= 3.6")
1421def test_static_folder_with_pathlib_path(app):1422 from pathlib import Path14231424 app = flask.Flask(__name__, static_folder=Path("static"))1425 rv = app.test_client().open("/static/index.html", method="GET")1426 assert rv.status_code == 2001427 rv.close()14281429

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

lines 1430–1440why, one step back
1430def test_static_folder_with_ending_slash():
1431 app = flask.Flask(__name__, static_folder="static/")14321433 @app.route("/<path:path>")1434 def catch_all(path):1435 return path14361437 rv = app.test_client().get("/catch/all")1438 assert rv.data == b"catch/all"14391440

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

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

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

lines 1442–1449why, one step back
1442 app = flask.Flask(__name__, host_matching=True, static_host="example.com")
1443 c = app.test_client()1444 rv = c.get("http://example.com/static/index.html")1445 assert rv.status_code == 2001446 rv.close()1447 with app.test_request_context():1448 rv = flask.url_for("static", filename="index.html", _external=True)1449 assert rv == "http://example.com/static/index.html"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1460–1461why, one step back
1460
1461

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

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

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

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

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

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

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

lines 1465–1466why, one step back
1465
1466

Merge branch '1.0.x'David Lordbefore adoption29111a3

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

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

lines 1468–1472why, one step back
1468 app = flask.Flask(__name__, subdomain_matching=True)
1469 client = app.test_client()14701471 @app.route("/")1472 def index():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1473why, one step back
1473 return "default"

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

lines 1474–1475why, one step back
1474
1475 @app.route("/", subdomain="foo")

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

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

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1477why, one step back
1477 return "subdomain"

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

line 1478why, one step back
1478

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1479why, one step back
1479 app.config["SERVER_NAME"] = "dev.local:5000"

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

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

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1481why, one step back
1481 assert rv.data == b"default"

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

line 1482why, one step back
1482

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1483–1484why, one step back
1483 rv = client.get("/", "http://dev.local:5000")
1484 assert rv.data == b"default"

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

line 1485why, one step back
1485

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1486–1487why, one step back
1486 rv = client.get("/", "https://dev.local:5000")
1487 assert rv.data == b"default"

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

line 1488why, one step back
1488

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1489–1490why, one step back
1489 app.config["SERVER_NAME"] = "dev.local:443"
1490 rv = client.get("/", "https://dev.local")

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

line 1491why, one step back
1491

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1492–1494why, one step back
1492 # Werkzeug 1.0 fixes matching https scheme with 443 port
1493 if rv.status_code != 404:1494 assert rv.data == b"default"

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

line 1495why, one step back
1495

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1496–1501why, one step back
1496 app.config["SERVER_NAME"] = "dev.local"
1497 rv = client.get("/", "https://dev.local")1498 assert rv.data == b"default"14991500 # suppress Werkzeug 1.0 warning about name mismatch1501 with pytest.warns(None):

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

lines 1502–1504why, one step back
1502 rv = client.get("/", "http://foo.localhost")
1503 assert rv.status_code == 4041504

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1505–1506why, one step back
1505 rv = client.get("/", "http://foo.dev.local")
1506 assert rv.data == b"subdomain"

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

lines 1507–1508why, one step back
1507
1508

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

lines 1509–1510why, one step back
1509def test_exception_propagation(app, client):
1510 def apprunner(config_key):

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

lines 1511–1514why, one step back
1511 @app.route("/")
1512 def index():1513 1 // 01514

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

lines 1515–1517why, one step back
1515 if config_key is not None:
1516 app.config[config_key] = True1517 with pytest.raises(Exception):

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

lines 1518–1521why, one step back
1518 client.get("/")
1519 else:1520 assert client.get("/").status_code == 5001521

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

lines 1522–1525why, one step back
1522 # we have to run this test in an isolated thread because if the
1523 # debug flag is set to true and an exception happens the context is1524 # not torn down. This causes other tests that run after this fail1525 # when they expect no exception on the stack.

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

line 1526why, one step back
1526 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:

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

lines 1527–1529why, one step back
1527 t = Thread(target=apprunner, args=(config_key,))
1528 t.start()1529 t.join()

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

lines 1530–1546why, one step back
1530
15311532@pytest.mark.parametrize("debug", [True, False])1533@pytest.mark.parametrize("use_debugger", [True, False])1534@pytest.mark.parametrize("use_reloader", [True, False])1535@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1536def test_werkzeug_passthrough_errors(1537 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1538):1539 rv = {}15401541 # Mocks werkzeug.serving.run_simple method1542 def run_simple_mock(*args, **kwargs):1543 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15441545 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1546 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptions

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

line 1547why, one step back
1547 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)

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

lines 1548–1549why, one step back
1548
1549

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

line 1550why, one step back
1550def test_max_content_length(app, client):

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

lines 1551–1553why, one step back
1551 app.config["MAX_CONTENT_LENGTH"] = 64
15521553 @app.before_request

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

line 1554why, one step back
1554 def always_first():

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

line 1555why, one step back
1555 flask.request.form["myfile"]

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

line 1556why, one step back
1556 AssertionError()

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

lines 1557–1558why, one step back
1557
1558 @app.route("/accept", methods=["POST"])

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

line 1559why, one step back
1559 def accept_file():

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

line 1560why, one step back
1560 flask.request.form["myfile"]

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

line 1561why, one step back
1561 AssertionError()

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

line 1562why, one step back
1562

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

lines 1563–1564why, one step back
1563 @app.errorhandler(413)
1564 def catcher(error):

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

lines 1565–1570why, one step back
1565 return "42"
15661567 rv = client.post("/accept", data={"myfile": "foo" * 100})1568 assert rv.data == b"42"15691570

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

lines 1571–1573why, one step back
1571def test_url_processors(app, client):
1572 @app.url_defaults1573 def add_language_code(endpoint, values):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1574–1578why, one step back
1574 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(
1575 endpoint, "lang_code"1576 ):1577 values.setdefault("lang_code", flask.g.lang_code)1578

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1579–1580why, one step back
1579 @app.url_value_preprocessor
1580 def pull_lang_code(endpoint, values):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1581–1587why, one step back
1581 flask.g.lang_code = values.pop("lang_code", None)
15821583 @app.route("/<lang_code>/")1584 def index():1585 return flask.url_for("about")15861587 @app.route("/<lang_code>/about")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1588why, one step back
1588 def about():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1589–1591why, one step back
1589 return flask.url_for("something_else")
15901591 @app.route("/foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1592why, one step back
1592 def something_else():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1593–1599why, one step back
1593 return flask.url_for("about", lang_code="en")
15941595 assert client.get("/de/").data == b"/de/about"1596 assert client.get("/de/about").data == b"/foo"1597 assert client.get("/foo").data == b"/en/about"15981599

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1600why, one step back
1600def test_inject_blueprint_url_defaults(app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1601–1602why, one step back
1601 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")
1602

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1603–1604why, one step back
1603 @bp.url_defaults
1604 def bp_defaults(endpoint, values):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1605–1607why, one step back
1605 values["page"] = "login"
16061607 @bp.route("/<page>")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1608why, one step back
1608 def view(page):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1609–1610why, one step back
1609 pass
1610

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1611why, one step back
1611 app.register_blueprint(bp)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1612why, one step back
1612

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1613why, one step back
1613 values = dict()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1614–1615why, one step back
1614 app.inject_url_defaults("foo.bar.baz.view", values)
1615 expected = dict(page="login")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1616why, one step back
1616 assert values == expected

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1617–1620why, one step back
1617
1618 with app.test_request_context("/somepage"):1619 url = flask.url_for("foo.bar.baz.view")1620 expected = "/login"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1621why, one step back
1621 assert url == expected

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1622–1623why, one step back
1622
1623

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1624why, one step back
1624def test_nonascii_pathinfo(app, client):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1625why, one step back
1625 @app.route("/киртест")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1626–1628why, one step back
1626 def index():
1627 return "Hello World!"1628

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1629why, one step back
1629 rv = client.get("/киртест")

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1630–1632why, one step back
1630 assert rv.data == b"Hello World!"
16311632

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1633why, one step back
1633def test_debug_mode_complains_after_first_request(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1634–1639why, one step back
1634 app.debug = True
16351636 @app.route("/")1637 def index():1638 return "Awesome"1639

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1640why, one step back
1640 assert not app.got_first_request

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1641why, one step back
1641 assert client.get("/").data == b"Awesome"

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1642why, one step back
1642 with pytest.raises(AssertionError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1643–1644why, one step back
1643
1644 @app.route("/foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1645why, one step back
1645 def broken():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1646–1647why, one step back
1646 return "Meh"
1647

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1648why, one step back
1648 assert "A setup function was called" in str(e.value)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1649–1652why, one step back
1649
1650 app.debug = False16511652 @app.route("/foo")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1653why, one step back
1653 def working():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1654–1659why, one step back
1654 return "Meh"
16551656 assert client.get("/foo").data == b"Meh"1657 assert app.got_first_request16581659

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1660why, one step back
1660def test_before_first_request_functions(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1661–1673why, one step back
1661 got = []
16621663 @app.before_first_request1664 def foo():1665 got.append(42)16661667 client.get("/")1668 assert got == [42]1669 client.get("/")1670 assert got == [42]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_concurrent(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1675–1678why, one step back
1675 got = []
16761677 @app.before_first_request1678 def foo():

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1679why, one step back
1679 time.sleep(0.2)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1680–1681why, one step back
1680 got.append(42)
1681

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1682why, one step back
1682 def get_and_assert():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1683why, one step back
1683 client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1684why, one step back
1684 assert got == [42]

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1685why, one step back
1685

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1686–1689why, one step back
1686 t = Thread(target=get_and_assert)
1687 t.start()1688 get_and_assert()1689 t.join()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1690–1692why, one step back
1690 assert app.got_first_request
16911692

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1693why, one step back
1693def test_routing_redirect_debugging(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1694–1700why, one step back
1694 app.debug = True
16951696 @app.route("/foo/", methods=["GET", "POST"])1697 def foo():1698 return "success"16991700 with client:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1701why, one step back
1701 with pytest.raises(AssertionError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1702why, one step back
1702 client.post("/foo", data={})

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1703why, one step back
1703 assert "http://localhost/foo/" in str(e.value)

Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b

line 1704why, one step back
1704 assert "Make sure to directly send your POST-request to this URL" in str(

Merge branch '1.0.x'David Lordbefore adoptionb05a685

lines 1705–1706why, one step back
1705 e.value
1706 )

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1707–1716why, one step back
1707
1708 rv = client.get("/foo", data={}, follow_redirects=True)1709 assert rv.data == b"success"17101711 app.debug = False1712 with client:1713 rv = client.post("/foo", data={}, follow_redirects=True)1714 assert rv.data == b"success"17151716

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1717why, one step back
1717def test_route_decorator_custom_endpoint(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1718–1724why, one step back
1718 app.debug = True
17191720 @app.route("/foo/")1721 def foo():1722 return flask.request.endpoint17231724 @app.route("/bar/", endpoint="bar")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1725why, one step back
1725 def for_bar():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1726–1728why, one step back
1726 return flask.request.endpoint
17271728 @app.route("/bar/123", endpoint="123")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1729why, one step back
1729 def for_bar_foo():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1730–1741why, one step back
1730 return flask.request.endpoint
17311732 with app.test_request_context():1733 assert flask.url_for("foo") == "/foo/"1734 assert flask.url_for("bar") == "/bar/"1735 assert flask.url_for("123") == "/bar/123"17361737 assert client.get("/foo/").data == b"foo"1738 assert client.get("/bar/").data == b"bar"1739 assert client.get("/bar/123").data == b"123"17401741

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1742why, one step back
1742def test_preserve_only_once(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1743–1748why, one step back
1743 app.debug = True
17441745 @app.route("/fail")1746 def fail_func():1747 1 // 01748

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1749why, one step back
1749 for _x in range(3):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1750why, one step back
1750 with pytest.raises(ZeroDivisionError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1751–1752why, one step back
1751 client.get("/fail")
1752

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1753–1758why, one step back
1753 assert flask._request_ctx_stack.top is not None
1754 assert flask._app_ctx_stack.top is not None1755 # implicit appctx disappears too1756 flask._request_ctx_stack.top.pop()1757 assert flask._request_ctx_stack.top is None1758 assert flask._app_ctx_stack.top is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1759–1760why, one step back
1759
1760

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1761why, one step back
1761def test_preserve_remembers_exception(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1762why, one step back
1762 app.debug = True

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1763why, one step back
1763 errors = []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1764–1769why, one step back
1764
1765 @app.route("/fail")1766 def fail_func():1767 1 // 017681769 @app.route("/success")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1770why, one step back
1770 def success_func():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1771–1773why, one step back
1771 return "Okay"
17721773 @app.teardown_request

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1774–1775why, one step back
1774 def teardown_handler(exc):
1775 errors.append(exc)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1776why, one step back
1776

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1777–1778why, one step back
1777 # After this failure we did not yet call the teardown handler
1778 with pytest.raises(ZeroDivisionError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1779why, one step back
1779 client.get("/fail")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1780why, one step back
1780 assert errors == []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1781why, one step back
1781

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1782why, one step back
1782 # But this request triggers it, and it's an error

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1783why, one step back
1783 client.get("/success")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1784–1785why, one step back
1784 assert len(errors) == 2
1785 assert isinstance(errors[0], ZeroDivisionError)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1786why, one step back
1786

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1787why, one step back
1787 # At this point another request does nothing.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1788why, one step back
1788 client.get("/success")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1789–1790why, one step back
1789 assert len(errors) == 3
1790 assert errors[1] is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1791–1792why, one step back
1791
1792

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1793why, one step back
1793def test_get_method_on_g(app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1794–1795why, one step back
1794 assert flask.g.get("x") is None
1795 assert flask.g.get("x", 11) == 11

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1796why, one step back
1796 flask.g.x = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1797why, one step back
1797 assert flask.g.get("x") == 42

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1798why, one step back
1798 assert flask.g.x == 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1799–1800why, one step back
1799
1800

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1801–1803why, one step back
1801def test_g_iteration_protocol(app_ctx):
1802 flask.g.foo = 231803 flask.g.bar = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1804–1808why, one step back
1804 assert "foo" in flask.g
1805 assert "foos" not in flask.g1806 assert sorted(flask.g) == ["bar", "foo"]18071808

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1809why, one step back
1809def test_subdomain_basic_support():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1810–1814why, one step back
1810 app = flask.Flask(__name__, subdomain_matching=True)
1811 app.config["SERVER_NAME"] = "localhost.localdomain"1812 client = app.test_client()18131814 @app.route("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1815why, one step back
1815 def normal_index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1816–1818why, one step back
1816 return "normal index"
18171818 @app.route("/", subdomain="test")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1819why, one step back
1819 def test_index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1820–1828why, one step back
1820 return "test index"
18211822 rv = client.get("/", "http://localhost.localdomain/")1823 assert rv.data == b"normal index"18241825 rv = client.get("/", "http://test.localhost.localdomain/")1826 assert rv.data == b"test index"18271828

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1829why, one step back
1829def test_subdomain_matching():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1830–1835why, one step back
1830 app = flask.Flask(__name__, subdomain_matching=True)
1831 client = app.test_client()1832 app.config["SERVER_NAME"] = "localhost.localdomain"18331834 @app.route("/", subdomain="<user>")1835 def index(user):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1836why, one step back
1836 return f"index for {user}"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1837–1841why, one step back
1837
1838 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1839 assert rv.data == b"index for mitsuhiko"18401841

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1842why, one step back
1842def test_subdomain_matching_with_ports():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1843–1848why, one step back
1843 app = flask.Flask(__name__, subdomain_matching=True)
1844 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1845 client = app.test_client()18461847 @app.route("/", subdomain="<user>")1848 def index(user):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1849why, one step back
1849 return f"index for {user}"

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1850–1855why, one step back
1850
1851 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1852 assert rv.data == b"index for mitsuhiko"185318541855@pytest.mark.parametrize("matching", (False, True))

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1856–1857why, one step back
1856def test_subdomain_matching_other_name(matching):
1857 app = flask.Flask(__name__, subdomain_matching=matching)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1858–1864why, one step back
1858 app.config["SERVER_NAME"] = "localhost.localdomain:3000"
1859 client = app.test_client()18601861 @app.route("/")1862 def index():1863 return "", 2041864

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1865–1869why, one step back
1865 # suppress Werkzeug 0.15 warning about name mismatch
1866 with pytest.warns(None):1867 # ip address can't match name1868 rv = client.get("/", "http://127.0.0.1:3000/")1869 assert rv.status_code == 404 if matching else 204

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1870why, one step back
1870

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1871why, one step back
1871 # allow all subdomains if matching is disabled

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1872–1875why, one step back
1872 rv = client.get("/", "http://www.localhost.localdomain:3000/")
1873 assert rv.status_code == 404 if matching else 20418741875

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1876why, one step back
1876def test_multi_route_rules(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1877–1879why, one step back
1877 @app.route("/")
1878 @app.route("/<test>/")1879 def index(test="a"):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1880why, one step back
1880 return test

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1881–1887why, one step back
1881
1882 rv = client.open("/")1883 assert rv.data == b"a"1884 rv = client.open("/b/")1885 assert rv.data == b"b"18861887

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1888why, one step back
1888def test_multi_route_class_views(app, client):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1889why, one step back
1889 class View:

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1890why, one step back
1890 def __init__(self, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1891–1894why, one step back
1891 app.add_url_rule("/", "index", self.index)
1892 app.add_url_rule("/<test>/", "index", self.index)18931894 def index(self, test="a"):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1895why, one step back
1895 return test

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1896why, one step back
1896

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1897why, one step back
1897 _ = View(app)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1898–1903why, one step back
1898 rv = client.open("/")
1899 assert rv.data == b"a"1900 rv = client.open("/b/")1901 assert rv.data == b"b"19021903

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1904why, one step back
1904def test_run_defaults(monkeypatch, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1905–1911why, one step back
1905 rv = {}
19061907 # Mocks werkzeug.serving.run_simple method1908 def run_simple_mock(*args, **kwargs):1909 rv["result"] = "running..."19101911 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1912why, one step back
1912 app.run()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1913–1915why, one step back
1913 assert rv["result"] == "running..."
19141915

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1916why, one step back
1916def test_run_server_port(monkeypatch, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1917–1919why, one step back
1917 rv = {}
19181919 # Mocks werkzeug.serving.run_simple method

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1920why, one step back
1920 def run_simple_mock(hostname, port, application, *args, **kwargs):

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1921why, one step back
1921 rv["result"] = f"running on {hostname}:{port} ..."

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1922–1924why, one step back
1922
1923 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1924 hostname, port = "localhost", 8000

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1925why, one step back
1925 app.run(hostname, port, debug=True)

Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374

line 1926why, one step back
1926 assert rv["result"] == f"running on {hostname}:{port} ..."

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1927–1929why, one step back
1927
19281929@pytest.mark.parametrize(

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1930why, one step back
1930 "host,port,server_name,expect_host,expect_port",

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1931why, one step back
1931 (

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

lines 1932–1938why, one step back
1932 (None, None, "pocoo.org:8080", "pocoo.org", 8080),
1933 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1934 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1935 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1936 ("localhost", 0, "localhost:8080", "localhost", 0),1937 (None, None, "localhost:8080", "localhost", 8080),1938 (None, None, "localhost:0", "localhost", 0),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1939–1940why, one step back
1939 ),
1940)

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

lines 1941–1943why, one step back
1941def test_run_from_config(
1942 monkeypatch, host, port, server_name, expect_host, expect_port, app1943):

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1944–1946why, one step back
1944 def run_simple_mock(hostname, port, *args, **kwargs):
1945 assert hostname == expect_host1946 assert port == expect_port

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1947–1948why, one step back
1947
1948 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1949why, one step back
1949 app.config["SERVER_NAME"] = server_name

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1950why, one step back
1950 app.run(host, port)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1951–1952why, one step back
1951
1952

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1953why, one step back
1953def test_max_cookie_size(app, client, recwarn):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1954–1955why, one step back
1954 app.config["MAX_COOKIE_SIZE"] = 100
1955

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1956–1958why, one step back
1956 # outside app context, default to Werkzeug static value,
1957 # which is also the default config1958 response = flask.Response()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1959why, one step back
1959 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1960why, one step back
1960 assert response.max_cookie_size == default

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1961why, one step back
1961

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1962–1964why, one step back
1962 # inside app context, use app config
1963 with app.app_context():1964 assert flask.Response().max_cookie_size == 100

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1965–1969why, one step back
1965
1966 @app.route("/")1967 def index():1968 r = flask.Response("", status=204)1969 r.set_cookie("foo", "bar" * 100)

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1970why, one step back
1970 return r

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1971–1972why, one step back
1971
1972 client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

lines 1973–1974why, one step back
1973 assert len(recwarn) == 1
1974 w = recwarn.pop()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1975–1979why, one step back
1975 assert "cookie is too large" in str(w.message)
19761977 app.config["MAX_COOKIE_SIZE"] = 019781979 client.get("/")

Merge pull request #2996 from alysivji/spa-docsDavid Lordbefore adoptionb78ebac

line 1980why, one step back
1980 assert len(recwarn) == 0

Break reference cycle created by default in Flask instances.Bogdan Opanchukbefore adoption8efea0c

lines 1981–1996why, one step back
1981
19821983@require_cpython_gc1984def test_app_freed_on_zero_refcount():1985 # A Flask instance should not create a reference cycle that prevents CPython1986 # from freeing it when all external references to it are released (see #3761).1987 gc.disable()1988 try:1989 app = flask.Flask(__name__)1990 assert app.view_functions["static"]1991 weak = weakref.ref(app)1992 assert weak() is not None1993 del app1994 assert weak() is None1995 finally:1996 gc.enable()