Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

1,969 lines · 52.7 KiB · Python

Last changed by

remove more compat codeDavid Lordbefore adoption57d628c

History of this file

Take it

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

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

lines 1–7why, one step back
1# -*- coding: utf-8 -*-
2"""3 tests.basic4 ~~~~~~~~~~~~~~~~~~~~~56 The basic functionality.7

Merge branch '1.0.x'David Lordbefore adoption1351d0a

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

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

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

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

line 12why, one step back
12import sys

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

lines 13–19why, one step back
13import time
14import uuid15from datetime import datetime16from threading import Thread1718import pytest19import werkzeug.serving

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

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

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

lines 23–29why, one step back
23from werkzeug.http import parse_date
24from werkzeug.routing import BuildError2526import flask272829def test_options_work(app, client):

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

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

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

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

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

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

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

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

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

lines 46–51why, one step back
46 return "Aha!"
4748 rv = client.open("/", method="OPTIONS")49 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]5051

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 75–81why, one step back
75 def index():
76 return flask.request.method7778 def more():79 return flask.request.method8081 app.add_url_rule("/", view_func=index, provide_automatic_options=False)

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

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

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

lines 83–93why, one step back
83 "/more",
84 view_func=more,85 methods=["GET", "POST"],86 provide_automatic_options=False,87 )88 assert client.get("/").data == b"GET"8990 rv = client.post("/")91 assert rv.status_code == 40592 assert sorted(rv.allow) == ["GET", "HEAD"]93

remove more compat codeDavid Lordbefore adoption57d628c

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

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

lines 95–106why, one step back
95 assert rv.status_code == 405
9697 rv = client.head("/")98 assert rv.status_code == 20099 assert not rv.data # head truncates100 assert client.post("/more").data == b"POST"101 assert client.get("/more").data == b"GET"102103 rv = client.delete("/more")104 assert rv.status_code == 405105 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]106

remove more compat codeDavid Lordbefore adoption57d628c

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

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

lines 108–110why, one step back
108 assert rv.status_code == 405
109110

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

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

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

lines 112–133why, one step back
112 @app.route("/")
113 def index():114 return flask.request.method115116 @app.route("/more", methods=["GET", "POST"])117 def more():118 return flask.request.method119120 assert client.get("/").data == b"GET"121 rv = client.post("/")122 assert rv.status_code == 405123 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]124 rv = client.head("/")125 assert rv.status_code == 200126 assert not rv.data # head truncates127 assert client.post("/more").data == b"POST"128 assert client.get("/more").data == b"GET"129 rv = client.delete("/more")130 assert rv.status_code == 405131 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]132133

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

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

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

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

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

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

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

lines 140–141why, one step back
140
141

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

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

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

lines 144–150why, one step back
144
145 def index():146 return flask.request.method147148 def more():149 return flask.request.method150

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

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

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

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

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

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

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

lines 159–174why, one step back
159 app.add_url_rule("/options", "options", options, methods=["options"])
160161 assert client.get("/").data == b"GET"162 rv = client.post("/")163 assert rv.status_code == 405164 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]165 rv = client.head("/")166 assert rv.status_code == 200167 assert not rv.data # head truncates168 assert client.post("/more").data == b"POST"169 assert client.get("/more").data == b"GET"170 rv = client.delete("/more")171 assert rv.status_code == 405172 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]173 rv = client.open("/options", method="OPTIONS")174 assert rv.status_code == 200

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

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

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

lines 176–177why, one step back
176
177

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

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

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

lines 179–197why, one step back
179 from werkzeug.routing import Submount, Rule
180181 app.url_map.add(182 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])183 )184185 def bar():186 return "bar"187188 def index():189 return "index"190191 app.view_functions["bar"] = bar192 app.view_functions["index"] = index193194 assert client.get("/foo/").data == b"index"195 assert client.get("/foo/bar").data == b"bar"196197

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

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

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

lines 199–216why, one step back
199 from werkzeug.routing import Submount, Rule
200201 app.url_map.add(202 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])203 )204205 @app.endpoint("bar")206 def bar():207 return "bar"208209 @app.endpoint("index")210 def index():211 return "index"212213 assert client.get("/foo/").data == b"index"214 assert client.get("/foo/bar").data == b"bar"215216

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

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

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

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

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

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

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

lines 220–223why, one step back
220 assert not flask.session.accessed
221 assert not flask.session.modified222 flask.session["value"] = flask.request.form["value"]223 assert flask.session.accessed

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

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

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

lines 225–233why, one step back
225 return "value set"
226227 @app.route("/get")228 def get():229 assert not flask.session.accessed230 assert not flask.session.modified231 v = flask.session.get("value", "None")232 assert flask.session.accessed233 assert not flask.session.modified

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

line 234why, one step back
234 return v

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

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

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

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

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

lines 241–252why, one step back
241 app.config.update(SERVER_NAME="example.com")
242243 @app.route("/")244 def index():245 flask.session["testing"] = 42246 return "Hello World"247248 rv = client.get("/", "http://example.com/")249 assert "domain=.example.com" in rv.headers["set-cookie"].lower()250 assert "httponly" in rv.headers["set-cookie"].lower()251252

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

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

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

lines 254–265why, one step back
254 app.config.update(SERVER_NAME="example.com:8080")
255256 @app.route("/")257 def index():258 flask.session["testing"] = 42259 return "Hello World"260261 rv = client.get("/", "http://example.com:8080/")262 assert "domain=.example.com" in rv.headers["set-cookie"].lower()263 assert "httponly" in rv.headers["set-cookie"].lower()264265

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

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

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

lines 267–279why, one step back
267 app.config.update(SERVER_NAME="example.com:8080", APPLICATION_ROOT="/foo")
268269 @app.route("/")270 def index():271 flask.session["testing"] = 42272 return "Hello World"273274 rv = client.get("/", "http://example.com:8080/foo")275 assert "domain=example.com" in rv.headers["set-cookie"].lower()276 assert "path=/foo" in rv.headers["set-cookie"].lower()277 assert "httponly" in rv.headers["set-cookie"].lower()278279

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

lines 280–284why, one step back
280def test_session_using_application_root(app, client):
281 class PrefixPathMiddleware(object):282 def __init__(self, app, prefix):283 self.app = app284 self.prefix = prefix

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

line 285why, one step back
285

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

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

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

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

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

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

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

lines 289–301why, one step back
289
290 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, "/bar")291 app.config.update(APPLICATION_ROOT="/bar")292293 @app.route("/")294 def index():295 flask.session["testing"] = 42296 return "Hello World"297298 rv = client.get("/", "http://example.com:8080/")299 assert "path=/bar" in rv.headers["set-cookie"].lower()300301

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

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

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

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

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

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

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

lines 309–326why, one step back
309 SESSION_COOKIE_SAMESITE="Lax",
310 SESSION_COOKIE_PATH="/",311 )312313 @app.route("/")314 def index():315 flask.session["testing"] = 42316 return "Hello World"317318 rv = client.get("/", "http://www.example.com:8080/test/")319 cookie = rv.headers["set-cookie"].lower()320 assert "domain=.example.com" in cookie321 assert "path=/" in cookie322 assert "secure" in cookie323 assert "httponly" not in cookie324 assert "samesite" in cookie325326

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

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

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

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

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

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

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

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

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

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

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

lines 339–353why, one step back
339 rv = client.get("/")
340 cookie = rv.headers["set-cookie"].lower()341 assert "samesite" not in cookie342343 app.config.update(SESSION_COOKIE_SAMESITE="Strict")344 rv = client.get("/")345 cookie = rv.headers["set-cookie"].lower()346 assert "samesite=strict" in cookie347348 app.config.update(SESSION_COOKIE_SAMESITE="Lax")349 rv = client.get("/")350 cookie = rv.headers["set-cookie"].lower()351 assert "samesite=lax" in cookie352353

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

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

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

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

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

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

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

lines 366–367why, one step back
366
367

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

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

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

lines 369–381why, one step back
369 app.config.update(SERVER_NAME="127.0.0.1:5000")
370371 @app.route("/")372 def index():373 flask.session["testing"] = 42374 return "testing"375376 rv = client.get("/", "http://127.0.0.1:5000/")377 assert "domain=127.0.0.1" in rv.headers["set-cookie"].lower()378 w = recwarn.pop(UserWarning)379 assert "cookie domain is an IP" in str(w.message)380381

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

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

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

line 384why, one step back
384

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

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

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

lines 387–394why, one step back
387 assert e.value.args and "session is unavailable" in e.value.args[0]
388389 with app.test_request_context():390 assert flask.session.get("missing_key") is None391 expect_exception(flask.session.__setitem__, "foo", 42)392 expect_exception(flask.session.pop, "foo")393394

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

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

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

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

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

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

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

lines 402–405why, one step back
402 return ""
403404 @app.route("/test")405 def test():

remove _compat moduleDavid Lordbefore adoption662c245

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

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

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

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

lines 411–415why, one step back
411 expires = parse_date(match.group())
412 expected = datetime.utcnow() + app.permanent_session_lifetime413 assert expires.year == expected.year414 assert expires.month == expected.month415 assert expires.day == expected.day

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

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

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

line 420why, one step back
420 permanent = False

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

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

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

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

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

lines 425–426why, one step back
425
426

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

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

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

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

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

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

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

lines 430–440why, one step back
430 flask.session["foo"] = 42
431 return response432433 @app.route("/")434 def dump_session_contents():435 return repr(flask.session.get("foo"))436437 assert client.get("/").data == b"None"438 assert client.get("/").data == b"42"439440

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

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

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

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

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

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

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

lines 460–471why, one step back
460 assert s["t"] == (1, 2, 3)
461 assert type(s["b"]) == bytes462 assert s["b"] == b"\xff"463 assert type(s["m"]) == flask.Markup464 assert s["m"] == flask.Markup("<html>")465 assert s["u"] == the_uuid466 assert s["d"] == now467 assert s["t_tag"] == {" t": "not-a-tuple"}468 assert s["di_t_tag"] == {" t__": "not-a-tuple"}469 assert s["di_tag"] == {" di": "not-a-dict"}470471

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 494–497why, one step back
494 assert rv.data == b"3"
495496 is_permanent = True497 app.config["SESSION_REFRESH_EACH_REQUEST"] = True

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

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

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

lines 499–512why, one step back
499
500 is_permanent = True501 app.config["SESSION_REFRESH_EACH_REQUEST"] = False502 run_test(expect_header=False)503504 is_permanent = False505 app.config["SESSION_REFRESH_EACH_REQUEST"] = True506 run_test(expect_header=False)507508 is_permanent = False509 app.config["SESSION_REFRESH_EACH_REQUEST"] = False510 run_test(expect_header=False)511512

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

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

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

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

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

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

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

lines 516–523why, one step back
516 flask.session["test"] = "test"
517 return ""518519 @app.route("/get")520 def get():521 return flask.session.get("test")522523 @app.route("/getitem")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

line 551why, one step back
551

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

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

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

lines 554–567why, one step back
554 assert len(rv.headers.get_all("Vary")) == 1
555 assert rv.headers["Vary"] == header_value556 else:557 assert "Vary" not in rv.headers558559 expect("/set")560 expect("/get")561 expect("/getitem")562 expect("/setdefault")563 expect("/vary-cookie-header-set")564 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")565 expect("/no-vary-header", None)566567

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 583–592why, one step back
583
584 @app.route("/")585 def index():586 flask.flash(u"Hello World")587 flask.flash(u"Hello World", "error")588 flask.flash(flask.Markup(u"<em>Testing</em>"), "warning")589 return ""590591 @app.route("/test/")592 def test():

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

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

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

lines 594–601why, one step back
594 assert list(messages) == [
595 u"Hello World",596 u"Hello World",597 flask.Markup(u"<em>Testing</em>"),598 ]599 return ""600601 @app.route("/test_with_categories/")

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

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

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

lines 605–612why, one step back
605 assert list(messages) == [
606 ("message", u"Hello World"),607 ("error", u"Hello World"),608 ("warning", flask.Markup(u"<em>Testing</em>")),609 ]610 return ""611612 @app.route("/test_filter/")

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

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

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

lines 614–620why, one step back
614 messages = flask.get_flashed_messages(
615 category_filter=["message"], with_categories=True616 )617 assert list(messages) == [("message", u"Hello World")]618 return ""619620 @app.route("/test_filters/")

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

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

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

lines 622–631why, one step back
622 messages = flask.get_flashed_messages(
623 category_filter=["message", "warning"], with_categories=True624 )625 assert list(messages) == [626 ("message", u"Hello World"),627 ("warning", flask.Markup(u"<em>Testing</em>")),628 ]629 return ""630631 @app.route("/test_filters_without_returning_categories/")

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

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

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

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

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

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

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

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

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

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

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

lines 640–657why, one step back
640
641 client = app.test_client()642 client.get("/")643 client.get("/test_with_categories/")644645 client = app.test_client()646 client.get("/")647 client.get("/test_filter/")648649 client = app.test_client()650 client.get("/")651 client.get("/test_filters/")652653 client = app.test_client()654 client.get("/")655 client.get("/test_filters_without_returning_categories/")656657

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

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

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

lines 659–682why, one step back
659 evts = []
660661 @app.before_request662 def before_request():663 evts.append("before")664665 @app.after_request666 def after_request(response):667 response.data += b"|after"668 evts.append("after")669 return response670671 @app.route("/")672 def index():673 assert "before" in evts674 assert "after" not in evts675 return "request"676677 assert "after" not in evts678 rv = client.get("/").data679 assert "after" in evts680 assert rv == b"request|after"681682

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 708–709why, one step back
708
709

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

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

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

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

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

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

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

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

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

line 716why, one step back
716 return response

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

lines 717–720why, one step back
717
718 return "Test"719720 resp = client.get("/")

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

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

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

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

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

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

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

lines 726–742why, one step back
726 called = []
727728 @app.teardown_request729 def teardown_request(exc):730 called.append(True)731 return "Ignored"732733 @app.route("/")734 def root():735 return "Response"736737 rv = client.get("/")738 assert rv.status_code == 200739 assert b"Response" in rv.data740 assert len(called) == 1741742

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

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

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

lines 744–760why, one step back
744 called = []
745746 @app.teardown_request747 def teardown_request(exc):748 called.append(True)749 return "Ignored"750751 @app.route("/")752 def root():753 return "Response"754755 rv = client.get("/")756 assert rv.status_code == 200757 assert b"Response" in rv.data758 assert len(called) == 1759760

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

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

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

lines 762–765why, one step back
762 called = []
763 app.testing = False764765 @app.teardown_request

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

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

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

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

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

line 774why, one step back
774 except Exception:

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

lines 775–777why, one step back
775 pass
776777 @app.teardown_request

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

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

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

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

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

line 786why, one step back
786 except Exception:

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

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

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

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

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

lines 791–795why, one step back
791 1 // 0
792793 rv = client.get("/")794 assert rv.status_code == 500795 assert b"Internal Server Error" in rv.data

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

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

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

lines 797–798why, one step back
797
798

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 813–815why, one step back
813 return response
814815 @app.after_request

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

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

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

lines 818–820why, one step back
818 return response
819820 @app.teardown_request

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

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

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

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

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

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

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

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

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

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

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

lines 835–836why, one step back
835
836

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

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

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

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

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

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

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

lines 842–847why, one step back
842 return "not found", 404
843844 @app.errorhandler(500)845 def internal_server_error(e):846 return "internal server error", 500847

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

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

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

lines 850–856why, one step back
850 return "forbidden", 403
851852 @app.route("/")853 def index():854 flask.abort(404)855856 @app.route("/error")

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

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

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

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

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

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

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

lines 862–870why, one step back
862 flask.abort(403)
863864 rv = client.get("/")865 assert rv.status_code == 404866 assert rv.data == b"not found"867 rv = client.get("/error")868 assert rv.status_code == 500869 assert b"internal server error" == rv.data870 rv = client.get("/forbidden")

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

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

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

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

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

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

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

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

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

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

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

lines 883–893why, one step back
883 app.testing = False
884885 @app.errorhandler(500)886 def internal_server_error(e):887 return "internal server error", 500888889 @app.route("/")890 def broken_func():891 1 // 0892893 @app.after_request

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

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

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

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

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

line 896why, one step back
896 return resp

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

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

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

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

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

lines 904–907why, one step back
904 app.testing = False
905906 @app.route("/")907 def broken_func():

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

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

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

line 909why, one step back
909

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

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

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

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

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

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

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

lines 916–917why, one step back
916
917

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

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

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

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

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

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

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

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

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

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

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

lines 926–931why, one step back
926
927 rv = client.get("/")928 assert rv.status_code == 404929 assert rv.data == b"value"930931

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

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

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

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

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

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

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

lines 939–942why, one step back
939 return "42"
940941 @app.route("/")942 def index():

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

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

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

lines 944–947why, one step back
944
945 assert client.get("/").data == b"42"946947

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1005–1012why, one step back
1005
1006 rv = client.get("/E1")1007 assert rv.data == b"Exception"10081009 rv = client.get("/E3")1010 assert rv.data == b"E2"10111012

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

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

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

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

lines 1021–1028why, one step back
1021
1022 rv = client.get("/key")1023 assert rv.status_code == 4001024 assert b"missing_key" not in rv.data1025 rv = client.get("/abort")1026 assert rv.status_code == 40010271028 app.debug = True

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

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

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

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

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

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

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

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

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

Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1056–1059why, one step back
1056 app.testing = False
10571058 @app.before_request1059 def before_request():

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

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

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

lines 1061–1064why, one step back
1061 1 // 0
10621063 @app.after_request1064 def after_request(response):

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

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

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

lines 1066–1076why, one step back
1066 1 // 0
1067 return response10681069 @app.route("/")1070 def index():1071 return "Foo"10721073 @app.errorhandler(500)1074 def internal_server_error(e):1075 return "Hello Server Error", 5001076

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

line 1095why, one step back
1095 with client:

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

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

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

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

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

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

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

lines 1100–1101why, one step back
1100
1101

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

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

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

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

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

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

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

lines 1105–1107why, one step back
1105 return u"Hällo Wörld"
11061107 @app.route("/bytes")

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

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

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

lines 1109–1111why, one step back
1109 return u"Hällo Wörld".encode("utf-8")
11101111 @app.route("/full_tuple")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

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 #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

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

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–1178why, 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"1168 assert rv.headers.getlist("X-Foo") == ["Baz", "Bar"]1169 assert rv.headers["X-Bar"] == "Foo"1170 assert rv.status_code == 40411711172 rv = client.get("/response_status")1173 assert rv.data == b"Hello world"1174 assert rv.status_code == 50011751176 rv = client.get("/wsgi")1177 assert b"Not Found" in rv.data1178 assert rv.status_code == 404

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

line 1179why, one step back
1179

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

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

Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b

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

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

lines 1183–1184why, one step back
1183
1184

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

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

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

lines 1186–1189why, one step back
1186 app = flask.Flask(__name__)
1187 app.testing = True11881189 @app.route("/none")

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

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

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

lines 1191–1193why, one step back
1191 pass
11921193 @app.route("/small_tuple")

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

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

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

lines 1195–1197why, one step back
1195 return ("Hello",)
11961197 @app.route("/large_tuple")

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

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

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

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

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

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

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

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

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

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

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

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

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

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

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

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

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

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

Merge branch '1.0.x'David Lordbefore adoptionb05a685

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

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

line 1225why, one step back
1225

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

lines 1226–1228why, one step back
1226 pytest.raises(TypeError, c.get, "/bad_wsgi")
12271228

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

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

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

lines 1231–1245why, one step back
1231 assert rv.status_code == 200
1232 assert rv.data == b""1233 assert rv.mimetype == "text/html"12341235 rv = flask.make_response("Awesome")1236 assert rv.status_code == 2001237 assert rv.data == b"Awesome"1238 assert rv.mimetype == "text/html"12391240 rv = flask.make_response("W00t", 404)1241 assert rv.status_code == 4041242 assert rv.data == b"W00t"1243 assert rv.mimetype == "text/html"12441245

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

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

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

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

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

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

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

lines 1250–1266why, one step back
1250 assert rv.mimetype == "application/json"
12511252 rv = flask.make_response(flask.Response(""), 400)1253 assert rv.status_code == 4001254 assert rv.data == b""1255 assert rv.mimetype == "text/html"12561257 rv = flask.make_response(1258 flask.Response("", headers={"Content-Type": "text/html"}),1259 400,1260 [("X-Foo", "bar")],1261 )1262 assert rv.status_code == 4001263 assert rv.headers["Content-Type"] == "text/html"1264 assert rv.headers["X-Foo"] == "bar"12651266

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

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

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

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

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

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

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

lines 1274–1275why, one step back
1274
1275

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

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

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

line 1279why, one step back
1279 pretty_response = (

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

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

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

lines 1281–1283why, one step back
1281 )
12821283 rv = flask.make_response(flask.jsonify(compressed_msg), 200)

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

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

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

lines 1285–1286why, one step back
1285
1286

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

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

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

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

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

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

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

line 1297why, one step back
1297

Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6

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

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

line 1302why, one step back
1302

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

line 1303why, one step back
1303

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

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

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

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

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

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

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

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

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

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

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

lines 1313–1321why, one step back
1313 pass
13141315 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1316 assert (1317 flask.url_for("hello", name="test x", _external=True)1318 == "http://localhost/hello/test%20x"1319 )13201321

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

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

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

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

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

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

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

line 1328why, one step back
1328 try:

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

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

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

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

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

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

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

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

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

line 1335why, one step back
1335 except RuntimeError:

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1344–1347why, one step back
1344 with app.test_request_context():
1345 assert flask.url_for("spam") == "/test_handler/"13461347

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

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

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

line 1352why, one step back
1352

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

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

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

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

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

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

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

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

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

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

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

lines 1363–1373why, one step back
1363 "_external": False,
1364 "_anchor": None,1365 "_method": None,1366 "_scheme": None,1367 }1368 return "handled"13691370 with app.test_request_context():1371 flask.url_for("/")13721373

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

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

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

lines 1375–1382why, one step back
1375 rv = client.get("/static/index.html")
1376 assert rv.status_code == 2001377 assert rv.data.strip() == b"<h1>Hello World!</h1>"1378 with app.test_request_context():1379 assert flask.url_for("static", filename="index.html") == "/static/index.html"1380 rv.close()13811382

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

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

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

lines 1384–1393why, one step back
1384 app = flask.Flask(__name__, static_url_path="/foo")
1385 app.testing = True1386 rv = app.test_client().get("/foo/index.html")1387 assert rv.status_code == 2001388 rv.close()13891390 with app.test_request_context():1391 assert flask.url_for("static", filename="index.html") == "/foo/index.html"13921393

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

lines 1394–1404why, one step back
1394def test_static_url_path_with_ending_slash():
1395 app = flask.Flask(__name__, static_url_path="/foo/")1396 app.testing = True1397 rv = app.test_client().get("/foo/index.html")1398 assert rv.status_code == 2001399 rv.close()14001401 with app.test_request_context():1402 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14031404

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

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

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

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

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1408–1412why, one step back
1408 assert rv.status_code == 200
1409 rv.close()141014111412def test_static_url_empty_path_default(app):

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

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

Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729

lines 1415–1418why, one step back
1415 assert rv.status_code == 200
1416 rv.close()14171418

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

lines 1419–1429why, one step back
1419def test_static_folder_with_ending_slash():
1420 app = flask.Flask(__name__, static_folder="static/")14211422 @app.route("/<path:path>")1423 def catch_all(path):1424 return path14251426 rv = app.test_client().get("/catch/all")1427 assert rv.data == b"catch/all"14281429

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

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

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

lines 1431–1438why, one step back
1431 app = flask.Flask(__name__, host_matching=True, static_host="example.com")
1432 c = app.test_client()1433 rv = c.get("http://example.com/static/index.html")1434 assert rv.status_code == 2001435 rv.close()1436 with app.test_request_context():1437 rv = flask.url_for("static", filename="index.html", _external=True)1438 assert rv == "http://example.com/static/index.html"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 1449–1450why, one step back
1449
1450

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

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

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

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

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

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

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

lines 1454–1455why, one step back
1454
1455

Merge branch '1.0.x'David Lordbefore adoption29111a3

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

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

lines 1457–1461why, one step back
1457 app = flask.Flask(__name__, subdomain_matching=True)
1458 client = app.test_client()14591460 @app.route("/")1461 def index():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1462why, one step back
1462 return "default"

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

lines 1463–1464why, one step back
1463
1464 @app.route("/", subdomain="foo")

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

line 1465why, one step back
1465 def subdomain():

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1466why, one step back
1466 return "subdomain"

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

line 1467why, one step back
1467

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1468why, one step back
1468 app.config["SERVER_NAME"] = "dev.local:5000"

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

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

Merge branch '1.0.x'David Lordbefore adoption29111a3

line 1470why, one step back
1470 assert rv.data == b"default"

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

line 1471why, one step back
1471

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1472–1473why, one step back
1472 rv = client.get("/", "http://dev.local:5000")
1473 assert rv.data == b"default"

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

line 1474why, one step back
1474

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1475–1476why, one step back
1475 rv = client.get("/", "https://dev.local:5000")
1476 assert rv.data == b"default"

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

line 1477why, one step back
1477

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1478–1479why, one step back
1478 app.config["SERVER_NAME"] = "dev.local:443"
1479 rv = client.get("/", "https://dev.local")

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

line 1480why, one step back
1480

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1481–1483why, one step back
1481 # Werkzeug 1.0 fixes matching https scheme with 443 port
1482 if rv.status_code != 404:1483 assert rv.data == b"default"

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

line 1484why, one step back
1484

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1485–1490why, one step back
1485 app.config["SERVER_NAME"] = "dev.local"
1486 rv = client.get("/", "https://dev.local")1487 assert rv.data == b"default"14881489 # suppress Werkzeug 1.0 warning about name mismatch1490 with pytest.warns(None):

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

lines 1491–1493why, one step back
1491 rv = client.get("/", "http://foo.localhost")
1492 assert rv.status_code == 4041493

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1494–1495why, one step back
1494 rv = client.get("/", "http://foo.dev.local")
1495 assert rv.data == b"subdomain"

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

lines 1496–1497why, one step back
1496
1497

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

lines 1498–1499why, one step back
1498def test_exception_propagation(app, client):
1499 def apprunner(config_key):

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

lines 1500–1503why, one step back
1500 @app.route("/")
1501 def index():1502 1 // 01503

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

lines 1504–1506why, one step back
1504 if config_key is not None:
1505 app.config[config_key] = True1506 with pytest.raises(Exception):

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

lines 1507–1510why, one step back
1507 client.get("/")
1508 else:1509 assert client.get("/").status_code == 5001510

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

lines 1511–1514why, one step back
1511 # we have to run this test in an isolated thread because if the
1512 # debug flag is set to true and an exception happens the context is1513 # not torn down. This causes other tests that run after this fail1514 # when they expect no exception on the stack.

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

line 1515why, one step back
1515 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:

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

lines 1516–1518why, one step back
1516 t = Thread(target=apprunner, args=(config_key,))
1517 t.start()1518 t.join()

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

lines 1519–1535why, one step back
1519
15201521@pytest.mark.parametrize("debug", [True, False])1522@pytest.mark.parametrize("use_debugger", [True, False])1523@pytest.mark.parametrize("use_reloader", [True, False])1524@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1525def test_werkzeug_passthrough_errors(1526 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1527):1528 rv = {}15291530 # Mocks werkzeug.serving.run_simple method1531 def run_simple_mock(*args, **kwargs):1532 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15331534 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1535 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptions

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

line 1536why, one step back
1536 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)

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

lines 1537–1538why, one step back
1537
1538

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

line 1539why, one step back
1539def test_max_content_length(app, client):

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

lines 1540–1542why, one step back
1540 app.config["MAX_CONTENT_LENGTH"] = 64
15411542 @app.before_request

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

line 1543why, one step back
1543 def always_first():

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

line 1544why, one step back
1544 flask.request.form["myfile"]

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

line 1545why, one step back
1545 AssertionError()

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

lines 1546–1547why, one step back
1546
1547 @app.route("/accept", methods=["POST"])

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

line 1548why, one step back
1548 def accept_file():

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

line 1549why, one step back
1549 flask.request.form["myfile"]

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

line 1550why, one step back
1550 AssertionError()

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

line 1551why, one step back
1551

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

lines 1552–1553why, one step back
1552 @app.errorhandler(413)
1553 def catcher(error):

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

lines 1554–1559why, one step back
1554 return "42"
15551556 rv = client.post("/accept", data={"myfile": "foo" * 100})1557 assert rv.data == b"42"15581559

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

lines 1560–1562why, one step back
1560def test_url_processors(app, client):
1561 @app.url_defaults1562 def add_language_code(endpoint, values):

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

lines 1563–1567why, one step back
1563 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(
1564 endpoint, "lang_code"1565 ):1566 values.setdefault("lang_code", flask.g.lang_code)1567

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

lines 1568–1569why, one step back
1568 @app.url_value_preprocessor
1569 def pull_lang_code(endpoint, values):

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

lines 1570–1576why, one step back
1570 flask.g.lang_code = values.pop("lang_code", None)
15711572 @app.route("/<lang_code>/")1573 def index():1574 return flask.url_for("about")15751576 @app.route("/<lang_code>/about")

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

line 1577why, one step back
1577 def about():

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

lines 1578–1580why, one step back
1578 return flask.url_for("something_else")
15791580 @app.route("/foo")

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

line 1581why, one step back
1581 def something_else():

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

lines 1582–1588why, one step back
1582 return flask.url_for("about", lang_code="en")
15831584 assert client.get("/de/").data == b"/de/about"1585 assert client.get("/de/about").data == b"/foo"1586 assert client.get("/foo").data == b"/en/about"15871588

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

line 1589why, one step back
1589def test_inject_blueprint_url_defaults(app):

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

lines 1590–1591why, one step back
1590 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")
1591

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

lines 1592–1593why, one step back
1592 @bp.url_defaults
1593 def bp_defaults(endpoint, values):

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

lines 1594–1596why, one step back
1594 values["page"] = "login"
15951596 @bp.route("/<page>")

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

line 1597why, one step back
1597 def view(page):

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

lines 1598–1599why, one step back
1598 pass
1599

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

line 1600why, one step back
1600 app.register_blueprint(bp)

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

line 1601why, one step back
1601

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

line 1602why, one step back
1602 values = dict()

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

lines 1603–1604why, one step back
1603 app.inject_url_defaults("foo.bar.baz.view", values)
1604 expected = dict(page="login")

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

line 1605why, one step back
1605 assert values == expected

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

lines 1606–1609why, one step back
1606
1607 with app.test_request_context("/somepage"):1608 url = flask.url_for("foo.bar.baz.view")1609 expected = "/login"

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

line 1610why, one step back
1610 assert url == expected

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

lines 1611–1612why, one step back
1611
1612

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

line 1613why, one step back
1613def test_nonascii_pathinfo(app, client):

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

lines 1614–1621why, one step back
1614 @app.route(u"/киртест")
1615 def index():1616 return "Hello World!"16171618 rv = client.get(u"/киртест")1619 assert rv.data == b"Hello World!"16201621

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

line 1622why, one step back
1622def test_debug_mode_complains_after_first_request(app, client):

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

lines 1623–1628why, one step back
1623 app.debug = True
16241625 @app.route("/")1626 def index():1627 return "Awesome"1628

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

line 1629why, one step back
1629 assert not app.got_first_request

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

line 1630why, one step back
1630 assert client.get("/").data == b"Awesome"

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

line 1631why, one step back
1631 with pytest.raises(AssertionError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1632–1633why, one step back
1632
1633 @app.route("/foo")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1634why, one step back
1634 def broken():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1635–1636why, one step back
1635 return "Meh"
1636

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1637why, one step back
1637 assert "A setup function was called" in str(e.value)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1638–1641why, one step back
1638
1639 app.debug = False16401641 @app.route("/foo")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1642why, one step back
1642 def working():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1643–1648why, one step back
1643 return "Meh"
16441645 assert client.get("/foo").data == b"Meh"1646 assert app.got_first_request16471648

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1649why, one step back
1649def test_before_first_request_functions(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1650–1662why, one step back
1650 got = []
16511652 @app.before_first_request1653 def foo():1654 got.append(42)16551656 client.get("/")1657 assert got == [42]1658 client.get("/")1659 assert got == [42]1660 assert app.got_first_request16611662

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1663why, one step back
1663def test_before_first_request_functions_concurrent(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1664–1667why, one step back
1664 got = []
16651666 @app.before_first_request1667 def foo():

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1668why, one step back
1668 time.sleep(0.2)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1669–1670why, one step back
1669 got.append(42)
1670

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1671why, one step back
1671 def get_and_assert():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1672why, one step back
1672 client.get("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1673why, one step back
1673 assert got == [42]

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1674why, one step back
1674

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1675–1678why, one step back
1675 t = Thread(target=get_and_assert)
1676 t.start()1677 get_and_assert()1678 t.join()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1679–1681why, one step back
1679 assert app.got_first_request
16801681

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1682why, one step back
1682def test_routing_redirect_debugging(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1683–1689why, one step back
1683 app.debug = True
16841685 @app.route("/foo/", methods=["GET", "POST"])1686 def foo():1687 return "success"16881689 with client:

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1690why, one step back
1690 with pytest.raises(AssertionError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1691why, one step back
1691 client.post("/foo", data={})

Merge branch '1.0.x'David Lordbefore adoptionb05a685

line 1692why, one step back
1692 assert "http://localhost/foo/" in str(e.value)

Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b

line 1693why, one step back
1693 assert "Make sure to directly send your POST-request to this URL" in str(

Merge branch '1.0.x'David Lordbefore adoptionb05a685

lines 1694–1695why, one step back
1694 e.value
1695 )

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1696–1705why, one step back
1696
1697 rv = client.get("/foo", data={}, follow_redirects=True)1698 assert rv.data == b"success"16991700 app.debug = False1701 with client:1702 rv = client.post("/foo", data={}, follow_redirects=True)1703 assert rv.data == b"success"17041705

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1706why, one step back
1706def test_route_decorator_custom_endpoint(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1707–1713why, one step back
1707 app.debug = True
17081709 @app.route("/foo/")1710 def foo():1711 return flask.request.endpoint17121713 @app.route("/bar/", endpoint="bar")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1714why, one step back
1714 def for_bar():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1715–1717why, one step back
1715 return flask.request.endpoint
17161717 @app.route("/bar/123", endpoint="123")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1718why, one step back
1718 def for_bar_foo():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1719–1730why, one step back
1719 return flask.request.endpoint
17201721 with app.test_request_context():1722 assert flask.url_for("foo") == "/foo/"1723 assert flask.url_for("bar") == "/bar/"1724 assert flask.url_for("123") == "/bar/123"17251726 assert client.get("/foo/").data == b"foo"1727 assert client.get("/bar/").data == b"bar"1728 assert client.get("/bar/123").data == b"123"17291730

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1731why, one step back
1731def test_preserve_only_once(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1732–1737why, one step back
1732 app.debug = True
17331734 @app.route("/fail")1735 def fail_func():1736 1 // 01737

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 1738why, one step back
1738 for _x in range(3):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1739why, one step back
1739 with pytest.raises(ZeroDivisionError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1740–1741why, one step back
1740 client.get("/fail")
1741

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1742–1747why, one step back
1742 assert flask._request_ctx_stack.top is not None
1743 assert flask._app_ctx_stack.top is not None1744 # implicit appctx disappears too1745 flask._request_ctx_stack.top.pop()1746 assert flask._request_ctx_stack.top is None1747 assert flask._app_ctx_stack.top is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1748–1749why, one step back
1748
1749

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1750why, one step back
1750def test_preserve_remembers_exception(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1751why, one step back
1751 app.debug = True

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1752why, one step back
1752 errors = []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1753–1758why, one step back
1753
1754 @app.route("/fail")1755 def fail_func():1756 1 // 017571758 @app.route("/success")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1759why, one step back
1759 def success_func():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1760–1762why, one step back
1760 return "Okay"
17611762 @app.teardown_request

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1763–1764why, one step back
1763 def teardown_handler(exc):
1764 errors.append(exc)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1765why, one step back
1765

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1766–1767why, one step back
1766 # After this failure we did not yet call the teardown handler
1767 with pytest.raises(ZeroDivisionError):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1768why, one step back
1768 client.get("/fail")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1769why, one step back
1769 assert errors == []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1770why, one step back
1770

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1771why, one step back
1771 # But this request triggers it, and it's an error

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1772why, one step back
1772 client.get("/success")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1773–1774why, one step back
1773 assert len(errors) == 2
1774 assert isinstance(errors[0], ZeroDivisionError)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1775why, one step back
1775

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1776why, one step back
1776 # At this point another request does nothing.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1777why, one step back
1777 client.get("/success")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1778–1779why, one step back
1778 assert len(errors) == 3
1779 assert errors[1] is None

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1780–1781why, one step back
1780
1781

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1782why, one step back
1782def test_get_method_on_g(app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1783–1784why, one step back
1783 assert flask.g.get("x") is None
1784 assert flask.g.get("x", 11) == 11

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1785why, one step back
1785 flask.g.x = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1786why, one step back
1786 assert flask.g.get("x") == 42

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1787why, one step back
1787 assert flask.g.x == 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1788–1789why, one step back
1788
1789

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1790–1792why, one step back
1790def test_g_iteration_protocol(app_ctx):
1791 flask.g.foo = 231792 flask.g.bar = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1793–1797why, one step back
1793 assert "foo" in flask.g
1794 assert "foos" not in flask.g1795 assert sorted(flask.g) == ["bar", "foo"]17961797

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1798why, one step back
1798def test_subdomain_basic_support():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1799–1803why, one step back
1799 app = flask.Flask(__name__, subdomain_matching=True)
1800 app.config["SERVER_NAME"] = "localhost.localdomain"1801 client = app.test_client()18021803 @app.route("/")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1804why, one step back
1804 def normal_index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1805–1807why, one step back
1805 return "normal index"
18061807 @app.route("/", subdomain="test")

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1808why, one step back
1808 def test_index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1809–1817why, one step back
1809 return "test index"
18101811 rv = client.get("/", "http://localhost.localdomain/")1812 assert rv.data == b"normal index"18131814 rv = client.get("/", "http://test.localhost.localdomain/")1815 assert rv.data == b"test index"18161817

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1818why, one step back
1818def test_subdomain_matching():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1819–1830why, one step back
1819 app = flask.Flask(__name__, subdomain_matching=True)
1820 client = app.test_client()1821 app.config["SERVER_NAME"] = "localhost.localdomain"18221823 @app.route("/", subdomain="<user>")1824 def index(user):1825 return "index for %s" % user18261827 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1828 assert rv.data == b"index for mitsuhiko"18291830

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1831why, one step back
1831def test_subdomain_matching_with_ports():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1832–1844why, one step back
1832 app = flask.Flask(__name__, subdomain_matching=True)
1833 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1834 client = app.test_client()18351836 @app.route("/", subdomain="<user>")1837 def index(user):1838 return "index for %s" % user18391840 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1841 assert rv.data == b"index for mitsuhiko"184218431844@pytest.mark.parametrize("matching", (False, True))

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1845–1846why, one step back
1845def test_subdomain_matching_other_name(matching):
1846 app = flask.Flask(__name__, subdomain_matching=matching)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1847–1853why, one step back
1847 app.config["SERVER_NAME"] = "localhost.localdomain:3000"
1848 client = app.test_client()18491850 @app.route("/")1851 def index():1852 return "", 2041853

Merge branch '1.0.x'David Lordbefore adoption29111a3

lines 1854–1858why, one step back
1854 # suppress Werkzeug 0.15 warning about name mismatch
1855 with pytest.warns(None):1856 # ip address can't match name1857 rv = client.get("/", "http://127.0.0.1:3000/")1858 assert rv.status_code == 404 if matching else 204

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1859why, one step back
1859

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1860why, one step back
1860 # allow all subdomains if matching is disabled

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1861–1864why, one step back
1861 rv = client.get("/", "http://www.localhost.localdomain:3000/")
1862 assert rv.status_code == 404 if matching else 20418631864

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1865why, one step back
1865def test_multi_route_rules(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1866–1868why, one step back
1866 @app.route("/")
1867 @app.route("/<test>/")1868 def index(test="a"):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1869why, one step back
1869 return test

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1870–1876why, one step back
1870
1871 rv = client.open("/")1872 assert rv.data == b"a"1873 rv = client.open("/b/")1874 assert rv.data == b"b"18751876

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1877–1879why, one step back
1877def test_multi_route_class_views(app, client):
1878 class View(object):1879 def __init__(self, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1880–1883why, one step back
1880 app.add_url_rule("/", "index", self.index)
1881 app.add_url_rule("/<test>/", "index", self.index)18821883 def index(self, test="a"):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1884why, one step back
1884 return test

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1885why, one step back
1885

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1886why, one step back
1886 _ = View(app)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1887–1892why, one step back
1887 rv = client.open("/")
1888 assert rv.data == b"a"1889 rv = client.open("/b/")1890 assert rv.data == b"b"18911892

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1893why, one step back
1893def test_run_defaults(monkeypatch, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1894–1900why, one step back
1894 rv = {}
18951896 # Mocks werkzeug.serving.run_simple method1897 def run_simple_mock(*args, **kwargs):1898 rv["result"] = "running..."18991900 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1901why, one step back
1901 app.run()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1902–1904why, one step back
1902 assert rv["result"] == "running..."
19031904

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1905why, one step back
1905def test_run_server_port(monkeypatch, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1906–1908why, one step back
1906 rv = {}
19071908 # Mocks werkzeug.serving.run_simple method

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1909why, one step back
1909 def run_simple_mock(hostname, port, application, *args, **kwargs):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1910–1913why, one step back
1910 rv["result"] = "running on %s:%s ..." % (hostname, port)
19111912 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1913 hostname, port = "localhost", 8000

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1914why, one step back
1914 app.run(hostname, port, debug=True)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1915–1918why, one step back
1915 assert rv["result"] == "running on %s:%s ..." % (hostname, port)
191619171918@pytest.mark.parametrize(

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1919why, one step back
1919 "host,port,server_name,expect_host,expect_port",

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1920why, one step back
1920 (

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

lines 1921–1927why, one step back
1921 (None, None, "pocoo.org:8080", "pocoo.org", 8080),
1922 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1923 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1924 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1925 ("localhost", 0, "localhost:8080", "localhost", 0),1926 (None, None, "localhost:8080", "localhost", 8080),1927 (None, None, "localhost:0", "localhost", 0),

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1928–1929why, one step back
1928 ),
1929)

Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398

lines 1930–1932why, one step back
1930def test_run_from_config(
1931 monkeypatch, host, port, server_name, expect_host, expect_port, app1932):

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

lines 1933–1935why, one step back
1933 def run_simple_mock(hostname, port, *args, **kwargs):
1934 assert hostname == expect_host1935 assert port == expect_port

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1936–1937why, one step back
1936
1937 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b

line 1938why, one step back
1938 app.config["SERVER_NAME"] = server_name

Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6

line 1939why, one step back
1939 app.run(host, port)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1940–1941why, one step back
1940
1941

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1942why, one step back
1942def test_max_cookie_size(app, client, recwarn):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1943–1944why, one step back
1943 app.config["MAX_COOKIE_SIZE"] = 100
1944

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

lines 1945–1947why, one step back
1945 # outside app context, default to Werkzeug static value,
1946 # which is also the default config1947 response = flask.Response()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1948why, one step back
1948 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1949why, one step back
1949 assert response.max_cookie_size == default

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1950why, one step back
1950

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

lines 1951–1953why, one step back
1951 # inside app context, use app config
1952 with app.app_context():1953 assert flask.Response().max_cookie_size == 100

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1954–1958why, one step back
1954
1955 @app.route("/")1956 def index():1957 r = flask.Response("", status=204)1958 r.set_cookie("foo", "bar" * 100)

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1959why, one step back
1959 return r

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1960–1961why, one step back
1960
1961 client.get("/")

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

lines 1962–1963why, one step back
1962 assert len(recwarn) == 1
1963 w = recwarn.pop()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1964–1968why, one step back
1964 assert "cookie is too large" in str(w.message)
19651966 app.config["MAX_COOKIE_SIZE"] = 019671968 client.get("/")

Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589

line 1969why, one step back
1969 assert len(recwarn) == 0