test_basic.py
This file
Path
tests/test_basic.py
1,959 lines · 52.5 KiB · Python
Last changed by
remove unused module docstringsDavid Lordbefore adoptionf2f027d
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
line 1why, one step back1import reMerge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
line 2why, one step back2import sysMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 3–9why, one step back3import time4import uuid5from datetime import datetime6from threading import Thread78import pytest9import werkzeug.servingMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 10–12why, one step back10from werkzeug.exceptions import BadRequest11from werkzeug.exceptions import Forbidden12from werkzeug.exceptions import NotFoundMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 13–19why, one step back13from werkzeug.http import parse_date14from werkzeug.routing import BuildError1516import flask171819def test_options_work(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 20–28why, one step back20 @app.route("/", methods=["GET", "POST"])21 def index():22 return "Hello World"2324 rv = client.open("/", method="OPTIONS")25 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]26 assert rv.data == b""2728Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 29why, one step back29def test_options_on_multiple_rules(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 30–34why, one step back30 @app.route("/", methods=["GET", "POST"])31 def index():32 return "Hello World"3334 @app.route("/", methods=["PUT"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 35why, one step back35 def index_put():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 36–41why, one step back36 return "Aha!"3738 rv = client.open("/", method="OPTIONS")39 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]4041Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 42why, one step back42def test_provide_automatic_options_attr():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 43–47why, one step back43 app = flask.Flask(__name__)4445 def index():46 return "Hello World!"47Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 48why, one step back48 index.provide_automatic_options = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 49–57why, one step back49 app.route("/")(index)50 rv = app.test_client().open("/", method="OPTIONS")51 assert rv.status_code == 4055253 app = flask.Flask(__name__)5455 def index2():56 return "Hello World!"57Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 58why, one step back58 index2.provide_automatic_options = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 59–63why, one step back59 app.route("/", methods=["OPTIONS"])(index2)60 rv = app.test_client().open("/", method="OPTIONS")61 assert sorted(rv.allow) == ["OPTIONS"]6263Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 64why, one step back64def test_provide_automatic_options_kwarg(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 65–71why, one step back65 def index():66 return flask.request.method6768 def more():69 return flask.request.method7071 app.add_url_rule("/", view_func=index, provide_automatic_options=False)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 72why, one step back72 app.add_url_rule(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 73–83why, one step back73 "/more",74 view_func=more,75 methods=["GET", "POST"],76 provide_automatic_options=False,77 )78 assert client.get("/").data == b"GET"7980 rv = client.post("/")81 assert rv.status_code == 40582 assert sorted(rv.allow) == ["GET", "HEAD"]83Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 84why, one step back84 rv = client.open("/", method="OPTIONS")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 85–96why, one step back85 assert rv.status_code == 4058687 rv = client.head("/")88 assert rv.status_code == 20089 assert not rv.data # head truncates90 assert client.post("/more").data == b"POST"91 assert client.get("/more").data == b"GET"9293 rv = client.delete("/more")94 assert rv.status_code == 40595 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]96Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 97why, one step back97 rv = client.open("/more", method="OPTIONS")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 98–100why, one step back98 assert rv.status_code == 40599100Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 101why, one step back101def test_request_dispatching(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 102–123why, one step back102 @app.route("/")103 def index():104 return flask.request.method105106 @app.route("/more", methods=["GET", "POST"])107 def more():108 return flask.request.method109110 assert client.get("/").data == b"GET"111 rv = client.post("/")112 assert rv.status_code == 405113 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]114 rv = client.head("/")115 assert rv.status_code == 200116 assert not rv.data # head truncates117 assert client.post("/more").data == b"POST"118 assert client.get("/more").data == b"GET"119 rv = client.delete("/more")120 assert rv.status_code == 405121 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]122123Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 124–125why, one step back124def test_disallow_string_for_allowed_methods(app):125 with pytest.raises(TypeError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 126–128why, one step back126127 @app.route("/", methods="GET POST")128 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 129why, one step back129 return "Hey"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 130–131why, one step back130131Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 132–133why, one step back132def test_url_mapping(app, client):133 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 134–140why, one step back134135 def index():136 return flask.request.method137138 def more():139 return flask.request.method140Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 141–142why, one step back141 def options():142 return random_uuid4Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 143–146why, one step back143144 app.add_url_rule("/", "index", index)145 app.add_url_rule("/more", "more", more, methods=["GET", "POST"])146Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 147–148why, one step back147 # Issue 1288: Test that automatic options are not added148 # when non-uppercase 'options' in methodsMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 149–164why, one step back149 app.add_url_rule("/options", "options", options, methods=["options"])150151 assert client.get("/").data == b"GET"152 rv = client.post("/")153 assert rv.status_code == 405154 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]155 rv = client.head("/")156 assert rv.status_code == 200157 assert not rv.data # head truncates158 assert client.post("/more").data == b"POST"159 assert client.get("/more").data == b"GET"160 rv = client.delete("/more")161 assert rv.status_code == 405162 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]163 rv = client.open("/options", method="OPTIONS")164 assert rv.status_code == 200Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 165why, one step back165 assert random_uuid4 in rv.data.decode("utf-8")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 166–167why, one step back166167Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 168why, one step back168def test_werkzeug_routing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 169–187why, one step back169 from werkzeug.routing import Submount, Rule170171 app.url_map.add(172 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])173 )174175 def bar():176 return "bar"177178 def index():179 return "index"180181 app.view_functions["bar"] = bar182 app.view_functions["index"] = index183184 assert client.get("/foo/").data == b"index"185 assert client.get("/foo/bar").data == b"bar"186187Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 188why, one step back188def test_endpoint_decorator(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 189–206why, 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 @app.endpoint("bar")196 def bar():197 return "bar"198199 @app.endpoint("index")200 def index():201 return "index"202203 assert client.get("/foo/").data == b"index"204 assert client.get("/foo/bar").data == b"bar"205206Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 207why, one step back207def test_session(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 208why, one step back208 @app.route("/set", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 209why, one step back209 def set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 210–213why, one step back210 assert not flask.session.accessed211 assert not flask.session.modified212 flask.session["value"] = flask.request.form["value"]213 assert flask.session.accessedMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 214why, one step back214 assert flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 215–223why, one step back215 return "value set"216217 @app.route("/get")218 def get():219 assert not flask.session.accessed220 assert not flask.session.modified221 v = flask.session.get("value", "None")222 assert flask.session.accessed223 assert not flask.session.modifiedMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 224why, one step back224 return vMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 225–229why, one step back225226 assert client.post("/set", data={"value": "42"}).data == b"value set"227 assert client.get("/get").data == b"42"228229Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 230why, one step back230def test_session_using_server_name(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 231–242why, one step back231 app.config.update(SERVER_NAME="example.com")232233 @app.route("/")234 def index():235 flask.session["testing"] = 42236 return "Hello World"237238 rv = client.get("/", "http://example.com/")239 assert "domain=.example.com" in rv.headers["set-cookie"].lower()240 assert "httponly" in rv.headers["set-cookie"].lower()241242Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 243why, one step back243def test_session_using_server_name_and_port(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 244–255why, one step back244 app.config.update(SERVER_NAME="example.com:8080")245246 @app.route("/")247 def index():248 flask.session["testing"] = 42249 return "Hello World"250251 rv = client.get("/", "http://example.com:8080/")252 assert "domain=.example.com" in rv.headers["set-cookie"].lower()253 assert "httponly" in rv.headers["set-cookie"].lower()254255Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 256why, one step back256def test_session_using_server_name_port_and_path(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 257–269why, one step back257 app.config.update(SERVER_NAME="example.com:8080", APPLICATION_ROOT="/foo")258259 @app.route("/")260 def index():261 flask.session["testing"] = 42262 return "Hello World"263264 rv = client.get("/", "http://example.com:8080/foo")265 assert "domain=example.com" in rv.headers["set-cookie"].lower()266 assert "path=/foo" in rv.headers["set-cookie"].lower()267 assert "httponly" in rv.headers["set-cookie"].lower()268269Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 270why, one step back270def test_session_using_application_root(app, client):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 271why, one step back271 class PrefixPathMiddleware:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 272–274why, one step back272 def __init__(self, app, prefix):273 self.app = app274 self.prefix = prefixMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 275why, one step back275Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 276why, one step back276 def __call__(self, environ, start_response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 277why, one step back277 environ["SCRIPT_NAME"] = self.prefixMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 278why, one step back278 return self.app(environ, start_response)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 279–291why, one step back279280 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, "/bar")281 app.config.update(APPLICATION_ROOT="/bar")282283 @app.route("/")284 def index():285 flask.session["testing"] = 42286 return "Hello World"287288 rv = client.get("/", "http://example.com:8080/")289 assert "path=/bar" in rv.headers["set-cookie"].lower()290291Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 292why, one step back292def test_session_using_session_settings(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 293–296why, one step back293 app.config.update(294 SERVER_NAME="www.example.com:8080",295 APPLICATION_ROOT="/test",296 SESSION_COOKIE_DOMAIN=".example.com",Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 297–298why, one step back297 SESSION_COOKIE_HTTPONLY=False,298 SESSION_COOKIE_SECURE=True,Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 299–316why, one step back299 SESSION_COOKIE_SAMESITE="Lax",300 SESSION_COOKIE_PATH="/",301 )302303 @app.route("/")304 def index():305 flask.session["testing"] = 42306 return "Hello World"307308 rv = client.get("/", "http://www.example.com:8080/test/")309 cookie = rv.headers["set-cookie"].lower()310 assert "domain=.example.com" in cookie311 assert "path=/" in cookie312 assert "secure" in cookie313 assert "httponly" not in cookie314 assert "samesite" in cookie315316Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 317why, one step back317def test_session_using_samesite_attribute(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 318–324why, one step back318 @app.route("/")319 def index():320 flask.session["testing"] = 42321 return "Hello World"322323 app.config.update(SESSION_COOKIE_SAMESITE="invalid")324Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 325why, one step back325 with pytest.raises(ValueError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 326–327why, one step back326 client.get("/")327Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 328why, one step back328 app.config.update(SESSION_COOKIE_SAMESITE=None)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 329–343why, one step back329 rv = client.get("/")330 cookie = rv.headers["set-cookie"].lower()331 assert "samesite" not in cookie332333 app.config.update(SESSION_COOKIE_SAMESITE="Strict")334 rv = client.get("/")335 cookie = rv.headers["set-cookie"].lower()336 assert "samesite=strict" in cookie337338 app.config.update(SESSION_COOKIE_SAMESITE="Lax")339 rv = client.get("/")340 cookie = rv.headers["set-cookie"].lower()341 assert "samesite=lax" in cookie342343Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 344why, one step back344def test_session_localhost_warning(recwarn, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 345–354why, one step back345 app.config.update(SERVER_NAME="localhost:5000")346347 @app.route("/")348 def index():349 flask.session["testing"] = 42350 return "testing"351352 rv = client.get("/", "http://localhost:5000/")353 assert "domain" not in rv.headers["set-cookie"].lower()354 w = recwarn.pop(UserWarning)Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 355why, one step back355 assert "'localhost' is not a valid cookie domain" in str(w.message)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 356–357why, one step back356357Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 358why, one step back358def test_session_ip_warning(recwarn, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 359–371why, one step back359 app.config.update(SERVER_NAME="127.0.0.1:5000")360361 @app.route("/")362 def index():363 flask.session["testing"] = 42364 return "testing"365366 rv = client.get("/", "http://127.0.0.1:5000/")367 assert "domain=127.0.0.1" in rv.headers["set-cookie"].lower()368 w = recwarn.pop(UserWarning)369 assert "cookie domain is an IP" in str(w.message)370371Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 372–373why, one step back372def test_missing_session(app):373 app.secret_key = NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 374why, one step back374Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 375–376why, one step back375 def expect_exception(f, *args, **kwargs):376 e = pytest.raises(RuntimeError, f, *args, **kwargs)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 377–384why, one step back377 assert e.value.args and "session is unavailable" in e.value.args[0]378379 with app.test_request_context():380 assert flask.session.get("missing_key") is None381 expect_exception(flask.session.__setitem__, "foo", 42)382 expect_exception(flask.session.pop, "foo")383384Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 385–386why, one step back385def test_session_expiration(app, client):386 permanent = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 387–390why, one step back387388 @app.route("/")389 def index():390 flask.session["test"] = 42Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 391why, one step back391 flask.session.permanent = permanentMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 392–395why, one step back392 return ""393394 @app.route("/test")395 def test():Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 396why, one step back396 return str(flask.session.permanent)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 397–400why, one step back397398 rv = client.get("/")399 assert "set-cookie" in rv.headers400 match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 401–405why, one step back401 expires = parse_date(match.group())402 expected = datetime.utcnow() + app.permanent_session_lifetime403 assert expires.year == expected.year404 assert expires.month == expected.month405 assert expires.day == expected.dayMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 406–409why, one step back406407 rv = client.get("/test")408 assert rv.data == b"True"409Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 410why, one step back410 permanent = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 411–413why, one step back411 rv = client.get("/")412 assert "set-cookie" in rv.headers413 match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 414why, one step back414 assert match is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 415–416why, one step back415416Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 417why, one step back417def test_session_stored_last(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 418why, one step back418 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 419why, one step back419 def modify_session(response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 420–430why, one step back420 flask.session["foo"] = 42421 return response422423 @app.route("/")424 def dump_session_contents():425 return repr(flask.session.get("foo"))426427 assert client.get("/").data == b"None"428 assert client.get("/").data == b"42"429430Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 431–433why, one step back431def test_session_special_types(app, client):432 now = datetime.utcnow().replace(microsecond=0)433 the_uuid = uuid.uuid4()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 434–448why, one step back434435 @app.route("/")436 def dump_session_contents():437 flask.session["t"] = (1, 2, 3)438 flask.session["b"] = b"\xff"439 flask.session["m"] = flask.Markup("<html>")440 flask.session["u"] = the_uuid441 flask.session["d"] = now442 flask.session["t_tag"] = {" t": "not-a-tuple"}443 flask.session["di_t_tag"] = {" t__": "not-a-tuple"}444 flask.session["di_tag"] = {" di": "not-a-dict"}445 return "", 204446447 with client:448 client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 449why, one step back449 s = flask.sessionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 450–461why, one step back450 assert s["t"] == (1, 2, 3)451 assert type(s["b"]) == bytes452 assert s["b"] == b"\xff"453 assert type(s["m"]) == flask.Markup454 assert s["m"] == flask.Markup("<html>")455 assert s["u"] == the_uuid456 assert s["d"] == now457 assert s["t_tag"] == {" t": "not-a-tuple"}458 assert s["di_t_tag"] == {" t__": "not-a-tuple"}459 assert s["di_tag"] == {" di": "not-a-dict"}460461Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 462why, one step back462def test_session_cookie_setting(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 463–465why, one step back463 is_permanent = True464465 @app.route("/bump")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 466why, one step back466 def bump():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 467why, one step back467 rv = flask.session["foo"] = flask.session.get("foo", 0) + 1Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 468–469why, one step back468 flask.session.permanent = is_permanent469 return str(rv)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 470–471why, one step back470471 @app.route("/read")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 472why, one step back472 def read():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 473–474why, one step back473 return str(flask.session.get("foo", 0))474Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 475–476why, one step back475 def run_test(expect_header):476 with app.test_client() as c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 477–482why, one step back477 assert c.get("/bump").data == b"1"478 assert c.get("/bump").data == b"2"479 assert c.get("/bump").data == b"3"480481 rv = c.get("/read")482 set_cookie = rv.headers.get("set-cookie")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 483why, one step back483 assert (set_cookie is not None) == expect_headerMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 484–487why, one step back484 assert rv.data == b"3"485486 is_permanent = True487 app.config["SESSION_REFRESH_EACH_REQUEST"] = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 488why, one step back488 run_test(expect_header=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 489–502why, one step back489490 is_permanent = True491 app.config["SESSION_REFRESH_EACH_REQUEST"] = False492 run_test(expect_header=False)493494 is_permanent = False495 app.config["SESSION_REFRESH_EACH_REQUEST"] = True496 run_test(expect_header=False)497498 is_permanent = False499 app.config["SESSION_REFRESH_EACH_REQUEST"] = False500 run_test(expect_header=False)501502Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 503why, one step back503def test_session_vary_cookie(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 504why, one step back504 @app.route("/set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 505why, one step back505 def set_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 506–513why, one step back506 flask.session["test"] = "test"507 return ""508509 @app.route("/get")510 def get():511 return flask.session.get("test")512513 @app.route("/getitem")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 514why, one step back514 def getitem():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 515–517why, one step back515 return flask.session["test"]516517 @app.route("/setdefault")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 518why, one step back518 def setdefault():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 519–521why, one step back519 return flask.session.setdefault("test", "default")520521 @app.route("/vary-cookie-header-set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 522why, one step back522 def vary_cookie_header_set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 523–528why, one step back523 response = flask.Response()524 response.vary.add("Cookie")525 flask.session["test"] = "test"526 return response527528 @app.route("/vary-header-set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 529why, one step back529 def vary_header_set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 530–535why, one step back530 response = flask.Response()531 response.vary.update(("Accept-Encoding", "Accept-Language"))532 flask.session["test"] = "test"533 return response534535 @app.route("/no-vary-header")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 536why, one step back536 def no_vary_header():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 537–539why, one step back537 return ""538539 def expect(path, header_value="Cookie"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 540why, one step back540 rv = client.get(path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 541why, one step back541Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 542–543why, one step back542 if header_value:543 # The 'Vary' key should exist in the headers only once.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 544–557why, one step back544 assert len(rv.headers.get_all("Vary")) == 1545 assert rv.headers["Vary"] == header_value546 else:547 assert "Vary" not in rv.headers548549 expect("/set")550 expect("/get")551 expect("/getitem")552 expect("/setdefault")553 expect("/vary-cookie-header-set")554 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")555 expect("/no-vary-header", None)556557Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 558–559why, one step back558def test_flashes(app, req_ctx):559 assert not flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 560why, one step back560 flask.flash("Zap")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 561why, one step back561 flask.session.modified = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 562why, one step back562 flask.flash("Zip")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 563why, one step back563 assert flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 564–566why, one step back564 assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]565566Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 567–572why, one step back567def test_extended_flashing(app):568 # Be sure app.testing=True below, else tests can fail silently.569 #570 # Specifically, if app.testing is not set to True, the AssertionErrors571 # in the view functions will cause a 500 response to the test client572 # instead of propagating exceptions.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 573–575why, one step back573574 @app.route("/")575 def index():Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 576–578why, one step back576 flask.flash("Hello World")577 flask.flash("Hello World", "error")578 flask.flash(flask.Markup("<em>Testing</em>"), "warning")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 579–582why, one step back579 return ""580581 @app.route("/test/")582 def test():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 583why, one step back583 messages = flask.get_flashed_messages()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 584why, one step back584 assert list(messages) == [Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 585–587why, one step back585 "Hello World",586 "Hello World",587 flask.Markup("<em>Testing</em>"),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 588–591why, one step back588 ]589 return ""590591 @app.route("/test_with_categories/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 592–594why, one step back592 def test_with_categories():593 messages = flask.get_flashed_messages(with_categories=True)594 assert len(messages) == 3Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 595why, one step back595 assert list(messages) == [Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 596–598why, one step back596 ("message", "Hello World"),597 ("error", "Hello World"),598 ("warning", flask.Markup("<em>Testing</em>")),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 599–602why, one step back599 ]600 return ""601602 @app.route("/test_filter/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 603why, one step back603 def test_filter():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 604–606why, one step back604 messages = flask.get_flashed_messages(605 category_filter=["message"], with_categories=True606 )Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 607why, one step back607 assert list(messages) == [("message", "Hello World")]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 608–610why, one step back608 return ""609610 @app.route("/test_filters/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 611why, one step back611 def test_filters():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 612–615why, one step back612 messages = flask.get_flashed_messages(613 category_filter=["message", "warning"], with_categories=True614 )615 assert list(messages) == [Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 616–617why, one step back616 ("message", "Hello World"),617 ("warning", flask.Markup("<em>Testing</em>")),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 618–621why, one step back618 ]619 return ""620621 @app.route("/test_filters_without_returning_categories/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 622why, one step back622 def test_filters2():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 623why, one step back623 messages = flask.get_flashed_messages(category_filter=["message", "warning"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 624why, one step back624 assert len(messages) == 2Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 625–626why, one step back625 assert messages[0] == "Hello World"626 assert messages[1] == flask.Markup("<em>Testing</em>")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 627–628why, one step back627 return ""628Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 629why, one step back629 # Create new test client on each test to clean flashed messages.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 630–647why, one step back630631 client = app.test_client()632 client.get("/")633 client.get("/test_with_categories/")634635 client = app.test_client()636 client.get("/")637 client.get("/test_filter/")638639 client = app.test_client()640 client.get("/")641 client.get("/test_filters/")642643 client = app.test_client()644 client.get("/")645 client.get("/test_filters_without_returning_categories/")646647Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 648why, one step back648def test_request_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 649–672why, one step back649 evts = []650651 @app.before_request652 def before_request():653 evts.append("before")654655 @app.after_request656 def after_request(response):657 response.data += b"|after"658 evts.append("after")659 return response660661 @app.route("/")662 def index():663 assert "before" in evts664 assert "after" not in evts665 return "request"666667 assert "after" not in evts668 rv = client.get("/").data669 assert "after" in evts670 assert rv == b"request|after"671672Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 673why, one step back673def test_request_preprocessing_early_return(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 674–676why, one step back674 evts = []675676 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 677–678why, one step back677 def before_request1():678 evts.append(1)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 679–680why, one step back679680 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 681–683why, one step back681 def before_request2():682 evts.append(2)683 return "hello"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 684–685why, one step back684685 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 686–688why, one step back686 def before_request3():687 evts.append(3)688 return "bye"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 689–692why, one step back689690 @app.route("/")691 def index():692 evts.append("index")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 693why, one step back693 return "damnit"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 694–696why, one step back694695 rv = client.get("/").data.strip()696 assert rv == b"hello"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 697why, one step back697 assert evts == [1, 2]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 698–699why, one step back698699Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 700why, one step back700def test_after_request_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 701–702why, one step back701 @app.route("/")702 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 703–704why, one step back703 @flask.after_this_request704 def foo(response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 705why, one step back705 response.headers["X-Foo"] = "a header"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 706why, one step back706 return responseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 707–710why, one step back707708 return "Test"709710 resp = client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 711why, one step back711 assert resp.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 712–714why, one step back712 assert resp.headers["X-Foo"] == "a header"713714Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 715why, one step back715def test_teardown_request_handler(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 716–732why, one step back716 called = []717718 @app.teardown_request719 def teardown_request(exc):720 called.append(True)721 return "Ignored"722723 @app.route("/")724 def root():725 return "Response"726727 rv = client.get("/")728 assert rv.status_code == 200729 assert b"Response" in rv.data730 assert len(called) == 1731732Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 733why, one step back733def test_teardown_request_handler_debug_mode(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 734–750why, one step back734 called = []735736 @app.teardown_request737 def teardown_request(exc):738 called.append(True)739 return "Ignored"740741 @app.route("/")742 def root():743 return "Response"744745 rv = client.get("/")746 assert rv.status_code == 200747 assert b"Response" in rv.data748 assert len(called) == 1749750Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 751why, one step back751def test_teardown_request_handler_error(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 752–755why, one step back752 called = []753 app.testing = False754755 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 756why, one step back756 def teardown_request1(exc):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 757–763why, one step back757 assert type(exc) == ZeroDivisionError758 called.append(True)759 # This raises a new error and blows away sys.exc_info(), so we can760 # test that all teardown_requests get passed the same original761 # exception.762 try:763 raise TypeError()Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 764why, one step back764 except Exception:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 765–767why, one step back765 pass766767 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 768why, one step back768 def teardown_request2(exc):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 769–775why, one step back769 assert type(exc) == ZeroDivisionError770 called.append(True)771 # This raises a new error and blows away sys.exc_info(), so we can772 # test that all teardown_requests get passed the same original773 # exception.774 try:775 raise TypeError()Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 776why, one step back776 except Exception:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 777–779why, one step back777 pass778779 @app.route("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 780why, one step back780 def fails():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 781–785why, one step back781 1 // 0782783 rv = client.get("/")784 assert rv.status_code == 500785 assert b"Internal Server Error" in rv.dataMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 786why, one step back786 assert len(called) == 2Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 787–788why, one step back787788Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 789why, one step back789def test_before_after_request_order(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 790–792why, one step back790 called = []791792 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 793–794why, one step back793 def before1():794 called.append(1)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 795–796why, one step back795796 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 797–798why, one step back797 def before2():798 called.append(2)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 799–800why, one step back799800 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 801–802why, one step back801 def after1(response):802 called.append(4)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 803–805why, one step back803 return response804805 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 806–807why, one step back806 def after2(response):807 called.append(3)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 808–810why, one step back808 return response809810 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 811–812why, one step back811 def finish1(exc):812 called.append(6)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 813–814why, one step back813814 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 815–816why, one step back815 def finish2(exc):816 called.append(5)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 817–823why, one step back817818 @app.route("/")819 def index():820 return "42"821822 rv = client.get("/")823 assert rv.data == b"42"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 824why, one step back824 assert called == [1, 2, 3, 4, 5, 6]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 825–826why, one step back825826Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 827why, one step back827def test_error_handling(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 828–830why, one step back828 app.testing = False829830 @app.errorhandler(404)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 831why, one step back831 def not_found(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 832–837why, one step back832 return "not found", 404833834 @app.errorhandler(500)835 def internal_server_error(e):836 return "internal server error", 500837Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 838–839why, one step back838 @app.errorhandler(Forbidden)839 def forbidden(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 840–846why, one step back840 return "forbidden", 403841842 @app.route("/")843 def index():844 flask.abort(404)845846 @app.route("/error")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 847why, one step back847 def error():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 848–850why, one step back848 1 // 0849850 @app.route("/forbidden")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 851why, one step back851 def error2():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 852–860why, one step back852 flask.abort(403)853854 rv = client.get("/")855 assert rv.status_code == 404856 assert rv.data == b"not found"857 rv = client.get("/error")858 assert rv.status_code == 500859 assert b"internal server error" == rv.data860 rv = client.get("/forbidden")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 861why, one step back861 assert rv.status_code == 403Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 862–864why, one step back862 assert b"forbidden" == rv.data863864Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 865–866why, one step back865def test_error_handler_unknown_code(app):866 with pytest.raises(KeyError) as exc_info:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 867–871why, one step back867 app.register_error_handler(999, lambda e: ("999", 999))868869 assert "Use a subclass" in exc_info.value.args[0]870871Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 872why, one step back872def test_error_handling_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 873–883why, one step back873 app.testing = False874875 @app.errorhandler(500)876 def internal_server_error(e):877 return "internal server error", 500878879 @app.route("/")880 def broken_func():881 1 // 0882883 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 884why, one step back884 def after_request(resp):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 885why, one step back885 resp.mimetype = "text/x-special"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 886why, one step back886 return respMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 887–892why, one step back887888 resp = client.get("/")889 assert resp.mimetype == "text/x-special"890 assert resp.data == b"internal server error"891892Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 893why, one step back893def test_baseexception_error_handling(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 894–897why, one step back894 app.testing = False895896 @app.route("/")897 def broken_func():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 898why, one step back898 raise KeyboardInterrupt()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 899why, one step back899Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 900why, one step back900 with pytest.raises(KeyboardInterrupt):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 901–902why, one step back901 client.get("/")902Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 903–905why, one step back903 ctx = flask._request_ctx_stack.top904 assert ctx.preserved905 assert type(ctx._preserved_exc) is KeyboardInterruptMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 906–907why, one step back906907Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 908why, one step back908def test_before_request_and_routing_errors(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 909why, one step back909 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 910why, one step back910 def attach_something():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 911–913why, one step back911 flask.g.something = "value"912913 @app.errorhandler(404)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 914–915why, one step back914 def return_something(error):915 return flask.g.something, 404Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 916–921why, one step back916917 rv = client.get("/")918 assert rv.status_code == 404919 assert rv.data == b"value"920921Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 922–923why, one step back922def test_user_error_handling(app, client):923 class MyException(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 924–925why, one step back924 pass925Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 926–928why, one step back926 @app.errorhandler(MyException)927 def handle_my_exception(e):928 assert isinstance(e, MyException)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 929–932why, one step back929 return "42"930931 @app.route("/")932 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 933why, one step back933 raise MyException()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 934–937why, one step back934935 assert client.get("/").data == b"42"936937Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 938–939why, one step back938def test_http_error_subclass_handling(app, client):939 class ForbiddenSubclass(Forbidden):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 940–941why, one step back940 pass941Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 942why, one step back942 @app.errorhandler(ForbiddenSubclass)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 943why, one step back943 def handle_forbidden_subclass(e):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 944why, one step back944 assert isinstance(e, ForbiddenSubclass)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 945–946why, one step back945 return "banana"946Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 947why, one step back947 @app.errorhandler(403)Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 948why, one step back948 def handle_403(e):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 949–950why, one step back949 assert not isinstance(e, ForbiddenSubclass)950 assert isinstance(e, Forbidden)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 951–953why, one step back951 return "apple"952953 @app.route("/1")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 954–955why, one step back954 def index1():955 raise ForbiddenSubclass()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 956–961why, one step back956957 @app.route("/2")958 def index2():959 flask.abort(403)960961 @app.route("/3")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 962–963why, one step back962 def index3():963 raise Forbidden()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 964–969why, one step back964965 assert client.get("/1").data == b"banana"966 assert client.get("/2").data == b"apple"967 assert client.get("/3").data == b"apple"968969Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 970–971why, one step back970def test_errorhandler_precedence(app, client):971 class E1(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 972–973why, one step back972 pass973Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 974why, one step back974 class E2(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 975–976why, one step back975 pass976Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 977why, one step back977 class E3(E1, E2):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 978–979why, one step back978 pass979Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 980–981why, one step back980 @app.errorhandler(E2)981 def handle_e2(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 982–983why, one step back982 return "E2"983Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 984–985why, one step back984 @app.errorhandler(Exception)985 def handle_exception(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 986–988why, one step back986 return "Exception"987988 @app.route("/E1")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 989–990why, one step back989 def raise_e1():990 raise E1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 991–992why, one step back991992 @app.route("/E3")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 993–994why, one step back993 def raise_e3():994 raise E3Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 995–1002why, one step back995996 rv = client.get("/E1")997 assert rv.data == b"Exception"998999 rv = client.get("/E3")1000 assert rv.data == b"E2"10011002Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1003why, one step back1003def test_trapping_of_bad_request_key_errors(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1004–1008why, one step back1004 @app.route("/key")1005 def fail():1006 flask.request.form["missing_key"]10071008 @app.route("/abort")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 1009–1010why, one step back1009 def allow_abort():1010 flask.abort(400)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1011–1018why, one step back10111012 rv = client.get("/key")1013 assert rv.status_code == 4001014 assert b"missing_key" not in rv.data1015 rv = client.get("/abort")1016 assert rv.status_code == 40010171018 app.debug = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1019why, one step back1019 with pytest.raises(KeyError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1020why, one step back1020 client.get("/key")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1021why, one step back1021 assert e.errisinstance(BadRequest)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1022–1027why, one step back1022 assert "missing_key" in e.value.get_description()1023 rv = client.get("/abort")1024 assert rv.status_code == 40010251026 app.debug = False1027 app.config["TRAP_BAD_REQUEST_ERRORS"] = TrueMerge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 1028why, one step back1028 with pytest.raises(KeyError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1029why, one step back1029 client.get("/key")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 1030why, one step back1030 with pytest.raises(BadRequest):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1031–1033why, one step back1031 client.get("/abort")10321033Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1034why, one step back1034def test_trapping_of_all_http_exceptions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1035–1040why, one step back1035 app.config["TRAP_HTTP_EXCEPTIONS"] = True10361037 @app.route("/fail")1038 def fail():1039 flask.abort(404)1040Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1041why, one step back1041 with pytest.raises(NotFound):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1042–1044why, one step back1042 client.get("/fail")10431044Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1045why, one step back1045def test_error_handler_after_processor_error(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1046–1049why, one step back1046 app.testing = False10471048 @app.before_request1049 def before_request():Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1050why, one step back1050 if _trigger == "before":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1051–1054why, one step back1051 1 // 010521053 @app.after_request1054 def after_request(response):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1055why, one step back1055 if _trigger == "after":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1056–1066why, one step back1056 1 // 01057 return response10581059 @app.route("/")1060 def index():1061 return "Foo"10621063 @app.errorhandler(500)1064 def internal_server_error(e):1065 return "Hello Server Error", 5001066Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1067why, one step back1067 for _trigger in "before", "after":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1068why, one step back1068 rv = client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1069why, one step back1069 assert rv.status_code == 500Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1070–1072why, one step back1070 assert rv.data == b"Hello Server Error"10711072Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1073–1074why, one step back1073def test_enctype_debug_helper(app, client):1074 from flask.debughelpers import DebugFilesKeyErrorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1075–1081why, one step back10751076 app.debug = True10771078 @app.route("/fail", methods=["POST"])1079 def index():1080 return flask.request.files["foo"].filename1081Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1082–1084why, one step back1082 # with statement is important because we leave an exception on the1083 # stack otherwise and we want to ensure that this is not the case1084 # to not negatively affect other tests.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1085why, one step back1085 with client:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1086why, one step back1086 with pytest.raises(DebugFilesKeyError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1087–1088why, one step back1087 client.post("/fail", data={"foo": "index.txt"})1088 assert "no file contents were transmitted" in str(e.value)Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1089why, one step back1089 assert "This was submitted: 'index.txt'" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1090–1091why, one step back10901091Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1092why, one step back1092def test_response_types(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1093why, one step back1093 @app.route("/text")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1094why, one step back1094 def from_text():Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1095why, one step back1095 return "Hällo Wörld"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1096–1097why, one step back10961097 @app.route("/bytes")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1098why, one step back1098 def from_bytes():Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1099why, one step back1099 return "Hällo Wörld".encode()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1100–1101why, one step back11001101 @app.route("/full_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1102why, one step back1102 def from_full_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1103–1109why, one step back1103 return (1104 "Meh",1105 400,1106 {"X-Foo": "Testing", "Content-Type": "text/plain; charset=utf-8"},1107 )11081109 @app.route("/text_headers")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1110why, one step back1110 def from_text_headers():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1111–1113why, one step back1111 return "Hello", {"X-Foo": "Test", "Content-Type": "text/plain; charset=utf-8"}11121113 @app.route("/text_status")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1114why, one step back1114 def from_text_status():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1115–1117why, one step back1115 return "Hi, status!", 40011161117 @app.route("/response_headers")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1118why, one step back1118 def from_response_headers():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1119–1124why, one step back1119 return (1120 flask.Response("Hello world", 404, {"X-Foo": "Baz"}),1121 {"X-Foo": "Bar", "X-Bar": "Foo"},1122 )11231124 @app.route("/response_status")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1125why, one step back1125 def from_response_status():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1126–1128why, one step back1126 return app.response_class("Hello world", 400), 50011271128 @app.route("/wsgi")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1129–1130why, one step back1129 def from_wsgi():1130 return NotFound()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1131why, one step back1131Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1132why, one step back1132 @app.route("/dict")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
lines 1133–1134why, one step back1133 def from_dict():1134 return {"foo": "bar"}, 201Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1135why, one step back1135Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 1136–1137why, one step back1136 assert client.get("/text").data == "Hällo Wörld".encode()1137 assert client.get("/bytes").data == "Hällo Wörld".encode()Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
line 1138why, one step back1138Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1139–1168why, one step back1139 rv = client.get("/full_tuple")1140 assert rv.data == b"Meh"1141 assert rv.headers["X-Foo"] == "Testing"1142 assert rv.status_code == 4001143 assert rv.mimetype == "text/plain"11441145 rv = client.get("/text_headers")1146 assert rv.data == b"Hello"1147 assert rv.headers["X-Foo"] == "Test"1148 assert rv.status_code == 2001149 assert rv.mimetype == "text/plain"11501151 rv = client.get("/text_status")1152 assert rv.data == b"Hi, status!"1153 assert rv.status_code == 4001154 assert rv.mimetype == "text/html"11551156 rv = client.get("/response_headers")1157 assert rv.data == b"Hello world"1158 assert rv.headers.getlist("X-Foo") == ["Baz", "Bar"]1159 assert rv.headers["X-Bar"] == "Foo"1160 assert rv.status_code == 40411611162 rv = client.get("/response_status")1163 assert rv.data == b"Hello world"1164 assert rv.status_code == 50011651166 rv = client.get("/wsgi")1167 assert b"Not Found" in rv.data1168 assert rv.status_code == 404Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
line 1169why, one step back1169Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1170why, one step back1170 rv = client.get("/dict")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
lines 1171–1172why, one step back1171 assert rv.json == {"foo": "bar"}1172 assert rv.status_code == 201Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1173–1174why, one step back11731174Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1175why, one step back1175def test_response_type_errors():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1176–1179why, one step back1176 app = flask.Flask(__name__)1177 app.testing = True11781179 @app.route("/none")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1180why, one step back1180 def from_none():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1181–1183why, one step back1181 pass11821183 @app.route("/small_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1184why, one step back1184 def from_small_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1185–1187why, one step back1185 return ("Hello",)11861187 @app.route("/large_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1188why, one step back1188 def from_large_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1189–1191why, one step back1189 return "Hello", 234, {"X-Foo": "Bar"}, "???"11901191 @app.route("/bad_type")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1192–1193why, one step back1192 def from_bad_type():1193 return TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1194–1195why, one step back11941195 @app.route("/bad_wsgi")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1196–1197why, one step back1196 def from_bad_wsgi():1197 return lambda: NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1198–1202why, one step back11981199 c = app.test_client()12001201 with pytest.raises(TypeError) as e:1202 c.get("/none")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1203why, one step back1203 assert "returned None" in str(e.value)Merge pull request #3498 from raymond-devries/3445-traceback-for-noneDavid Lordbefore adoptiona3e4395
line 1204why, one step back1204 assert "from_none" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1205–1207why, one step back12051206 with pytest.raises(TypeError) as e:1207 c.get("/small_tuple")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1208why, one step back1208 assert "tuple must have the form" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1209–1213why, one step back12091210 pytest.raises(TypeError, c.get, "/large_tuple")12111212 with pytest.raises(TypeError) as e:1213 c.get("/bad_type")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1214why, one step back1214 assert "it was a bool" in str(e.value)Merge pull request #3235 from johnzeringue/better-return-type-errorDavid Lordbefore adoption52f9aa7
line 1215why, one step back1215Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1216–1218why, one step back1216 pytest.raises(TypeError, c.get, "/bad_wsgi")12171218Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1219–1220why, one step back1219def test_make_response(app, req_ctx):1220 rv = flask.make_response()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1221–1235why, one step back1221 assert rv.status_code == 2001222 assert rv.data == b""1223 assert rv.mimetype == "text/html"12241225 rv = flask.make_response("Awesome")1226 assert rv.status_code == 2001227 assert rv.data == b"Awesome"1228 assert rv.mimetype == "text/html"12291230 rv = flask.make_response("W00t", 404)1231 assert rv.status_code == 4041232 assert rv.data == b"W00t"1233 assert rv.mimetype == "text/html"12341235Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1236why, one step back1236def test_make_response_with_response_instance(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1237–1238why, one step back1237 rv = flask.make_response(flask.jsonify({"msg": "W00t"}), 400)1238 assert rv.status_code == 400Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1239why, one step back1239 assert rv.data == b'{"msg":"W00t"}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1240–1256why, one step back1240 assert rv.mimetype == "application/json"12411242 rv = flask.make_response(flask.Response(""), 400)1243 assert rv.status_code == 4001244 assert rv.data == b""1245 assert rv.mimetype == "text/html"12461247 rv = flask.make_response(1248 flask.Response("", headers={"Content-Type": "text/html"}),1249 400,1250 [("X-Foo", "bar")],1251 )1252 assert rv.status_code == 4001253 assert rv.headers["Content-Type"] == "text/html"1254 assert rv.headers["X-Foo"] == "bar"12551256Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1257–1259why, one step back1257def test_jsonify_no_prettyprint(app, req_ctx):1258 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})1259 compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1260–1262why, one step back1260 uncompressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}12611262 rv = flask.make_response(flask.jsonify(uncompressed_msg), 200)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1263why, one step back1263 assert rv.data == compressed_msgMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1264–1265why, one step back12641265Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1266–1268why, one step back1266def test_jsonify_prettyprint(app, req_ctx):1267 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})1268 compressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1269why, one step back1269 pretty_response = (Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1270why, one step back1270 b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1271–1273why, one step back1271 )12721273 rv = flask.make_response(flask.jsonify(compressed_msg), 200)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1274why, one step back1274 assert rv.data == pretty_responseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1275–1276why, one step back12751276Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1277why, one step back1277def test_jsonify_mimetype(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1278–1282why, one step back1278 app.config.update({"JSONIFY_MIMETYPE": "application/vnd.api+json"})1279 msg = {"msg": {"submsg": "W00t"}}1280 rv = flask.make_response(flask.jsonify(msg), 200)1281 assert rv.mimetype == "application/vnd.api+json"1282Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
lines 1283–1286why, one step back12831284@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")1285def test_json_dump_dataclass(app, req_ctx):1286 from dataclasses import make_dataclassMerge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1287why, one step back1287Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
lines 1288–1291why, one step back1288 Data = make_dataclass("Data", [("name", str)])1289 value = flask.json.dumps(Data("Flask"), app=app)1290 value = flask.json.loads(value, app=app)1291 assert value == {"name": "Flask"}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1292why, one step back1292Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1293why, one step back1293Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1294why, one step back1294def test_jsonify_args_and_kwargs_check(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1295–1299why, one step back1295 with pytest.raises(TypeError) as e:1296 flask.jsonify("fake args", kwargs="fake")1297 assert "behavior undefined" in str(e.value)12981299Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1300why, one step back1300def test_url_generation(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1301why, one step back1301 @app.route("/hello/<name>", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1302why, one step back1302 def hello():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1303–1311why, one step back1303 pass13041305 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1306 assert (1307 flask.url_for("hello", name="test x", _external=True)1308 == "http://localhost/hello/test%20x"1309 )13101311Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1312–1313why, one step back1312def test_build_error_handler(app):1313 # Test base case, a URL which results in a BuildError.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1314–1316why, one step back1314 with app.test_request_context():1315 pytest.raises(BuildError, flask.url_for, "spam")1316Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1317why, one step back1317 # Verify the error is re-raised if not the current exception.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1318why, one step back1318 try:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1319why, one step back1319 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1320why, one step back1320 flask.url_for("spam")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1321–1322why, one step back1321 except BuildError as err:1322 error = errMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1323–1324why, one step back1323 try:1324 raise RuntimeError("Test case where BuildError is not current.")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1325why, one step back1325 except RuntimeError:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1326–1327why, one step back1326 pytest.raises(BuildError, app.handle_url_build_error, error, "spam", {})1327Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1328why, one step back1328 # Test a custom handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1329why, one step back1329 def handler(error, endpoint, values):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1330why, one step back1330 # Just a test.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1331–1332why, one step back1331 return "/test_handler/"1332Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1333why, one step back1333 app.url_build_error_handlers.append(handler)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1334–1337why, one step back1334 with app.test_request_context():1335 assert flask.url_for("spam") == "/test_handler/"13361337Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1338–1341why, one step back1338def test_build_error_handler_reraise(app):1339 # Test a custom handler which reraises the BuildError1340 def handler_raises_build_error(error, endpoint, values):1341 raise errorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1342why, one step back1342Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1343why, one step back1343 app.url_build_error_handlers.append(handler_raises_build_error)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1344–1348why, one step back13441345 with app.test_request_context():1346 pytest.raises(BuildError, flask.url_for, "not.existing")13471348Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1349–1350why, one step back1349def test_url_for_passes_special_values_to_build_error_handler(app):1350 @app.url_build_error_handlers.appendMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1351why, one step back1351 def handler(error, endpoint, values):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1352why, one step back1352 assert values == {Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1353–1363why, one step back1353 "_external": False,1354 "_anchor": None,1355 "_method": None,1356 "_scheme": None,1357 }1358 return "handled"13591360 with app.test_request_context():1361 flask.url_for("/")13621363Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1364why, one step back1364def test_static_files(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1365–1372why, one step back1365 rv = client.get("/static/index.html")1366 assert rv.status_code == 2001367 assert rv.data.strip() == b"<h1>Hello World!</h1>"1368 with app.test_request_context():1369 assert flask.url_for("static", filename="index.html") == "/static/index.html"1370 rv.close()13711372Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1373why, one step back1373def test_static_url_path():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1374–1383why, one step back1374 app = flask.Flask(__name__, static_url_path="/foo")1375 app.testing = True1376 rv = app.test_client().get("/foo/index.html")1377 assert rv.status_code == 2001378 rv.close()13791380 with app.test_request_context():1381 assert flask.url_for("static", filename="index.html") == "/foo/index.html"13821383Merge pull request #3182 from qil026/issue-3134-url-joinDavid Lordbefore adoptiondbd3840
lines 1384–1394why, one step back1384def test_static_url_path_with_ending_slash():1385 app = flask.Flask(__name__, static_url_path="/foo/")1386 app.testing = True1387 rv = app.test_client().get("/foo/index.html")1388 assert rv.status_code == 2001389 rv.close()13901391 with app.test_request_context():1392 assert flask.url_for("static", filename="index.html") == "/foo/index.html"13931394Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
line 1395why, one step back1395def test_static_url_empty_path(app):Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1396–1397why, one step back1396 app = flask.Flask(__name__, static_folder="", static_url_path="")1397 rv = app.test_client().open("/static/index.html", method="GET")Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
lines 1398–1402why, one step back1398 assert rv.status_code == 2001399 rv.close()140014011402def test_static_url_empty_path_default(app):Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1403–1404why, one step back1403 app = flask.Flask(__name__, static_folder="")1404 rv = app.test_client().open("/static/index.html", method="GET")Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
lines 1405–1408why, one step back1405 assert rv.status_code == 2001406 rv.close()14071408Merge remote-tracking branch 'origin/1.1.x'David Lordbefore adoption64ba434
lines 1409–1419why, one step back1409def test_static_folder_with_ending_slash():1410 app = flask.Flask(__name__, static_folder="static/")14111412 @app.route("/<path:path>")1413 def catch_all(path):1414 return path14151416 rv = app.test_client().get("/catch/all")1417 assert rv.data == b"catch/all"14181419Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1420why, one step back1420def test_static_route_with_host_matching():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1421–1428why, one step back1421 app = flask.Flask(__name__, host_matching=True, static_host="example.com")1422 c = app.test_client()1423 rv = c.get("http://example.com/static/index.html")1424 assert rv.status_code == 2001425 rv.close()1426 with app.test_request_context():1427 rv = flask.url_for("static", filename="index.html", _external=True)1428 assert rv == "http://example.com/static/index.html"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1429why, one step back1429 # Providing static_host without host_matching=True should error.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1430–1431why, one step back1430 with pytest.raises(Exception):1431 flask.Flask(__name__, static_host="example.com")Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 1432–1433why, one step back1432 # Providing host_matching=True with static_folder1433 # but without static_host should error.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1434why, one step back1434 with pytest.raises(Exception):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1435why, one step back1435 flask.Flask(__name__, host_matching=True)Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 1436–1437why, one step back1436 # Providing host_matching=True without static_host1437 # but with static_folder=None should not error.Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1438why, one step back1438 flask.Flask(__name__, host_matching=True, static_folder=None)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1439–1440why, one step back14391440Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1441why, one step back1441def test_request_locals():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1442why, one step back1442 assert repr(flask.g) == "<LocalProxy unbound>"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1443why, one step back1443 assert not flask.gMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1444–1445why, one step back14441445Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1446why, one step back1446def test_server_name_subdomain():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1447–1451why, one step back1447 app = flask.Flask(__name__, subdomain_matching=True)1448 client = app.test_client()14491450 @app.route("/")1451 def index():Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1452why, one step back1452 return "default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1453–1454why, one step back14531454 @app.route("/", subdomain="foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1455why, one step back1455 def subdomain():Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1456why, one step back1456 return "subdomain"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1457why, one step back1457Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1458why, one step back1458 app.config["SERVER_NAME"] = "dev.local:5000"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1459why, one step back1459 rv = client.get("/")Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1460why, one step back1460 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1461why, one step back1461Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1462–1463why, one step back1462 rv = client.get("/", "http://dev.local:5000")1463 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1464why, one step back1464Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1465–1466why, one step back1465 rv = client.get("/", "https://dev.local:5000")1466 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1467why, one step back1467Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1468–1469why, one step back1468 app.config["SERVER_NAME"] = "dev.local:443"1469 rv = client.get("/", "https://dev.local")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1470why, one step back1470Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1471–1473why, one step back1471 # Werkzeug 1.0 fixes matching https scheme with 443 port1472 if rv.status_code != 404:1473 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1474why, one step back1474Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1475–1480why, one step back1475 app.config["SERVER_NAME"] = "dev.local"1476 rv = client.get("/", "https://dev.local")1477 assert rv.data == b"default"14781479 # suppress Werkzeug 1.0 warning about name mismatch1480 with pytest.warns(None):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1481–1483why, one step back1481 rv = client.get("/", "http://foo.localhost")1482 assert rv.status_code == 4041483Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1484–1485why, one step back1484 rv = client.get("/", "http://foo.dev.local")1485 assert rv.data == b"subdomain"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1486–1487why, one step back14861487Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1488–1489why, one step back1488def test_exception_propagation(app, client):1489 def apprunner(config_key):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1490–1493why, one step back1490 @app.route("/")1491 def index():1492 1 // 01493Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1494–1496why, one step back1494 if config_key is not None:1495 app.config[config_key] = True1496 with pytest.raises(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1497–1500why, one step back1497 client.get("/")1498 else:1499 assert client.get("/").status_code == 5001500Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1501–1504why, one step back1501 # we have to run this test in an isolated thread because if the1502 # debug flag is set to true and an exception happens the context is1503 # not torn down. This causes other tests that run after this fail1504 # when they expect no exception on the stack.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1505why, one step back1505 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1506–1508why, one step back1506 t = Thread(target=apprunner, args=(config_key,))1507 t.start()1508 t.join()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1509–1525why, one step back150915101511@pytest.mark.parametrize("debug", [True, False])1512@pytest.mark.parametrize("use_debugger", [True, False])1513@pytest.mark.parametrize("use_reloader", [True, False])1514@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1515def test_werkzeug_passthrough_errors(1516 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1517):1518 rv = {}15191520 # Mocks werkzeug.serving.run_simple method1521 def run_simple_mock(*args, **kwargs):1522 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15231524 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1525 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptionsMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1526why, one step back1526 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1527–1528why, one step back15271528Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1529why, one step back1529def test_max_content_length(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1530–1532why, one step back1530 app.config["MAX_CONTENT_LENGTH"] = 6415311532 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1533why, one step back1533 def always_first():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1534why, one step back1534 flask.request.form["myfile"]Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1535why, one step back1535 AssertionError()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1536–1537why, one step back15361537 @app.route("/accept", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1538why, one step back1538 def accept_file():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1539why, one step back1539 flask.request.form["myfile"]Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1540why, one step back1540 AssertionError()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1541why, one step back1541Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1542–1543why, one step back1542 @app.errorhandler(413)1543 def catcher(error):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1544–1549why, one step back1544 return "42"15451546 rv = client.post("/accept", data={"myfile": "foo" * 100})1547 assert rv.data == b"42"15481549Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1550–1552why, one step back1550def test_url_processors(app, client):1551 @app.url_defaults1552 def add_language_code(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1553–1557why, one step back1553 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(1554 endpoint, "lang_code"1555 ):1556 values.setdefault("lang_code", flask.g.lang_code)1557Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1558–1559why, one step back1558 @app.url_value_preprocessor1559 def pull_lang_code(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1560–1566why, one step back1560 flask.g.lang_code = values.pop("lang_code", None)15611562 @app.route("/<lang_code>/")1563 def index():1564 return flask.url_for("about")15651566 @app.route("/<lang_code>/about")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1567why, one step back1567 def about():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1568–1570why, one step back1568 return flask.url_for("something_else")15691570 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1571why, one step back1571 def something_else():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1572–1578why, one step back1572 return flask.url_for("about", lang_code="en")15731574 assert client.get("/de/").data == b"/de/about"1575 assert client.get("/de/about").data == b"/foo"1576 assert client.get("/foo").data == b"/en/about"15771578Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1579why, one step back1579def test_inject_blueprint_url_defaults(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1580–1581why, one step back1580 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")1581Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1582–1583why, one step back1582 @bp.url_defaults1583 def bp_defaults(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1584–1586why, one step back1584 values["page"] = "login"15851586 @bp.route("/<page>")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1587why, one step back1587 def view(page):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1588–1589why, one step back1588 pass1589Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1590why, one step back1590 app.register_blueprint(bp)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1591why, one step back1591Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1592why, one step back1592 values = dict()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1593–1594why, one step back1593 app.inject_url_defaults("foo.bar.baz.view", values)1594 expected = dict(page="login")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1595why, one step back1595 assert values == expectedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1596–1599why, one step back15961597 with app.test_request_context("/somepage"):1598 url = flask.url_for("foo.bar.baz.view")1599 expected = "/login"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1600why, one step back1600 assert url == expectedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1601–1602why, one step back16011602Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1603why, one step back1603def test_nonascii_pathinfo(app, client):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1604why, one step back1604 @app.route("/киртест")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1605–1607why, one step back1605 def index():1606 return "Hello World!"1607Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1608why, one step back1608 rv = client.get("/киртест")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1609–1611why, one step back1609 assert rv.data == b"Hello World!"16101611Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1612why, one step back1612def test_debug_mode_complains_after_first_request(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1613–1618why, one step back1613 app.debug = True16141615 @app.route("/")1616 def index():1617 return "Awesome"1618Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1619why, one step back1619 assert not app.got_first_requestMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1620why, one step back1620 assert client.get("/").data == b"Awesome"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1621why, one step back1621 with pytest.raises(AssertionError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1622–1623why, one step back16221623 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1624why, one step back1624 def broken():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1625–1626why, one step back1625 return "Meh"1626Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1627why, one step back1627 assert "A setup function was called" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1628–1631why, one step back16281629 app.debug = False16301631 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1632why, one step back1632 def working():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1633–1638why, one step back1633 return "Meh"16341635 assert client.get("/foo").data == b"Meh"1636 assert app.got_first_request16371638Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1639why, one step back1639def test_before_first_request_functions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1640–1652why, one step back1640 got = []16411642 @app.before_first_request1643 def foo():1644 got.append(42)16451646 client.get("/")1647 assert got == [42]1648 client.get("/")1649 assert got == [42]1650 assert app.got_first_request16511652Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1653why, one step back1653def test_before_first_request_functions_concurrent(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1654–1657why, one step back1654 got = []16551656 @app.before_first_request1657 def foo():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1658why, one step back1658 time.sleep(0.2)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1659–1660why, one step back1659 got.append(42)1660Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1661why, one step back1661 def get_and_assert():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1662why, one step back1662 client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1663why, one step back1663 assert got == [42]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1664why, one step back1664Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1665–1668why, one step back1665 t = Thread(target=get_and_assert)1666 t.start()1667 get_and_assert()1668 t.join()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1669–1671why, one step back1669 assert app.got_first_request16701671Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1672why, one step back1672def test_routing_redirect_debugging(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1673–1679why, one step back1673 app.debug = True16741675 @app.route("/foo/", methods=["GET", "POST"])1676 def foo():1677 return "success"16781679 with client:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1680why, one step back1680 with pytest.raises(AssertionError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1681why, one step back1681 client.post("/foo", data={})Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1682why, one step back1682 assert "http://localhost/foo/" in str(e.value)Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b
line 1683why, one step back1683 assert "Make sure to directly send your POST-request to this URL" in str(Merge branch '1.0.x'David Lordbefore adoptionb05a685
lines 1684–1685why, one step back1684 e.value1685 )Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1686–1695why, one step back16861687 rv = client.get("/foo", data={}, follow_redirects=True)1688 assert rv.data == b"success"16891690 app.debug = False1691 with client:1692 rv = client.post("/foo", data={}, follow_redirects=True)1693 assert rv.data == b"success"16941695Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1696why, one step back1696def test_route_decorator_custom_endpoint(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1697–1703why, one step back1697 app.debug = True16981699 @app.route("/foo/")1700 def foo():1701 return flask.request.endpoint17021703 @app.route("/bar/", endpoint="bar")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1704why, one step back1704 def for_bar():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1705–1707why, one step back1705 return flask.request.endpoint17061707 @app.route("/bar/123", endpoint="123")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1708why, one step back1708 def for_bar_foo():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1709–1720why, one step back1709 return flask.request.endpoint17101711 with app.test_request_context():1712 assert flask.url_for("foo") == "/foo/"1713 assert flask.url_for("bar") == "/bar/"1714 assert flask.url_for("123") == "/bar/123"17151716 assert client.get("/foo/").data == b"foo"1717 assert client.get("/bar/").data == b"bar"1718 assert client.get("/bar/123").data == b"123"17191720Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1721why, one step back1721def test_preserve_only_once(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1722–1727why, one step back1722 app.debug = True17231724 @app.route("/fail")1725 def fail_func():1726 1 // 01727Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1728why, one step back1728 for _x in range(3):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1729why, one step back1729 with pytest.raises(ZeroDivisionError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1730–1731why, one step back1730 client.get("/fail")1731Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1732–1737why, one step back1732 assert flask._request_ctx_stack.top is not None1733 assert flask._app_ctx_stack.top is not None1734 # implicit appctx disappears too1735 flask._request_ctx_stack.top.pop()1736 assert flask._request_ctx_stack.top is None1737 assert flask._app_ctx_stack.top is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1738–1739why, one step back17381739Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1740why, one step back1740def test_preserve_remembers_exception(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1741why, one step back1741 app.debug = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1742why, one step back1742 errors = []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1743–1748why, one step back17431744 @app.route("/fail")1745 def fail_func():1746 1 // 017471748 @app.route("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1749why, one step back1749 def success_func():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1750–1752why, one step back1750 return "Okay"17511752 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1753–1754why, one step back1753 def teardown_handler(exc):1754 errors.append(exc)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1755why, one step back1755Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1756–1757why, one step back1756 # After this failure we did not yet call the teardown handler1757 with pytest.raises(ZeroDivisionError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1758why, one step back1758 client.get("/fail")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1759why, one step back1759 assert errors == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1760why, one step back1760Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1761why, one step back1761 # But this request triggers it, and it's an errorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1762why, one step back1762 client.get("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1763–1764why, one step back1763 assert len(errors) == 21764 assert isinstance(errors[0], ZeroDivisionError)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1765why, one step back1765Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1766why, one step back1766 # At this point another request does nothing.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1767why, one step back1767 client.get("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1768–1769why, one step back1768 assert len(errors) == 31769 assert errors[1] is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1770–1771why, one step back17701771Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1772why, one step back1772def test_get_method_on_g(app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1773–1774why, one step back1773 assert flask.g.get("x") is None1774 assert flask.g.get("x", 11) == 11Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1775why, one step back1775 flask.g.x = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1776why, one step back1776 assert flask.g.get("x") == 42Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1777why, one step back1777 assert flask.g.x == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1778–1779why, one step back17781779Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1780–1782why, one step back1780def test_g_iteration_protocol(app_ctx):1781 flask.g.foo = 231782 flask.g.bar = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1783–1787why, one step back1783 assert "foo" in flask.g1784 assert "foos" not in flask.g1785 assert sorted(flask.g) == ["bar", "foo"]17861787Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1788why, one step back1788def test_subdomain_basic_support():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1789–1793why, one step back1789 app = flask.Flask(__name__, subdomain_matching=True)1790 app.config["SERVER_NAME"] = "localhost.localdomain"1791 client = app.test_client()17921793 @app.route("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1794why, one step back1794 def normal_index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1795–1797why, one step back1795 return "normal index"17961797 @app.route("/", subdomain="test")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1798why, one step back1798 def test_index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1799–1807why, one step back1799 return "test index"18001801 rv = client.get("/", "http://localhost.localdomain/")1802 assert rv.data == b"normal index"18031804 rv = client.get("/", "http://test.localhost.localdomain/")1805 assert rv.data == b"test index"18061807Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1808why, one step back1808def test_subdomain_matching():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1809–1814why, one step back1809 app = flask.Flask(__name__, subdomain_matching=True)1810 client = app.test_client()1811 app.config["SERVER_NAME"] = "localhost.localdomain"18121813 @app.route("/", subdomain="<user>")1814 def index(user):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1815why, one step back1815 return f"index for {user}"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1816–1820why, one step back18161817 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1818 assert rv.data == b"index for mitsuhiko"18191820Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1821why, one step back1821def test_subdomain_matching_with_ports():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1822–1827why, one step back1822 app = flask.Flask(__name__, subdomain_matching=True)1823 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1824 client = app.test_client()18251826 @app.route("/", subdomain="<user>")1827 def index(user):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1828why, one step back1828 return f"index for {user}"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1829–1834why, one step back18291830 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1831 assert rv.data == b"index for mitsuhiko"183218331834@pytest.mark.parametrize("matching", (False, True))Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1835–1836why, one step back1835def test_subdomain_matching_other_name(matching):1836 app = flask.Flask(__name__, subdomain_matching=matching)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1837–1843why, one step back1837 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1838 client = app.test_client()18391840 @app.route("/")1841 def index():1842 return "", 2041843Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1844–1848why, one step back1844 # suppress Werkzeug 0.15 warning about name mismatch1845 with pytest.warns(None):1846 # ip address can't match name1847 rv = client.get("/", "http://127.0.0.1:3000/")1848 assert rv.status_code == 404 if matching else 204Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1849why, one step back1849Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1850why, one step back1850 # allow all subdomains if matching is disabledMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1851–1854why, one step back1851 rv = client.get("/", "http://www.localhost.localdomain:3000/")1852 assert rv.status_code == 404 if matching else 20418531854Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1855why, one step back1855def test_multi_route_rules(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1856–1858why, one step back1856 @app.route("/")1857 @app.route("/<test>/")1858 def index(test="a"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1859why, one step back1859 return testMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1860–1866why, one step back18601861 rv = client.open("/")1862 assert rv.data == b"a"1863 rv = client.open("/b/")1864 assert rv.data == b"b"18651866Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1867why, one step back1867def test_multi_route_class_views(app, client):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1868why, one step back1868 class View:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1869why, one step back1869 def __init__(self, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1870–1873why, one step back1870 app.add_url_rule("/", "index", self.index)1871 app.add_url_rule("/<test>/", "index", self.index)18721873 def index(self, test="a"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1874why, one step back1874 return testMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1875why, one step back1875Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1876why, one step back1876 _ = View(app)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1877–1882why, one step back1877 rv = client.open("/")1878 assert rv.data == b"a"1879 rv = client.open("/b/")1880 assert rv.data == b"b"18811882Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1883why, one step back1883def test_run_defaults(monkeypatch, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1884–1890why, one step back1884 rv = {}18851886 # Mocks werkzeug.serving.run_simple method1887 def run_simple_mock(*args, **kwargs):1888 rv["result"] = "running..."18891890 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1891why, one step back1891 app.run()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1892–1894why, one step back1892 assert rv["result"] == "running..."18931894Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1895why, one step back1895def test_run_server_port(monkeypatch, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1896–1898why, one step back1896 rv = {}18971898 # Mocks werkzeug.serving.run_simple methodMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1899why, one step back1899 def run_simple_mock(hostname, port, application, *args, **kwargs):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1900why, one step back1900 rv["result"] = f"running on {hostname}:{port} ..."Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1901–1903why, one step back19011902 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1903 hostname, port = "localhost", 8000Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1904why, one step back1904 app.run(hostname, port, debug=True)Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 1905why, one step back1905 assert rv["result"] == f"running on {hostname}:{port} ..."Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1906–1908why, one step back190619071908@pytest.mark.parametrize(Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
line 1909why, one step back1909 "host,port,server_name,expect_host,expect_port",Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1910why, one step back1910 (Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
lines 1911–1917why, one step back1911 (None, None, "pocoo.org:8080", "pocoo.org", 8080),1912 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1913 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1914 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1915 ("localhost", 0, "localhost:8080", "localhost", 0),1916 (None, None, "localhost:8080", "localhost", 8080),1917 (None, None, "localhost:0", "localhost", 0),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1918–1919why, one step back1918 ),1919)Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1920–1922why, one step back1920def test_run_from_config(1921 monkeypatch, host, port, server_name, expect_host, expect_port, app1922):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1923–1925why, one step back1923 def run_simple_mock(hostname, port, *args, **kwargs):1924 assert hostname == expect_host1925 assert port == expect_portMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1926–1927why, one step back19261927 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
line 1928why, one step back1928 app.config["SERVER_NAME"] = server_nameMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1929why, one step back1929 app.run(host, port)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1930–1931why, one step back19301931Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1932why, one step back1932def test_max_cookie_size(app, client, recwarn):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1933–1934why, one step back1933 app.config["MAX_COOKIE_SIZE"] = 1001934Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1935–1937why, one step back1935 # outside app context, default to Werkzeug static value,1936 # which is also the default config1937 response = flask.Response()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1938why, one step back1938 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1939why, one step back1939 assert response.max_cookie_size == defaultMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1940why, one step back1940Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1941–1943why, one step back1941 # inside app context, use app config1942 with app.app_context():1943 assert flask.Response().max_cookie_size == 100Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1944–1948why, one step back19441945 @app.route("/")1946 def index():1947 r = flask.Response("", status=204)1948 r.set_cookie("foo", "bar" * 100)Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1949why, one step back1949 return rMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1950–1951why, one step back19501951 client.get("/")Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1952–1953why, one step back1952 assert len(recwarn) == 11953 w = recwarn.pop()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1954–1958why, one step back1954 assert "cookie is too large" in str(w.message)19551956 app.config["MAX_COOKIE_SIZE"] = 019571958 client.get("/")Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1959why, one step back1959 assert len(recwarn) == 0