test_basic.py
This file
Path
tests/test_basic.py
1,979 lines · 53.0 KiB · Python
Last changed by
Merge remote-tracking branch 'origin/1.1.x'David Lordbefore adoption64ba434
History of this fileTake 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 back1# -*- coding: utf-8 -*-2"""3 tests.basic4 ~~~~~~~~~~~~~~~~~~~~~56 The basic functionality.7Merge branch '1.0.x'David Lordbefore adoption1351d0a
lines 8–9why, one step back8 :copyright: 2010 Pallets9 :license: BSD-3-ClauseMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 10–11why, one step back10"""11import reMerge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
line 12why, one step back12import sysMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 13–19why, one step back13import time14import uuid15from datetime import datetime16from threading import Thread1718import pytest19import werkzeug.servingMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 20–22why, one step back20from werkzeug.exceptions import BadRequest21from werkzeug.exceptions import Forbidden22from werkzeug.exceptions import NotFoundMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 23–30why, one step back23from werkzeug.http import parse_date24from werkzeug.routing import BuildError2526import flask27from flask._compat import text_type282930def test_options_work(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 31–39why, one step back31 @app.route("/", methods=["GET", "POST"])32 def index():33 return "Hello World"3435 rv = client.open("/", method="OPTIONS")36 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]37 assert rv.data == b""3839Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 40why, one step back40def test_options_on_multiple_rules(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 41–45why, one step back41 @app.route("/", methods=["GET", "POST"])42 def index():43 return "Hello World"4445 @app.route("/", methods=["PUT"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 46why, one step back46 def index_put():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 47–52why, one step back47 return "Aha!"4849 rv = client.open("/", method="OPTIONS")50 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]5152Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 53why, one step back53def test_provide_automatic_options_attr():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 54–58why, one step back54 app = flask.Flask(__name__)5556 def index():57 return "Hello World!"58Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 59why, one step back59 index.provide_automatic_options = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 60–68why, one step back60 app.route("/")(index)61 rv = app.test_client().open("/", method="OPTIONS")62 assert rv.status_code == 4056364 app = flask.Flask(__name__)6566 def index2():67 return "Hello World!"68Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 69why, one step back69 index2.provide_automatic_options = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 70–74why, one step back70 app.route("/", methods=["OPTIONS"])(index2)71 rv = app.test_client().open("/", method="OPTIONS")72 assert sorted(rv.allow) == ["OPTIONS"]7374Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 75why, one step back75def test_provide_automatic_options_kwarg(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 76–82why, one step back76 def index():77 return flask.request.method7879 def more():80 return flask.request.method8182 app.add_url_rule("/", view_func=index, provide_automatic_options=False)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 83why, one step back83 app.add_url_rule(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 84–94why, one step back84 "/more",85 view_func=more,86 methods=["GET", "POST"],87 provide_automatic_options=False,88 )89 assert client.get("/").data == b"GET"9091 rv = client.post("/")92 assert rv.status_code == 40593 assert sorted(rv.allow) == ["GET", "HEAD"]94Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 95why, one step back95 # Older versions of Werkzeug.test.Client don't have an options methodMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 96–120why, one step back96 if hasattr(client, "options"):97 rv = client.options("/")98 else:99 rv = client.open("/", method="OPTIONS")100101 assert rv.status_code == 405102103 rv = client.head("/")104 assert rv.status_code == 200105 assert not rv.data # head truncates106 assert client.post("/more").data == b"POST"107 assert client.get("/more").data == b"GET"108109 rv = client.delete("/more")110 assert rv.status_code == 405111 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]112113 if hasattr(client, "options"):114 rv = client.options("/more")115 else:116 rv = client.open("/more", method="OPTIONS")117118 assert rv.status_code == 405119120Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 121why, one step back121def test_request_dispatching(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 122–143why, one step back122 @app.route("/")123 def index():124 return flask.request.method125126 @app.route("/more", methods=["GET", "POST"])127 def more():128 return flask.request.method129130 assert client.get("/").data == b"GET"131 rv = client.post("/")132 assert rv.status_code == 405133 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]134 rv = client.head("/")135 assert rv.status_code == 200136 assert not rv.data # head truncates137 assert client.post("/more").data == b"POST"138 assert client.get("/more").data == b"GET"139 rv = client.delete("/more")140 assert rv.status_code == 405141 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]142143Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 144–145why, one step back144def test_disallow_string_for_allowed_methods(app):145 with pytest.raises(TypeError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 146–148why, one step back146147 @app.route("/", methods="GET POST")148 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 149why, one step back149 return "Hey"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 150–151why, one step back150151Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 152–153why, one step back152def test_url_mapping(app, client):153 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 154–160why, one step back154155 def index():156 return flask.request.method157158 def more():159 return flask.request.method160Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 161–162why, one step back161 def options():162 return random_uuid4Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 163–166why, one step back163164 app.add_url_rule("/", "index", index)165 app.add_url_rule("/more", "more", more, methods=["GET", "POST"])166Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 167–168why, one step back167 # Issue 1288: Test that automatic options are not added168 # when non-uppercase 'options' in methodsMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 169–184why, one step back169 app.add_url_rule("/options", "options", options, methods=["options"])170171 assert client.get("/").data == b"GET"172 rv = client.post("/")173 assert rv.status_code == 405174 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]175 rv = client.head("/")176 assert rv.status_code == 200177 assert not rv.data # head truncates178 assert client.post("/more").data == b"POST"179 assert client.get("/more").data == b"GET"180 rv = client.delete("/more")181 assert rv.status_code == 405182 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]183 rv = client.open("/options", method="OPTIONS")184 assert rv.status_code == 200Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 185why, one step back185 assert random_uuid4 in rv.data.decode("utf-8")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 186–187why, one step back186187Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 188why, one step back188def test_werkzeug_routing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 189–207why, one step back189 from werkzeug.routing import Submount, Rule190191 app.url_map.add(192 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])193 )194195 def bar():196 return "bar"197198 def index():199 return "index"200201 app.view_functions["bar"] = bar202 app.view_functions["index"] = index203204 assert client.get("/foo/").data == b"index"205 assert client.get("/foo/bar").data == b"bar"206207Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 208why, one step back208def test_endpoint_decorator(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 209–226why, one step back209 from werkzeug.routing import Submount, Rule210211 app.url_map.add(212 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])213 )214215 @app.endpoint("bar")216 def bar():217 return "bar"218219 @app.endpoint("index")220 def index():221 return "index"222223 assert client.get("/foo/").data == b"index"224 assert client.get("/foo/bar").data == b"bar"225226Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 227why, one step back227def test_session(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 228why, one step back228 @app.route("/set", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 229why, one step back229 def set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 230–233why, one step back230 assert not flask.session.accessed231 assert not flask.session.modified232 flask.session["value"] = flask.request.form["value"]233 assert flask.session.accessedMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 234why, one step back234 assert flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 235–243why, one step back235 return "value set"236237 @app.route("/get")238 def get():239 assert not flask.session.accessed240 assert not flask.session.modified241 v = flask.session.get("value", "None")242 assert flask.session.accessed243 assert not flask.session.modifiedMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 244why, one step back244 return vMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 245–249why, one step back245246 assert client.post("/set", data={"value": "42"}).data == b"value set"247 assert client.get("/get").data == b"42"248249Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 250why, one step back250def test_session_using_server_name(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 251–262why, one step back251 app.config.update(SERVER_NAME="example.com")252253 @app.route("/")254 def index():255 flask.session["testing"] = 42256 return "Hello World"257258 rv = client.get("/", "http://example.com/")259 assert "domain=.example.com" in rv.headers["set-cookie"].lower()260 assert "httponly" in rv.headers["set-cookie"].lower()261262Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 263why, one step back263def test_session_using_server_name_and_port(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 264–275why, one step back264 app.config.update(SERVER_NAME="example.com:8080")265266 @app.route("/")267 def index():268 flask.session["testing"] = 42269 return "Hello World"270271 rv = client.get("/", "http://example.com:8080/")272 assert "domain=.example.com" in rv.headers["set-cookie"].lower()273 assert "httponly" in rv.headers["set-cookie"].lower()274275Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 276why, one step back276def test_session_using_server_name_port_and_path(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 277–289why, one step back277 app.config.update(SERVER_NAME="example.com:8080", APPLICATION_ROOT="/foo")278279 @app.route("/")280 def index():281 flask.session["testing"] = 42282 return "Hello World"283284 rv = client.get("/", "http://example.com:8080/foo")285 assert "domain=example.com" in rv.headers["set-cookie"].lower()286 assert "path=/foo" in rv.headers["set-cookie"].lower()287 assert "httponly" in rv.headers["set-cookie"].lower()288289Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 290–294why, one step back290def test_session_using_application_root(app, client):291 class PrefixPathMiddleware(object):292 def __init__(self, app, prefix):293 self.app = app294 self.prefix = prefixMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 295why, one step back295Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 296why, one step back296 def __call__(self, environ, start_response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 297why, one step back297 environ["SCRIPT_NAME"] = self.prefixMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 298why, one step back298 return self.app(environ, start_response)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 299–311why, one step back299300 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, "/bar")301 app.config.update(APPLICATION_ROOT="/bar")302303 @app.route("/")304 def index():305 flask.session["testing"] = 42306 return "Hello World"307308 rv = client.get("/", "http://example.com:8080/")309 assert "path=/bar" in rv.headers["set-cookie"].lower()310311Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 312why, one step back312def test_session_using_session_settings(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 313–316why, one step back313 app.config.update(314 SERVER_NAME="www.example.com:8080",315 APPLICATION_ROOT="/test",316 SESSION_COOKIE_DOMAIN=".example.com",Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 317–318why, one step back317 SESSION_COOKIE_HTTPONLY=False,318 SESSION_COOKIE_SECURE=True,Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 319–336why, one step back319 SESSION_COOKIE_SAMESITE="Lax",320 SESSION_COOKIE_PATH="/",321 )322323 @app.route("/")324 def index():325 flask.session["testing"] = 42326 return "Hello World"327328 rv = client.get("/", "http://www.example.com:8080/test/")329 cookie = rv.headers["set-cookie"].lower()330 assert "domain=.example.com" in cookie331 assert "path=/" in cookie332 assert "secure" in cookie333 assert "httponly" not in cookie334 assert "samesite" in cookie335336Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 337why, one step back337def test_session_using_samesite_attribute(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 338–344why, one step back338 @app.route("/")339 def index():340 flask.session["testing"] = 42341 return "Hello World"342343 app.config.update(SESSION_COOKIE_SAMESITE="invalid")344Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 345why, one step back345 with pytest.raises(ValueError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 346–347why, one step back346 client.get("/")347Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 348why, one step back348 app.config.update(SESSION_COOKIE_SAMESITE=None)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 349–363why, one step back349 rv = client.get("/")350 cookie = rv.headers["set-cookie"].lower()351 assert "samesite" not in cookie352353 app.config.update(SESSION_COOKIE_SAMESITE="Strict")354 rv = client.get("/")355 cookie = rv.headers["set-cookie"].lower()356 assert "samesite=strict" in cookie357358 app.config.update(SESSION_COOKIE_SAMESITE="Lax")359 rv = client.get("/")360 cookie = rv.headers["set-cookie"].lower()361 assert "samesite=lax" in cookie362363Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 364why, one step back364def test_session_localhost_warning(recwarn, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 365–374why, one step back365 app.config.update(SERVER_NAME="localhost:5000")366367 @app.route("/")368 def index():369 flask.session["testing"] = 42370 return "testing"371372 rv = client.get("/", "http://localhost:5000/")373 assert "domain" not in rv.headers["set-cookie"].lower()374 w = recwarn.pop(UserWarning)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 375why, one step back375 assert '"localhost" is not a valid cookie domain' in str(w.message)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 376–377why, one step back376377Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 378why, one step back378def test_session_ip_warning(recwarn, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 379–391why, one step back379 app.config.update(SERVER_NAME="127.0.0.1:5000")380381 @app.route("/")382 def index():383 flask.session["testing"] = 42384 return "testing"385386 rv = client.get("/", "http://127.0.0.1:5000/")387 assert "domain=127.0.0.1" in rv.headers["set-cookie"].lower()388 w = recwarn.pop(UserWarning)389 assert "cookie domain is an IP" in str(w.message)390391Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 392–393why, one step back392def test_missing_session(app):393 app.secret_key = NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 394why, one step back394Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 395–396why, one step back395 def expect_exception(f, *args, **kwargs):396 e = pytest.raises(RuntimeError, f, *args, **kwargs)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 397–404why, one step back397 assert e.value.args and "session is unavailable" in e.value.args[0]398399 with app.test_request_context():400 assert flask.session.get("missing_key") is None401 expect_exception(flask.session.__setitem__, "foo", 42)402 expect_exception(flask.session.pop, "foo")403404Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 405–406why, one step back405def test_session_expiration(app, client):406 permanent = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 407–410why, one step back407408 @app.route("/")409 def index():410 flask.session["test"] = 42Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 411why, one step back411 flask.session.permanent = permanentMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 412–415why, one step back412 return ""413414 @app.route("/test")415 def test():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 416why, one step back416 return text_type(flask.session.permanent)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 417–420why, one step back417418 rv = client.get("/")419 assert "set-cookie" in rv.headers420 match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 421–425why, one step back421 expires = parse_date(match.group())422 expected = datetime.utcnow() + app.permanent_session_lifetime423 assert expires.year == expected.year424 assert expires.month == expected.month425 assert expires.day == expected.dayMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 426–429why, one step back426427 rv = client.get("/test")428 assert rv.data == b"True"429Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 430why, one step back430 permanent = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 431–433why, one step back431 rv = client.get("/")432 assert "set-cookie" in rv.headers433 match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 434why, one step back434 assert match is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 435–436why, one step back435436Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 437why, one step back437def test_session_stored_last(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 438why, one step back438 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 439why, one step back439 def modify_session(response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 440–450why, one step back440 flask.session["foo"] = 42441 return response442443 @app.route("/")444 def dump_session_contents():445 return repr(flask.session.get("foo"))446447 assert client.get("/").data == b"None"448 assert client.get("/").data == b"42"449450Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 451–453why, one step back451def test_session_special_types(app, client):452 now = datetime.utcnow().replace(microsecond=0)453 the_uuid = uuid.uuid4()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 454–468why, one step back454455 @app.route("/")456 def dump_session_contents():457 flask.session["t"] = (1, 2, 3)458 flask.session["b"] = b"\xff"459 flask.session["m"] = flask.Markup("<html>")460 flask.session["u"] = the_uuid461 flask.session["d"] = now462 flask.session["t_tag"] = {" t": "not-a-tuple"}463 flask.session["di_t_tag"] = {" t__": "not-a-tuple"}464 flask.session["di_tag"] = {" di": "not-a-dict"}465 return "", 204466467 with client:468 client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 469why, one step back469 s = flask.sessionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 470–481why, one step back470 assert s["t"] == (1, 2, 3)471 assert type(s["b"]) == bytes472 assert s["b"] == b"\xff"473 assert type(s["m"]) == flask.Markup474 assert s["m"] == flask.Markup("<html>")475 assert s["u"] == the_uuid476 assert s["d"] == now477 assert s["t_tag"] == {" t": "not-a-tuple"}478 assert s["di_t_tag"] == {" t__": "not-a-tuple"}479 assert s["di_tag"] == {" di": "not-a-dict"}480481Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 482why, one step back482def test_session_cookie_setting(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 483–485why, one step back483 is_permanent = True484485 @app.route("/bump")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 486why, one step back486 def bump():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 487why, one step back487 rv = flask.session["foo"] = flask.session.get("foo", 0) + 1Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 488–489why, one step back488 flask.session.permanent = is_permanent489 return str(rv)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 490–491why, one step back490491 @app.route("/read")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 492why, one step back492 def read():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 493–494why, one step back493 return str(flask.session.get("foo", 0))494Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 495–496why, one step back495 def run_test(expect_header):496 with app.test_client() as c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 497–502why, one step back497 assert c.get("/bump").data == b"1"498 assert c.get("/bump").data == b"2"499 assert c.get("/bump").data == b"3"500501 rv = c.get("/read")502 set_cookie = rv.headers.get("set-cookie")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 503why, one step back503 assert (set_cookie is not None) == expect_headerMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 504–507why, one step back504 assert rv.data == b"3"505506 is_permanent = True507 app.config["SESSION_REFRESH_EACH_REQUEST"] = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 508why, one step back508 run_test(expect_header=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 509–522why, one step back509510 is_permanent = True511 app.config["SESSION_REFRESH_EACH_REQUEST"] = False512 run_test(expect_header=False)513514 is_permanent = False515 app.config["SESSION_REFRESH_EACH_REQUEST"] = True516 run_test(expect_header=False)517518 is_permanent = False519 app.config["SESSION_REFRESH_EACH_REQUEST"] = False520 run_test(expect_header=False)521522Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 523why, one step back523def test_session_vary_cookie(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 524why, one step back524 @app.route("/set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 525why, one step back525 def set_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 526–533why, one step back526 flask.session["test"] = "test"527 return ""528529 @app.route("/get")530 def get():531 return flask.session.get("test")532533 @app.route("/getitem")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 534why, one step back534 def getitem():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 535–537why, one step back535 return flask.session["test"]536537 @app.route("/setdefault")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 538why, one step back538 def setdefault():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 539–541why, one step back539 return flask.session.setdefault("test", "default")540541 @app.route("/vary-cookie-header-set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 542why, one step back542 def vary_cookie_header_set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 543–548why, one step back543 response = flask.Response()544 response.vary.add("Cookie")545 flask.session["test"] = "test"546 return response547548 @app.route("/vary-header-set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 549why, one step back549 def vary_header_set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 550–555why, one step back550 response = flask.Response()551 response.vary.update(("Accept-Encoding", "Accept-Language"))552 flask.session["test"] = "test"553 return response554555 @app.route("/no-vary-header")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 556why, one step back556 def no_vary_header():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 557–559why, one step back557 return ""558559 def expect(path, header_value="Cookie"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 560why, one step back560 rv = client.get(path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 561why, one step back561Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 562–563why, one step back562 if header_value:563 # The 'Vary' key should exist in the headers only once.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 564–577why, one step back564 assert len(rv.headers.get_all("Vary")) == 1565 assert rv.headers["Vary"] == header_value566 else:567 assert "Vary" not in rv.headers568569 expect("/set")570 expect("/get")571 expect("/getitem")572 expect("/setdefault")573 expect("/vary-cookie-header-set")574 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")575 expect("/no-vary-header", None)576577Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 578–579why, one step back578def test_flashes(app, req_ctx):579 assert not flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 580why, one step back580 flask.flash("Zap")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 581why, one step back581 flask.session.modified = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 582why, one step back582 flask.flash("Zip")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 583why, one step back583 assert flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 584–586why, one step back584 assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]585586Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 587–592why, one step back587def test_extended_flashing(app):588 # Be sure app.testing=True below, else tests can fail silently.589 #590 # Specifically, if app.testing is not set to True, the AssertionErrors591 # in the view functions will cause a 500 response to the test client592 # instead of propagating exceptions.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 593–602why, one step back593594 @app.route("/")595 def index():596 flask.flash(u"Hello World")597 flask.flash(u"Hello World", "error")598 flask.flash(flask.Markup(u"<em>Testing</em>"), "warning")599 return ""600601 @app.route("/test/")602 def test():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 603why, one step back603 messages = flask.get_flashed_messages()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 604–611why, one step back604 assert list(messages) == [605 u"Hello World",606 u"Hello World",607 flask.Markup(u"<em>Testing</em>"),608 ]609 return ""610611 @app.route("/test_with_categories/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 612–614why, one step back612 def test_with_categories():613 messages = flask.get_flashed_messages(with_categories=True)614 assert len(messages) == 3Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 615–622why, one step back615 assert list(messages) == [616 ("message", u"Hello World"),617 ("error", u"Hello World"),618 ("warning", flask.Markup(u"<em>Testing</em>")),619 ]620 return ""621622 @app.route("/test_filter/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 623why, one step back623 def test_filter():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 624–630why, one step back624 messages = flask.get_flashed_messages(625 category_filter=["message"], with_categories=True626 )627 assert list(messages) == [("message", u"Hello World")]628 return ""629630 @app.route("/test_filters/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 631why, one step back631 def test_filters():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 632–641why, one step back632 messages = flask.get_flashed_messages(633 category_filter=["message", "warning"], with_categories=True634 )635 assert list(messages) == [636 ("message", u"Hello World"),637 ("warning", flask.Markup(u"<em>Testing</em>")),638 ]639 return ""640641 @app.route("/test_filters_without_returning_categories/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 642why, one step back642 def test_filters2():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 643why, one step back643 messages = flask.get_flashed_messages(category_filter=["message", "warning"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 644why, one step back644 assert len(messages) == 2Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 645–648why, one step back645 assert messages[0] == u"Hello World"646 assert messages[1] == flask.Markup(u"<em>Testing</em>")647 return ""648Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 649why, one step back649 # Create new test client on each test to clean flashed messages.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 650–667why, one step back650651 client = app.test_client()652 client.get("/")653 client.get("/test_with_categories/")654655 client = app.test_client()656 client.get("/")657 client.get("/test_filter/")658659 client = app.test_client()660 client.get("/")661 client.get("/test_filters/")662663 client = app.test_client()664 client.get("/")665 client.get("/test_filters_without_returning_categories/")666667Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 668why, one step back668def test_request_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 669–692why, one step back669 evts = []670671 @app.before_request672 def before_request():673 evts.append("before")674675 @app.after_request676 def after_request(response):677 response.data += b"|after"678 evts.append("after")679 return response680681 @app.route("/")682 def index():683 assert "before" in evts684 assert "after" not in evts685 return "request"686687 assert "after" not in evts688 rv = client.get("/").data689 assert "after" in evts690 assert rv == b"request|after"691692Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 693why, one step back693def test_request_preprocessing_early_return(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 694–696why, one step back694 evts = []695696 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 697–698why, one step back697 def before_request1():698 evts.append(1)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 699–700why, one step back699700 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 701–703why, one step back701 def before_request2():702 evts.append(2)703 return "hello"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 704–705why, one step back704705 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 706–708why, one step back706 def before_request3():707 evts.append(3)708 return "bye"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 709–712why, one step back709710 @app.route("/")711 def index():712 evts.append("index")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 713why, one step back713 return "damnit"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 714–716why, one step back714715 rv = client.get("/").data.strip()716 assert rv == b"hello"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 717why, one step back717 assert evts == [1, 2]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 718–719why, one step back718719Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 720why, one step back720def test_after_request_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 721–722why, one step back721 @app.route("/")722 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 723–724why, one step back723 @flask.after_this_request724 def foo(response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 725why, one step back725 response.headers["X-Foo"] = "a header"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 726why, one step back726 return responseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 727–730why, one step back727728 return "Test"729730 resp = client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 731why, one step back731 assert resp.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 732–734why, one step back732 assert resp.headers["X-Foo"] == "a header"733734Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 735why, one step back735def test_teardown_request_handler(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 736–752why, one step back736 called = []737738 @app.teardown_request739 def teardown_request(exc):740 called.append(True)741 return "Ignored"742743 @app.route("/")744 def root():745 return "Response"746747 rv = client.get("/")748 assert rv.status_code == 200749 assert b"Response" in rv.data750 assert len(called) == 1751752Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 753why, one step back753def test_teardown_request_handler_debug_mode(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 754–770why, one step back754 called = []755756 @app.teardown_request757 def teardown_request(exc):758 called.append(True)759 return "Ignored"760761 @app.route("/")762 def root():763 return "Response"764765 rv = client.get("/")766 assert rv.status_code == 200767 assert b"Response" in rv.data768 assert len(called) == 1769770Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 771why, one step back771def test_teardown_request_handler_error(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 772–775why, one step back772 called = []773 app.testing = False774775 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 776why, one step back776 def teardown_request1(exc):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 777–783why, one step back777 assert type(exc) == ZeroDivisionError778 called.append(True)779 # This raises a new error and blows away sys.exc_info(), so we can780 # test that all teardown_requests get passed the same original781 # exception.782 try:783 raise TypeError()Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 784why, one step back784 except Exception:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 785–787why, one step back785 pass786787 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 788why, one step back788 def teardown_request2(exc):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 789–795why, one step back789 assert type(exc) == ZeroDivisionError790 called.append(True)791 # This raises a new error and blows away sys.exc_info(), so we can792 # test that all teardown_requests get passed the same original793 # exception.794 try:795 raise TypeError()Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 796why, one step back796 except Exception:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 797–799why, one step back797 pass798799 @app.route("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 800why, one step back800 def fails():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 801–805why, one step back801 1 // 0802803 rv = client.get("/")804 assert rv.status_code == 500805 assert b"Internal Server Error" in rv.dataMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 806why, one step back806 assert len(called) == 2Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 807–808why, one step back807808Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 809why, one step back809def test_before_after_request_order(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 810–812why, one step back810 called = []811812 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 813–814why, one step back813 def before1():814 called.append(1)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 815–816why, one step back815816 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 817–818why, one step back817 def before2():818 called.append(2)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 819–820why, one step back819820 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 821–822why, one step back821 def after1(response):822 called.append(4)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 823–825why, one step back823 return response824825 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 826–827why, one step back826 def after2(response):827 called.append(3)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 828–830why, one step back828 return response829830 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 831–832why, one step back831 def finish1(exc):832 called.append(6)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 833–834why, one step back833834 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 835–836why, one step back835 def finish2(exc):836 called.append(5)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 837–843why, one step back837838 @app.route("/")839 def index():840 return "42"841842 rv = client.get("/")843 assert rv.data == b"42"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 844why, one step back844 assert called == [1, 2, 3, 4, 5, 6]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 845–846why, one step back845846Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 847why, one step back847def test_error_handling(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 848–850why, one step back848 app.testing = False849850 @app.errorhandler(404)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 851why, one step back851 def not_found(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 852–857why, one step back852 return "not found", 404853854 @app.errorhandler(500)855 def internal_server_error(e):856 return "internal server error", 500857Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 858–859why, one step back858 @app.errorhandler(Forbidden)859 def forbidden(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 860–866why, one step back860 return "forbidden", 403861862 @app.route("/")863 def index():864 flask.abort(404)865866 @app.route("/error")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 867why, one step back867 def error():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 868–870why, one step back868 1 // 0869870 @app.route("/forbidden")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 871why, one step back871 def error2():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 872–880why, one step back872 flask.abort(403)873874 rv = client.get("/")875 assert rv.status_code == 404876 assert rv.data == b"not found"877 rv = client.get("/error")878 assert rv.status_code == 500879 assert b"internal server error" == rv.data880 rv = client.get("/forbidden")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 881why, one step back881 assert rv.status_code == 403Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 882–884why, one step back882 assert b"forbidden" == rv.data883884Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 885–886why, one step back885def test_error_handler_unknown_code(app):886 with pytest.raises(KeyError) as exc_info:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 887–891why, one step back887 app.register_error_handler(999, lambda e: ("999", 999))888889 assert "Use a subclass" in exc_info.value.args[0]890891Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 892why, one step back892def test_error_handling_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 893–903why, one step back893 app.testing = False894895 @app.errorhandler(500)896 def internal_server_error(e):897 return "internal server error", 500898899 @app.route("/")900 def broken_func():901 1 // 0902903 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 904why, one step back904 def after_request(resp):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 905why, one step back905 resp.mimetype = "text/x-special"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 906why, one step back906 return respMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 907–912why, one step back907908 resp = client.get("/")909 assert resp.mimetype == "text/x-special"910 assert resp.data == b"internal server error"911912Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 913why, one step back913def test_baseexception_error_handling(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 914–917why, one step back914 app.testing = False915916 @app.route("/")917 def broken_func():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 918why, one step back918 raise KeyboardInterrupt()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 919why, one step back919Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 920why, one step back920 with pytest.raises(KeyboardInterrupt):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 921–922why, one step back921 client.get("/")922Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 923–925why, one step back923 ctx = flask._request_ctx_stack.top924 assert ctx.preserved925 assert type(ctx._preserved_exc) is KeyboardInterruptMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 926–927why, one step back926927Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 928why, one step back928def test_before_request_and_routing_errors(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 929why, one step back929 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 930why, one step back930 def attach_something():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 931–933why, one step back931 flask.g.something = "value"932933 @app.errorhandler(404)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 934–935why, one step back934 def return_something(error):935 return flask.g.something, 404Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 936–941why, one step back936937 rv = client.get("/")938 assert rv.status_code == 404939 assert rv.data == b"value"940941Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 942–943why, one step back942def test_user_error_handling(app, client):943 class MyException(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 944–945why, one step back944 pass945Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 946–948why, one step back946 @app.errorhandler(MyException)947 def handle_my_exception(e):948 assert isinstance(e, MyException)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 949–952why, one step back949 return "42"950951 @app.route("/")952 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 953why, one step back953 raise MyException()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 954–957why, one step back954955 assert client.get("/").data == b"42"956957Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 958–959why, one step back958def test_http_error_subclass_handling(app, client):959 class ForbiddenSubclass(Forbidden):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 960–961why, one step back960 pass961Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 962why, one step back962 @app.errorhandler(ForbiddenSubclass)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 963why, one step back963 def handle_forbidden_subclass(e):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 964why, one step back964 assert isinstance(e, ForbiddenSubclass)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 965–966why, one step back965 return "banana"966Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 967why, one step back967 @app.errorhandler(403)Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 968why, one step back968 def handle_403(e):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 969–970why, one step back969 assert not isinstance(e, ForbiddenSubclass)970 assert isinstance(e, Forbidden)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 971–973why, one step back971 return "apple"972973 @app.route("/1")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 974–975why, one step back974 def index1():975 raise ForbiddenSubclass()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 976–981why, one step back976977 @app.route("/2")978 def index2():979 flask.abort(403)980981 @app.route("/3")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 982–983why, one step back982 def index3():983 raise Forbidden()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 984–989why, one step back984985 assert client.get("/1").data == b"banana"986 assert client.get("/2").data == b"apple"987 assert client.get("/3").data == b"apple"988989Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 990–991why, one step back990def test_errorhandler_precedence(app, client):991 class E1(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 992–993why, one step back992 pass993Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 994why, one step back994 class E2(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 995–996why, one step back995 pass996Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 997why, one step back997 class E3(E1, E2):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 998–999why, one step back998 pass999Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1000–1001why, one step back1000 @app.errorhandler(E2)1001 def handle_e2(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1002–1003why, one step back1002 return "E2"1003Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1004–1005why, one step back1004 @app.errorhandler(Exception)1005 def handle_exception(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1006–1008why, one step back1006 return "Exception"10071008 @app.route("/E1")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1009–1010why, one step back1009 def raise_e1():1010 raise E1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1011–1012why, one step back10111012 @app.route("/E3")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1013–1014why, one step back1013 def raise_e3():1014 raise E3Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1015–1022why, one step back10151016 rv = client.get("/E1")1017 assert rv.data == b"Exception"10181019 rv = client.get("/E3")1020 assert rv.data == b"E2"10211022Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1023why, one step back1023def test_trapping_of_bad_request_key_errors(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1024–1028why, one step back1024 @app.route("/key")1025 def fail():1026 flask.request.form["missing_key"]10271028 @app.route("/abort")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 1029–1030why, one step back1029 def allow_abort():1030 flask.abort(400)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1031–1038why, one step back10311032 rv = client.get("/key")1033 assert rv.status_code == 4001034 assert b"missing_key" not in rv.data1035 rv = client.get("/abort")1036 assert rv.status_code == 40010371038 app.debug = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1039why, one step back1039 with pytest.raises(KeyError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1040why, one step back1040 client.get("/key")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1041why, one step back1041 assert e.errisinstance(BadRequest)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1042–1047why, one step back1042 assert "missing_key" in e.value.get_description()1043 rv = client.get("/abort")1044 assert rv.status_code == 40010451046 app.debug = False1047 app.config["TRAP_BAD_REQUEST_ERRORS"] = TrueMerge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 1048why, one step back1048 with pytest.raises(KeyError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1049why, one step back1049 client.get("/key")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 1050why, one step back1050 with pytest.raises(BadRequest):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1051–1053why, one step back1051 client.get("/abort")10521053Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1054why, one step back1054def test_trapping_of_all_http_exceptions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1055–1060why, one step back1055 app.config["TRAP_HTTP_EXCEPTIONS"] = True10561057 @app.route("/fail")1058 def fail():1059 flask.abort(404)1060Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1061why, one step back1061 with pytest.raises(NotFound):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1062–1064why, one step back1062 client.get("/fail")10631064Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1065why, one step back1065def test_error_handler_after_processor_error(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1066–1069why, one step back1066 app.testing = False10671068 @app.before_request1069 def before_request():Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1070why, one step back1070 if _trigger == "before":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1071–1074why, one step back1071 1 // 010721073 @app.after_request1074 def after_request(response):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1075why, one step back1075 if _trigger == "after":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1076–1086why, one step back1076 1 // 01077 return response10781079 @app.route("/")1080 def index():1081 return "Foo"10821083 @app.errorhandler(500)1084 def internal_server_error(e):1085 return "Hello Server Error", 5001086Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1087why, one step back1087 for _trigger in "before", "after":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1088why, one step back1088 rv = client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1089why, one step back1089 assert rv.status_code == 500Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1090–1092why, one step back1090 assert rv.data == b"Hello Server Error"10911092Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1093–1094why, one step back1093def test_enctype_debug_helper(app, client):1094 from flask.debughelpers import DebugFilesKeyErrorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1095–1101why, one step back10951096 app.debug = True10971098 @app.route("/fail", methods=["POST"])1099 def index():1100 return flask.request.files["foo"].filename1101Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1102–1104why, one step back1102 # with statement is important because we leave an exception on the1103 # stack otherwise and we want to ensure that this is not the case1104 # to not negatively affect other tests.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1105why, one step back1105 with client:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1106why, one step back1106 with pytest.raises(DebugFilesKeyError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1107–1108why, one step back1107 client.post("/fail", data={"foo": "index.txt"})1108 assert "no file contents were transmitted" in str(e.value)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1109why, one step back1109 assert 'This was submitted: "index.txt"' in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1110–1111why, one step back11101111Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1112why, one step back1112def test_response_types(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1113why, one step back1113 @app.route("/text")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1114why, one step back1114 def from_text():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1115–1117why, one step back1115 return u"Hällo Wörld"11161117 @app.route("/bytes")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1118why, one step back1118 def from_bytes():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1119–1121why, one step back1119 return u"Hällo Wörld".encode("utf-8")11201121 @app.route("/full_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1122why, one step back1122 def from_full_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1123–1129why, one step back1123 return (1124 "Meh",1125 400,1126 {"X-Foo": "Testing", "Content-Type": "text/plain; charset=utf-8"},1127 )11281129 @app.route("/text_headers")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1130why, one step back1130 def from_text_headers():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1131–1133why, one step back1131 return "Hello", {"X-Foo": "Test", "Content-Type": "text/plain; charset=utf-8"}11321133 @app.route("/text_status")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1134why, one step back1134 def from_text_status():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1135–1137why, one step back1135 return "Hi, status!", 40011361137 @app.route("/response_headers")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1138why, one step back1138 def from_response_headers():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1139–1144why, one step back1139 return (1140 flask.Response("Hello world", 404, {"X-Foo": "Baz"}),1141 {"X-Foo": "Bar", "X-Bar": "Foo"},1142 )11431144 @app.route("/response_status")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1145why, one step back1145 def from_response_status():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1146–1148why, one step back1146 return app.response_class("Hello world", 400), 50011471148 @app.route("/wsgi")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1149–1150why, one step back1149 def from_wsgi():1150 return NotFound()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1151why, one step back1151Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1152why, one step back1152 @app.route("/dict")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
lines 1153–1154why, one step back1153 def from_dict():1154 return {"foo": "bar"}, 201Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1155why, one step back1155Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1156–1157why, one step back1156 assert client.get("/text").data == u"Hällo Wörld".encode("utf-8")1157 assert client.get("/bytes").data == u"Hällo Wörld".encode("utf-8")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
line 1158why, one step back1158Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1159–1188why, one step back1159 rv = client.get("/full_tuple")1160 assert rv.data == b"Meh"1161 assert rv.headers["X-Foo"] == "Testing"1162 assert rv.status_code == 4001163 assert rv.mimetype == "text/plain"11641165 rv = client.get("/text_headers")1166 assert rv.data == b"Hello"1167 assert rv.headers["X-Foo"] == "Test"1168 assert rv.status_code == 2001169 assert rv.mimetype == "text/plain"11701171 rv = client.get("/text_status")1172 assert rv.data == b"Hi, status!"1173 assert rv.status_code == 4001174 assert rv.mimetype == "text/html"11751176 rv = client.get("/response_headers")1177 assert rv.data == b"Hello world"1178 assert rv.headers.getlist("X-Foo") == ["Baz", "Bar"]1179 assert rv.headers["X-Bar"] == "Foo"1180 assert rv.status_code == 40411811182 rv = client.get("/response_status")1183 assert rv.data == b"Hello world"1184 assert rv.status_code == 50011851186 rv = client.get("/wsgi")1187 assert b"Not Found" in rv.data1188 assert rv.status_code == 404Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
line 1189why, one step back1189Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1190why, one step back1190 rv = client.get("/dict")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
lines 1191–1192why, one step back1191 assert rv.json == {"foo": "bar"}1192 assert rv.status_code == 201Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1193–1194why, one step back11931194Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1195why, one step back1195def test_response_type_errors():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1196–1199why, one step back1196 app = flask.Flask(__name__)1197 app.testing = True11981199 @app.route("/none")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1200why, one step back1200 def from_none():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1201–1203why, one step back1201 pass12021203 @app.route("/small_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1204why, one step back1204 def from_small_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1205–1207why, one step back1205 return ("Hello",)12061207 @app.route("/large_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1208why, one step back1208 def from_large_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1209–1211why, one step back1209 return "Hello", 234, {"X-Foo": "Bar"}, "???"12101211 @app.route("/bad_type")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1212–1213why, one step back1212 def from_bad_type():1213 return TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1214–1215why, one step back12141215 @app.route("/bad_wsgi")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1216–1217why, one step back1216 def from_bad_wsgi():1217 return lambda: NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1218–1222why, one step back12181219 c = app.test_client()12201221 with pytest.raises(TypeError) as e:1222 c.get("/none")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1223why, one step back1223 assert "returned None" in str(e.value)Merge pull request #3498 from raymond-devries/3445-traceback-for-noneDavid Lordbefore adoptiona3e4395
line 1224why, one step back1224 assert "from_none" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1225–1227why, one step back12251226 with pytest.raises(TypeError) as e:1227 c.get("/small_tuple")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1228why, one step back1228 assert "tuple must have the form" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1229–1233why, one step back12291230 pytest.raises(TypeError, c.get, "/large_tuple")12311232 with pytest.raises(TypeError) as e:1233 c.get("/bad_type")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1234why, one step back1234 assert "it was a bool" in str(e.value)Merge pull request #3235 from johnzeringue/better-return-type-errorDavid Lordbefore adoption52f9aa7
line 1235why, one step back1235Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1236–1238why, one step back1236 pytest.raises(TypeError, c.get, "/bad_wsgi")12371238Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1239–1240why, one step back1239def test_make_response(app, req_ctx):1240 rv = flask.make_response()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1241–1255why, one step back1241 assert rv.status_code == 2001242 assert rv.data == b""1243 assert rv.mimetype == "text/html"12441245 rv = flask.make_response("Awesome")1246 assert rv.status_code == 2001247 assert rv.data == b"Awesome"1248 assert rv.mimetype == "text/html"12491250 rv = flask.make_response("W00t", 404)1251 assert rv.status_code == 4041252 assert rv.data == b"W00t"1253 assert rv.mimetype == "text/html"12541255Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1256why, one step back1256def test_make_response_with_response_instance(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1257–1258why, one step back1257 rv = flask.make_response(flask.jsonify({"msg": "W00t"}), 400)1258 assert rv.status_code == 400Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1259why, one step back1259 assert rv.data == b'{"msg":"W00t"}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1260–1276why, one step back1260 assert rv.mimetype == "application/json"12611262 rv = flask.make_response(flask.Response(""), 400)1263 assert rv.status_code == 4001264 assert rv.data == b""1265 assert rv.mimetype == "text/html"12661267 rv = flask.make_response(1268 flask.Response("", headers={"Content-Type": "text/html"}),1269 400,1270 [("X-Foo", "bar")],1271 )1272 assert rv.status_code == 4001273 assert rv.headers["Content-Type"] == "text/html"1274 assert rv.headers["X-Foo"] == "bar"12751276Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1277–1279why, one step back1277def test_jsonify_no_prettyprint(app, req_ctx):1278 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})1279 compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1280–1282why, one step back1280 uncompressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}12811282 rv = flask.make_response(flask.jsonify(uncompressed_msg), 200)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1283why, one step back1283 assert rv.data == compressed_msgMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1284–1285why, one step back12841285Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1286–1288why, one step back1286def test_jsonify_prettyprint(app, req_ctx):1287 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})1288 compressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1289why, one step back1289 pretty_response = (Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1290why, one step back1290 b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1291–1293why, one step back1291 )12921293 rv = flask.make_response(flask.jsonify(compressed_msg), 200)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1294why, one step back1294 assert rv.data == pretty_responseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1295–1296why, one step back12951296Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1297why, one step back1297def test_jsonify_mimetype(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1298–1302why, one step back1298 app.config.update({"JSONIFY_MIMETYPE": "application/vnd.api+json"})1299 msg = {"msg": {"submsg": "W00t"}}1300 rv = flask.make_response(flask.jsonify(msg), 200)1301 assert rv.mimetype == "application/vnd.api+json"1302Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
lines 1303–1306why, one step back13031304@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")1305def test_json_dump_dataclass(app, req_ctx):1306 from dataclasses import make_dataclassMerge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1307why, one step back1307Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
lines 1308–1311why, one step back1308 Data = make_dataclass("Data", [("name", str)])1309 value = flask.json.dumps(Data("Flask"), app=app)1310 value = flask.json.loads(value, app=app)1311 assert value == {"name": "Flask"}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1312why, one step back1312Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1313why, one step back1313Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1314why, one step back1314def test_jsonify_args_and_kwargs_check(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1315–1319why, one step back1315 with pytest.raises(TypeError) as e:1316 flask.jsonify("fake args", kwargs="fake")1317 assert "behavior undefined" in str(e.value)13181319Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1320why, one step back1320def test_url_generation(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1321why, one step back1321 @app.route("/hello/<name>", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1322why, one step back1322 def hello():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1323–1331why, one step back1323 pass13241325 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1326 assert (1327 flask.url_for("hello", name="test x", _external=True)1328 == "http://localhost/hello/test%20x"1329 )13301331Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1332–1333why, one step back1332def test_build_error_handler(app):1333 # Test base case, a URL which results in a BuildError.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1334–1336why, one step back1334 with app.test_request_context():1335 pytest.raises(BuildError, flask.url_for, "spam")1336Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1337why, one step back1337 # Verify the error is re-raised if not the current exception.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1338why, one step back1338 try:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1339why, one step back1339 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1340why, one step back1340 flask.url_for("spam")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1341–1342why, one step back1341 except BuildError as err:1342 error = errMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1343–1344why, one step back1343 try:1344 raise RuntimeError("Test case where BuildError is not current.")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1345why, one step back1345 except RuntimeError:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1346–1347why, one step back1346 pytest.raises(BuildError, app.handle_url_build_error, error, "spam", {})1347Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1348why, one step back1348 # Test a custom handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1349why, one step back1349 def handler(error, endpoint, values):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1350why, one step back1350 # Just a test.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1351–1352why, one step back1351 return "/test_handler/"1352Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1353why, one step back1353 app.url_build_error_handlers.append(handler)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1354–1357why, one step back1354 with app.test_request_context():1355 assert flask.url_for("spam") == "/test_handler/"13561357Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1358–1361why, one step back1358def test_build_error_handler_reraise(app):1359 # Test a custom handler which reraises the BuildError1360 def handler_raises_build_error(error, endpoint, values):1361 raise errorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1362why, one step back1362Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1363why, one step back1363 app.url_build_error_handlers.append(handler_raises_build_error)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1364–1368why, one step back13641365 with app.test_request_context():1366 pytest.raises(BuildError, flask.url_for, "not.existing")13671368Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1369–1370why, one step back1369def test_url_for_passes_special_values_to_build_error_handler(app):1370 @app.url_build_error_handlers.appendMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1371why, one step back1371 def handler(error, endpoint, values):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1372why, one step back1372 assert values == {Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1373–1383why, one step back1373 "_external": False,1374 "_anchor": None,1375 "_method": None,1376 "_scheme": None,1377 }1378 return "handled"13791380 with app.test_request_context():1381 flask.url_for("/")13821383Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1384why, one step back1384def test_static_files(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1385–1392why, one step back1385 rv = client.get("/static/index.html")1386 assert rv.status_code == 2001387 assert rv.data.strip() == b"<h1>Hello World!</h1>"1388 with app.test_request_context():1389 assert flask.url_for("static", filename="index.html") == "/static/index.html"1390 rv.close()13911392Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1393why, one step back1393def test_static_url_path():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1394–1403why, one step back1394 app = flask.Flask(__name__, static_url_path="/foo")1395 app.testing = True1396 rv = app.test_client().get("/foo/index.html")1397 assert rv.status_code == 2001398 rv.close()13991400 with app.test_request_context():1401 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14021403Merge pull request #3182 from qil026/issue-3134-url-joinDavid Lordbefore adoptiondbd3840
lines 1404–1414why, one step back1404def test_static_url_path_with_ending_slash():1405 app = flask.Flask(__name__, static_url_path="/foo/")1406 app.testing = True1407 rv = app.test_client().get("/foo/index.html")1408 assert rv.status_code == 2001409 rv.close()14101411 with app.test_request_context():1412 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14131414Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
line 1415why, one step back1415def test_static_url_empty_path(app):Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1416–1417why, one step back1416 app = flask.Flask(__name__, static_folder="", static_url_path="")1417 rv = app.test_client().open("/static/index.html", method="GET")Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
lines 1418–1422why, one step back1418 assert rv.status_code == 2001419 rv.close()142014211422def test_static_url_empty_path_default(app):Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1423–1424why, one step back1423 app = flask.Flask(__name__, static_folder="")1424 rv = app.test_client().open("/static/index.html", method="GET")Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
lines 1425–1428why, one step back1425 assert rv.status_code == 2001426 rv.close()14271428Merge remote-tracking branch 'origin/1.1.x'David Lordbefore adoption64ba434
lines 1429–1439why, one step back1429def test_static_folder_with_ending_slash():1430 app = flask.Flask(__name__, static_folder="static/")14311432 @app.route("/<path:path>")1433 def catch_all(path):1434 return path14351436 rv = app.test_client().get("/catch/all")1437 assert rv.data == b"catch/all"14381439Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1440why, one step back1440def test_static_route_with_host_matching():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1441–1448why, one step back1441 app = flask.Flask(__name__, host_matching=True, static_host="example.com")1442 c = app.test_client()1443 rv = c.get("http://example.com/static/index.html")1444 assert rv.status_code == 2001445 rv.close()1446 with app.test_request_context():1447 rv = flask.url_for("static", filename="index.html", _external=True)1448 assert rv == "http://example.com/static/index.html"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1449why, one step back1449 # Providing static_host without host_matching=True should error.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1450–1451why, one step back1450 with pytest.raises(Exception):1451 flask.Flask(__name__, static_host="example.com")Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 1452–1453why, one step back1452 # Providing host_matching=True with static_folder1453 # but without static_host should error.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1454why, one step back1454 with pytest.raises(Exception):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1455why, one step back1455 flask.Flask(__name__, host_matching=True)Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 1456–1457why, one step back1456 # Providing host_matching=True without static_host1457 # but with static_folder=None should not error.Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1458why, one step back1458 flask.Flask(__name__, host_matching=True, static_folder=None)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1459–1460why, one step back14591460Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1461why, one step back1461def test_request_locals():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1462why, one step back1462 assert repr(flask.g) == "<LocalProxy unbound>"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1463why, one step back1463 assert not flask.gMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1464–1465why, one step back14641465Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1466why, one step back1466def test_server_name_subdomain():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1467–1471why, one step back1467 app = flask.Flask(__name__, subdomain_matching=True)1468 client = app.test_client()14691470 @app.route("/")1471 def index():Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1472why, one step back1472 return "default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1473–1474why, one step back14731474 @app.route("/", subdomain="foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1475why, one step back1475 def subdomain():Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1476why, one step back1476 return "subdomain"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1477why, one step back1477Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1478why, one step back1478 app.config["SERVER_NAME"] = "dev.local:5000"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1479why, one step back1479 rv = client.get("/")Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1480why, one step back1480 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1481why, one step back1481Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1482–1483why, one step back1482 rv = client.get("/", "http://dev.local:5000")1483 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1484why, one step back1484Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1485–1486why, one step back1485 rv = client.get("/", "https://dev.local:5000")1486 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1487why, one step back1487Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1488–1489why, one step back1488 app.config["SERVER_NAME"] = "dev.local:443"1489 rv = client.get("/", "https://dev.local")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1490why, one step back1490Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1491–1493why, one step back1491 # Werkzeug 1.0 fixes matching https scheme with 443 port1492 if rv.status_code != 404:1493 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1494why, one step back1494Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1495–1500why, one step back1495 app.config["SERVER_NAME"] = "dev.local"1496 rv = client.get("/", "https://dev.local")1497 assert rv.data == b"default"14981499 # suppress Werkzeug 1.0 warning about name mismatch1500 with pytest.warns(None):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1501–1503why, one step back1501 rv = client.get("/", "http://foo.localhost")1502 assert rv.status_code == 4041503Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1504–1505why, one step back1504 rv = client.get("/", "http://foo.dev.local")1505 assert rv.data == b"subdomain"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1506–1507why, one step back15061507Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1508–1509why, one step back1508def test_exception_propagation(app, client):1509 def apprunner(config_key):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1510–1513why, one step back1510 @app.route("/")1511 def index():1512 1 // 01513Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1514–1516why, one step back1514 if config_key is not None:1515 app.config[config_key] = True1516 with pytest.raises(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1517–1520why, one step back1517 client.get("/")1518 else:1519 assert client.get("/").status_code == 5001520Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1521–1524why, one step back1521 # we have to run this test in an isolated thread because if the1522 # debug flag is set to true and an exception happens the context is1523 # not torn down. This causes other tests that run after this fail1524 # when they expect no exception on the stack.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1525why, one step back1525 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1526–1528why, one step back1526 t = Thread(target=apprunner, args=(config_key,))1527 t.start()1528 t.join()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1529–1545why, one step back152915301531@pytest.mark.parametrize("debug", [True, False])1532@pytest.mark.parametrize("use_debugger", [True, False])1533@pytest.mark.parametrize("use_reloader", [True, False])1534@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1535def test_werkzeug_passthrough_errors(1536 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1537):1538 rv = {}15391540 # Mocks werkzeug.serving.run_simple method1541 def run_simple_mock(*args, **kwargs):1542 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15431544 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1545 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptionsMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1546why, one step back1546 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1547–1548why, one step back15471548Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1549why, one step back1549def test_max_content_length(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1550–1552why, one step back1550 app.config["MAX_CONTENT_LENGTH"] = 6415511552 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1553why, one step back1553 def always_first():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1554why, one step back1554 flask.request.form["myfile"]Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1555why, one step back1555 AssertionError()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1556–1557why, one step back15561557 @app.route("/accept", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1558why, one step back1558 def accept_file():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1559why, one step back1559 flask.request.form["myfile"]Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1560why, one step back1560 AssertionError()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1561why, one step back1561Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1562–1563why, one step back1562 @app.errorhandler(413)1563 def catcher(error):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1564–1569why, one step back1564 return "42"15651566 rv = client.post("/accept", data={"myfile": "foo" * 100})1567 assert rv.data == b"42"15681569Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1570–1572why, one step back1570def test_url_processors(app, client):1571 @app.url_defaults1572 def add_language_code(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1573–1577why, one step back1573 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(1574 endpoint, "lang_code"1575 ):1576 values.setdefault("lang_code", flask.g.lang_code)1577Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1578–1579why, one step back1578 @app.url_value_preprocessor1579 def pull_lang_code(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1580–1586why, one step back1580 flask.g.lang_code = values.pop("lang_code", None)15811582 @app.route("/<lang_code>/")1583 def index():1584 return flask.url_for("about")15851586 @app.route("/<lang_code>/about")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1587why, one step back1587 def about():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1588–1590why, one step back1588 return flask.url_for("something_else")15891590 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1591why, one step back1591 def something_else():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1592–1598why, one step back1592 return flask.url_for("about", lang_code="en")15931594 assert client.get("/de/").data == b"/de/about"1595 assert client.get("/de/about").data == b"/foo"1596 assert client.get("/foo").data == b"/en/about"15971598Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1599why, one step back1599def test_inject_blueprint_url_defaults(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1600–1601why, one step back1600 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")1601Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1602–1603why, one step back1602 @bp.url_defaults1603 def bp_defaults(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1604–1606why, one step back1604 values["page"] = "login"16051606 @bp.route("/<page>")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1607why, one step back1607 def view(page):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1608–1609why, one step back1608 pass1609Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1610why, one step back1610 app.register_blueprint(bp)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1611why, one step back1611Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1612why, one step back1612 values = dict()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1613–1614why, one step back1613 app.inject_url_defaults("foo.bar.baz.view", values)1614 expected = dict(page="login")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1615why, one step back1615 assert values == expectedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1616–1619why, one step back16161617 with app.test_request_context("/somepage"):1618 url = flask.url_for("foo.bar.baz.view")1619 expected = "/login"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1620why, one step back1620 assert url == expectedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1621–1622why, one step back16211622Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1623why, one step back1623def test_nonascii_pathinfo(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1624–1631why, one step back1624 @app.route(u"/киртест")1625 def index():1626 return "Hello World!"16271628 rv = client.get(u"/киртест")1629 assert rv.data == b"Hello World!"16301631Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1632why, one step back1632def test_debug_mode_complains_after_first_request(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1633–1638why, one step back1633 app.debug = True16341635 @app.route("/")1636 def index():1637 return "Awesome"1638Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1639why, one step back1639 assert not app.got_first_requestMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1640why, one step back1640 assert client.get("/").data == b"Awesome"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1641why, one step back1641 with pytest.raises(AssertionError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1642–1643why, one step back16421643 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1644why, one step back1644 def broken():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1645–1646why, one step back1645 return "Meh"1646Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1647why, one step back1647 assert "A setup function was called" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1648–1651why, one step back16481649 app.debug = False16501651 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1652why, one step back1652 def working():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1653–1658why, one step back1653 return "Meh"16541655 assert client.get("/foo").data == b"Meh"1656 assert app.got_first_request16571658Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1659why, one step back1659def test_before_first_request_functions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1660–1672why, one step back1660 got = []16611662 @app.before_first_request1663 def foo():1664 got.append(42)16651666 client.get("/")1667 assert got == [42]1668 client.get("/")1669 assert got == [42]1670 assert app.got_first_request16711672Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1673why, one step back1673def test_before_first_request_functions_concurrent(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1674–1677why, one step back1674 got = []16751676 @app.before_first_request1677 def foo():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1678why, one step back1678 time.sleep(0.2)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1679–1680why, one step back1679 got.append(42)1680Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1681why, one step back1681 def get_and_assert():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1682why, one step back1682 client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1683why, one step back1683 assert got == [42]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1684why, one step back1684Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1685–1688why, one step back1685 t = Thread(target=get_and_assert)1686 t.start()1687 get_and_assert()1688 t.join()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1689–1691why, one step back1689 assert app.got_first_request16901691Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1692why, one step back1692def test_routing_redirect_debugging(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1693–1699why, one step back1693 app.debug = True16941695 @app.route("/foo/", methods=["GET", "POST"])1696 def foo():1697 return "success"16981699 with client:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1700why, one step back1700 with pytest.raises(AssertionError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1701why, one step back1701 client.post("/foo", data={})Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1702why, one step back1702 assert "http://localhost/foo/" in str(e.value)Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b
line 1703why, one step back1703 assert "Make sure to directly send your POST-request to this URL" in str(Merge branch '1.0.x'David Lordbefore adoptionb05a685
lines 1704–1705why, one step back1704 e.value1705 )Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1706–1715why, one step back17061707 rv = client.get("/foo", data={}, follow_redirects=True)1708 assert rv.data == b"success"17091710 app.debug = False1711 with client:1712 rv = client.post("/foo", data={}, follow_redirects=True)1713 assert rv.data == b"success"17141715Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1716why, one step back1716def test_route_decorator_custom_endpoint(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1717–1723why, one step back1717 app.debug = True17181719 @app.route("/foo/")1720 def foo():1721 return flask.request.endpoint17221723 @app.route("/bar/", endpoint="bar")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1724why, one step back1724 def for_bar():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1725–1727why, one step back1725 return flask.request.endpoint17261727 @app.route("/bar/123", endpoint="123")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1728why, one step back1728 def for_bar_foo():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1729–1740why, one step back1729 return flask.request.endpoint17301731 with app.test_request_context():1732 assert flask.url_for("foo") == "/foo/"1733 assert flask.url_for("bar") == "/bar/"1734 assert flask.url_for("123") == "/bar/123"17351736 assert client.get("/foo/").data == b"foo"1737 assert client.get("/bar/").data == b"bar"1738 assert client.get("/bar/123").data == b"123"17391740Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1741why, one step back1741def test_preserve_only_once(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1742–1747why, one step back1742 app.debug = True17431744 @app.route("/fail")1745 def fail_func():1746 1 // 01747Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1748why, one step back1748 for _x in range(3):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1749why, one step back1749 with pytest.raises(ZeroDivisionError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1750–1751why, one step back1750 client.get("/fail")1751Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1752–1757why, one step back1752 assert flask._request_ctx_stack.top is not None1753 assert flask._app_ctx_stack.top is not None1754 # implicit appctx disappears too1755 flask._request_ctx_stack.top.pop()1756 assert flask._request_ctx_stack.top is None1757 assert flask._app_ctx_stack.top is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1758–1759why, one step back17581759Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1760why, one step back1760def test_preserve_remembers_exception(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1761why, one step back1761 app.debug = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1762why, one step back1762 errors = []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1763–1768why, one step back17631764 @app.route("/fail")1765 def fail_func():1766 1 // 017671768 @app.route("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1769why, one step back1769 def success_func():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1770–1772why, one step back1770 return "Okay"17711772 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1773–1774why, one step back1773 def teardown_handler(exc):1774 errors.append(exc)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1775why, one step back1775Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1776–1777why, one step back1776 # After this failure we did not yet call the teardown handler1777 with pytest.raises(ZeroDivisionError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1778why, one step back1778 client.get("/fail")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1779why, one step back1779 assert errors == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1780why, one step back1780Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1781why, one step back1781 # But this request triggers it, and it's an errorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1782why, one step back1782 client.get("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1783–1784why, one step back1783 assert len(errors) == 21784 assert isinstance(errors[0], ZeroDivisionError)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1785why, one step back1785Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1786why, one step back1786 # At this point another request does nothing.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1787why, one step back1787 client.get("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1788–1789why, one step back1788 assert len(errors) == 31789 assert errors[1] is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1790–1791why, one step back17901791Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1792why, one step back1792def test_get_method_on_g(app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1793–1794why, one step back1793 assert flask.g.get("x") is None1794 assert flask.g.get("x", 11) == 11Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1795why, one step back1795 flask.g.x = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1796why, one step back1796 assert flask.g.get("x") == 42Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1797why, one step back1797 assert flask.g.x == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1798–1799why, one step back17981799Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1800–1802why, one step back1800def test_g_iteration_protocol(app_ctx):1801 flask.g.foo = 231802 flask.g.bar = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1803–1807why, one step back1803 assert "foo" in flask.g1804 assert "foos" not in flask.g1805 assert sorted(flask.g) == ["bar", "foo"]18061807Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1808why, one step back1808def test_subdomain_basic_support():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1809–1813why, one step back1809 app = flask.Flask(__name__, subdomain_matching=True)1810 app.config["SERVER_NAME"] = "localhost.localdomain"1811 client = app.test_client()18121813 @app.route("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1814why, one step back1814 def normal_index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1815–1817why, one step back1815 return "normal index"18161817 @app.route("/", subdomain="test")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1818why, one step back1818 def test_index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1819–1827why, one step back1819 return "test index"18201821 rv = client.get("/", "http://localhost.localdomain/")1822 assert rv.data == b"normal index"18231824 rv = client.get("/", "http://test.localhost.localdomain/")1825 assert rv.data == b"test index"18261827Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1828why, one step back1828def test_subdomain_matching():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1829–1840why, one step back1829 app = flask.Flask(__name__, subdomain_matching=True)1830 client = app.test_client()1831 app.config["SERVER_NAME"] = "localhost.localdomain"18321833 @app.route("/", subdomain="<user>")1834 def index(user):1835 return "index for %s" % user18361837 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1838 assert rv.data == b"index for mitsuhiko"18391840Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1841why, one step back1841def test_subdomain_matching_with_ports():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1842–1854why, one step back1842 app = flask.Flask(__name__, subdomain_matching=True)1843 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1844 client = app.test_client()18451846 @app.route("/", subdomain="<user>")1847 def index(user):1848 return "index for %s" % user18491850 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1851 assert rv.data == b"index for mitsuhiko"185218531854@pytest.mark.parametrize("matching", (False, True))Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1855–1856why, one step back1855def test_subdomain_matching_other_name(matching):1856 app = flask.Flask(__name__, subdomain_matching=matching)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1857–1863why, one step back1857 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1858 client = app.test_client()18591860 @app.route("/")1861 def index():1862 return "", 2041863Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1864–1868why, one step back1864 # suppress Werkzeug 0.15 warning about name mismatch1865 with pytest.warns(None):1866 # ip address can't match name1867 rv = client.get("/", "http://127.0.0.1:3000/")1868 assert rv.status_code == 404 if matching else 204Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1869why, one step back1869Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1870why, one step back1870 # allow all subdomains if matching is disabledMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1871–1874why, one step back1871 rv = client.get("/", "http://www.localhost.localdomain:3000/")1872 assert rv.status_code == 404 if matching else 20418731874Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1875why, one step back1875def test_multi_route_rules(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1876–1878why, one step back1876 @app.route("/")1877 @app.route("/<test>/")1878 def index(test="a"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1879why, one step back1879 return testMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1880–1886why, one step back18801881 rv = client.open("/")1882 assert rv.data == b"a"1883 rv = client.open("/b/")1884 assert rv.data == b"b"18851886Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1887–1889why, one step back1887def test_multi_route_class_views(app, client):1888 class View(object):1889 def __init__(self, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1890–1893why, one step back1890 app.add_url_rule("/", "index", self.index)1891 app.add_url_rule("/<test>/", "index", self.index)18921893 def index(self, test="a"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1894why, one step back1894 return testMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1895why, one step back1895Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1896why, one step back1896 _ = View(app)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1897–1902why, one step back1897 rv = client.open("/")1898 assert rv.data == b"a"1899 rv = client.open("/b/")1900 assert rv.data == b"b"19011902Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1903why, one step back1903def test_run_defaults(monkeypatch, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1904–1910why, one step back1904 rv = {}19051906 # Mocks werkzeug.serving.run_simple method1907 def run_simple_mock(*args, **kwargs):1908 rv["result"] = "running..."19091910 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1911why, one step back1911 app.run()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1912–1914why, one step back1912 assert rv["result"] == "running..."19131914Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1915why, one step back1915def test_run_server_port(monkeypatch, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1916–1918why, one step back1916 rv = {}19171918 # Mocks werkzeug.serving.run_simple methodMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1919why, one step back1919 def run_simple_mock(hostname, port, application, *args, **kwargs):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1920–1923why, one step back1920 rv["result"] = "running on %s:%s ..." % (hostname, port)19211922 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1923 hostname, port = "localhost", 8000Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1924why, one step back1924 app.run(hostname, port, debug=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1925–1928why, one step back1925 assert rv["result"] == "running on %s:%s ..." % (hostname, port)192619271928@pytest.mark.parametrize(Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
line 1929why, one step back1929 "host,port,server_name,expect_host,expect_port",Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1930why, one step back1930 (Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
lines 1931–1937why, one step back1931 (None, None, "pocoo.org:8080", "pocoo.org", 8080),1932 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1933 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1934 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1935 ("localhost", 0, "localhost:8080", "localhost", 0),1936 (None, None, "localhost:8080", "localhost", 8080),1937 (None, None, "localhost:0", "localhost", 0),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1938–1939why, one step back1938 ),1939)Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1940–1942why, one step back1940def test_run_from_config(1941 monkeypatch, host, port, server_name, expect_host, expect_port, app1942):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1943–1945why, one step back1943 def run_simple_mock(hostname, port, *args, **kwargs):1944 assert hostname == expect_host1945 assert port == expect_portMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1946–1947why, one step back19461947 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
line 1948why, one step back1948 app.config["SERVER_NAME"] = server_nameMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1949why, one step back1949 app.run(host, port)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1950–1951why, one step back19501951Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1952why, one step back1952def test_max_cookie_size(app, client, recwarn):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1953–1954why, one step back1953 app.config["MAX_COOKIE_SIZE"] = 1001954Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1955–1957why, one step back1955 # outside app context, default to Werkzeug static value,1956 # which is also the default config1957 response = flask.Response()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1958why, one step back1958 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1959why, one step back1959 assert response.max_cookie_size == defaultMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1960why, one step back1960Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1961–1963why, one step back1961 # inside app context, use app config1962 with app.app_context():1963 assert flask.Response().max_cookie_size == 100Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1964–1968why, one step back19641965 @app.route("/")1966 def index():1967 r = flask.Response("", status=204)1968 r.set_cookie("foo", "bar" * 100)Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1969why, one step back1969 return rMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1970–1971why, one step back19701971 client.get("/")Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1972–1973why, one step back1972 assert len(recwarn) == 11973 w = recwarn.pop()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1974–1978why, one step back1974 assert "cookie is too large" in str(w.message)19751976 app.config["MAX_COOKIE_SIZE"] = 019771978 client.get("/")Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1979why, one step back1979 assert len(recwarn) == 0