test_basic.py
This file
Path
tests/test_basic.py
1,969 lines · 52.7 KiB · Python
Last changed by
remove more compat codeDavid Lordbefore adoption57d628c
History of this fileTake it
The walk stopped after 200 commits: lines older than 16d83d6 point at it.
Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 tests.basic4 ~~~~~~~~~~~~~~~~~~~~~56 The basic functionality.7Merge branch '1.0.x'David Lordbefore adoption1351d0a
lines 8–9why, one step back8 :copyright: 2010 Pallets9 :license: BSD-3-ClauseMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 10–11why, one step back10"""11import reMerge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
line 12why, one step back12import sysMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 13–19why, one step back13import time14import uuid15from datetime import datetime16from threading import Thread1718import pytest19import werkzeug.servingMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 20–22why, one step back20from werkzeug.exceptions import BadRequest21from werkzeug.exceptions import Forbidden22from werkzeug.exceptions import NotFoundMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 23–29why, one step back23from werkzeug.http import parse_date24from werkzeug.routing import BuildError2526import flask272829def test_options_work(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 30–38why, one step back30 @app.route("/", methods=["GET", "POST"])31 def index():32 return "Hello World"3334 rv = client.open("/", method="OPTIONS")35 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]36 assert rv.data == b""3738Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 39why, one step back39def test_options_on_multiple_rules(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 40–44why, one step back40 @app.route("/", methods=["GET", "POST"])41 def index():42 return "Hello World"4344 @app.route("/", methods=["PUT"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 45why, one step back45 def index_put():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 46–51why, one step back46 return "Aha!"4748 rv = client.open("/", method="OPTIONS")49 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]5051Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 52why, one step back52def test_provide_automatic_options_attr():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 53–57why, one step back53 app = flask.Flask(__name__)5455 def index():56 return "Hello World!"57Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 58why, one step back58 index.provide_automatic_options = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 59–67why, one step back59 app.route("/")(index)60 rv = app.test_client().open("/", method="OPTIONS")61 assert rv.status_code == 4056263 app = flask.Flask(__name__)6465 def index2():66 return "Hello World!"67Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 68why, one step back68 index2.provide_automatic_options = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 69–73why, one step back69 app.route("/", methods=["OPTIONS"])(index2)70 rv = app.test_client().open("/", method="OPTIONS")71 assert sorted(rv.allow) == ["OPTIONS"]7273Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 74why, one step back74def test_provide_automatic_options_kwarg(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 75–81why, one step back75 def index():76 return flask.request.method7778 def more():79 return flask.request.method8081 app.add_url_rule("/", view_func=index, provide_automatic_options=False)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 82why, one step back82 app.add_url_rule(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 83–93why, one step back83 "/more",84 view_func=more,85 methods=["GET", "POST"],86 provide_automatic_options=False,87 )88 assert client.get("/").data == b"GET"8990 rv = client.post("/")91 assert rv.status_code == 40592 assert sorted(rv.allow) == ["GET", "HEAD"]93remove more compat codeDavid Lordbefore adoption57d628c
line 94why, one step back94 rv = client.open("/", method="OPTIONS")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 95–106why, one step back95 assert rv.status_code == 4059697 rv = client.head("/")98 assert rv.status_code == 20099 assert not rv.data # head truncates100 assert client.post("/more").data == b"POST"101 assert client.get("/more").data == b"GET"102103 rv = client.delete("/more")104 assert rv.status_code == 405105 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]106remove more compat codeDavid Lordbefore adoption57d628c
line 107why, one step back107 rv = client.open("/more", method="OPTIONS")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 108–110why, one step back108 assert rv.status_code == 405109110Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 111why, one step back111def test_request_dispatching(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 112–133why, one step back112 @app.route("/")113 def index():114 return flask.request.method115116 @app.route("/more", methods=["GET", "POST"])117 def more():118 return flask.request.method119120 assert client.get("/").data == b"GET"121 rv = client.post("/")122 assert rv.status_code == 405123 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]124 rv = client.head("/")125 assert rv.status_code == 200126 assert not rv.data # head truncates127 assert client.post("/more").data == b"POST"128 assert client.get("/more").data == b"GET"129 rv = client.delete("/more")130 assert rv.status_code == 405131 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]132133Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 134–135why, one step back134def test_disallow_string_for_allowed_methods(app):135 with pytest.raises(TypeError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 136–138why, one step back136137 @app.route("/", methods="GET POST")138 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 139why, one step back139 return "Hey"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 140–141why, one step back140141Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 142–143why, one step back142def test_url_mapping(app, client):143 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 144–150why, one step back144145 def index():146 return flask.request.method147148 def more():149 return flask.request.method150Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 151–152why, one step back151 def options():152 return random_uuid4Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 153–156why, one step back153154 app.add_url_rule("/", "index", index)155 app.add_url_rule("/more", "more", more, methods=["GET", "POST"])156Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 157–158why, one step back157 # Issue 1288: Test that automatic options are not added158 # when non-uppercase 'options' in methodsMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 159–174why, one step back159 app.add_url_rule("/options", "options", options, methods=["options"])160161 assert client.get("/").data == b"GET"162 rv = client.post("/")163 assert rv.status_code == 405164 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS"]165 rv = client.head("/")166 assert rv.status_code == 200167 assert not rv.data # head truncates168 assert client.post("/more").data == b"POST"169 assert client.get("/more").data == b"GET"170 rv = client.delete("/more")171 assert rv.status_code == 405172 assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]173 rv = client.open("/options", method="OPTIONS")174 assert rv.status_code == 200Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 175why, one step back175 assert random_uuid4 in rv.data.decode("utf-8")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 176–177why, one step back176177Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 178why, one step back178def test_werkzeug_routing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 179–197why, one step back179 from werkzeug.routing import Submount, Rule180181 app.url_map.add(182 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])183 )184185 def bar():186 return "bar"187188 def index():189 return "index"190191 app.view_functions["bar"] = bar192 app.view_functions["index"] = index193194 assert client.get("/foo/").data == b"index"195 assert client.get("/foo/bar").data == b"bar"196197Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 198why, one step back198def test_endpoint_decorator(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 199–216why, one step back199 from werkzeug.routing import Submount, Rule200201 app.url_map.add(202 Submount("/foo", [Rule("/bar", endpoint="bar"), Rule("/", endpoint="index")])203 )204205 @app.endpoint("bar")206 def bar():207 return "bar"208209 @app.endpoint("index")210 def index():211 return "index"212213 assert client.get("/foo/").data == b"index"214 assert client.get("/foo/bar").data == b"bar"215216Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 217why, one step back217def test_session(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 218why, one step back218 @app.route("/set", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 219why, one step back219 def set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 220–223why, one step back220 assert not flask.session.accessed221 assert not flask.session.modified222 flask.session["value"] = flask.request.form["value"]223 assert flask.session.accessedMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 224why, one step back224 assert flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 225–233why, one step back225 return "value set"226227 @app.route("/get")228 def get():229 assert not flask.session.accessed230 assert not flask.session.modified231 v = flask.session.get("value", "None")232 assert flask.session.accessed233 assert not flask.session.modifiedMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 234why, one step back234 return vMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 235–239why, one step back235236 assert client.post("/set", data={"value": "42"}).data == b"value set"237 assert client.get("/get").data == b"42"238239Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 240why, one step back240def test_session_using_server_name(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 241–252why, one step back241 app.config.update(SERVER_NAME="example.com")242243 @app.route("/")244 def index():245 flask.session["testing"] = 42246 return "Hello World"247248 rv = client.get("/", "http://example.com/")249 assert "domain=.example.com" in rv.headers["set-cookie"].lower()250 assert "httponly" in rv.headers["set-cookie"].lower()251252Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 253why, one step back253def test_session_using_server_name_and_port(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 254–265why, one step back254 app.config.update(SERVER_NAME="example.com:8080")255256 @app.route("/")257 def index():258 flask.session["testing"] = 42259 return "Hello World"260261 rv = client.get("/", "http://example.com:8080/")262 assert "domain=.example.com" in rv.headers["set-cookie"].lower()263 assert "httponly" in rv.headers["set-cookie"].lower()264265Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 266why, one step back266def test_session_using_server_name_port_and_path(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 267–279why, one step back267 app.config.update(SERVER_NAME="example.com:8080", APPLICATION_ROOT="/foo")268269 @app.route("/")270 def index():271 flask.session["testing"] = 42272 return "Hello World"273274 rv = client.get("/", "http://example.com:8080/foo")275 assert "domain=example.com" in rv.headers["set-cookie"].lower()276 assert "path=/foo" in rv.headers["set-cookie"].lower()277 assert "httponly" in rv.headers["set-cookie"].lower()278279Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 280–284why, one step back280def test_session_using_application_root(app, client):281 class PrefixPathMiddleware(object):282 def __init__(self, app, prefix):283 self.app = app284 self.prefix = prefixMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 285why, one step back285Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 286why, one step back286 def __call__(self, environ, start_response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 287why, one step back287 environ["SCRIPT_NAME"] = self.prefixMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 288why, one step back288 return self.app(environ, start_response)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 289–301why, one step back289290 app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, "/bar")291 app.config.update(APPLICATION_ROOT="/bar")292293 @app.route("/")294 def index():295 flask.session["testing"] = 42296 return "Hello World"297298 rv = client.get("/", "http://example.com:8080/")299 assert "path=/bar" in rv.headers["set-cookie"].lower()300301Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 302why, one step back302def test_session_using_session_settings(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 303–306why, one step back303 app.config.update(304 SERVER_NAME="www.example.com:8080",305 APPLICATION_ROOT="/test",306 SESSION_COOKIE_DOMAIN=".example.com",Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 307–308why, one step back307 SESSION_COOKIE_HTTPONLY=False,308 SESSION_COOKIE_SECURE=True,Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 309–326why, one step back309 SESSION_COOKIE_SAMESITE="Lax",310 SESSION_COOKIE_PATH="/",311 )312313 @app.route("/")314 def index():315 flask.session["testing"] = 42316 return "Hello World"317318 rv = client.get("/", "http://www.example.com:8080/test/")319 cookie = rv.headers["set-cookie"].lower()320 assert "domain=.example.com" in cookie321 assert "path=/" in cookie322 assert "secure" in cookie323 assert "httponly" not in cookie324 assert "samesite" in cookie325326Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 327why, one step back327def test_session_using_samesite_attribute(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 328–334why, one step back328 @app.route("/")329 def index():330 flask.session["testing"] = 42331 return "Hello World"332333 app.config.update(SESSION_COOKIE_SAMESITE="invalid")334Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 335why, one step back335 with pytest.raises(ValueError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 336–337why, one step back336 client.get("/")337Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 338why, one step back338 app.config.update(SESSION_COOKIE_SAMESITE=None)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 339–353why, one step back339 rv = client.get("/")340 cookie = rv.headers["set-cookie"].lower()341 assert "samesite" not in cookie342343 app.config.update(SESSION_COOKIE_SAMESITE="Strict")344 rv = client.get("/")345 cookie = rv.headers["set-cookie"].lower()346 assert "samesite=strict" in cookie347348 app.config.update(SESSION_COOKIE_SAMESITE="Lax")349 rv = client.get("/")350 cookie = rv.headers["set-cookie"].lower()351 assert "samesite=lax" in cookie352353Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 354why, one step back354def test_session_localhost_warning(recwarn, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 355–364why, one step back355 app.config.update(SERVER_NAME="localhost:5000")356357 @app.route("/")358 def index():359 flask.session["testing"] = 42360 return "testing"361362 rv = client.get("/", "http://localhost:5000/")363 assert "domain" not in rv.headers["set-cookie"].lower()364 w = recwarn.pop(UserWarning)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 365why, one step back365 assert '"localhost" is not a valid cookie domain' in str(w.message)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 366–367why, one step back366367Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 368why, one step back368def test_session_ip_warning(recwarn, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 369–381why, one step back369 app.config.update(SERVER_NAME="127.0.0.1:5000")370371 @app.route("/")372 def index():373 flask.session["testing"] = 42374 return "testing"375376 rv = client.get("/", "http://127.0.0.1:5000/")377 assert "domain=127.0.0.1" in rv.headers["set-cookie"].lower()378 w = recwarn.pop(UserWarning)379 assert "cookie domain is an IP" in str(w.message)380381Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 382–383why, one step back382def test_missing_session(app):383 app.secret_key = NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 384why, one step back384Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 385–386why, one step back385 def expect_exception(f, *args, **kwargs):386 e = pytest.raises(RuntimeError, f, *args, **kwargs)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 387–394why, one step back387 assert e.value.args and "session is unavailable" in e.value.args[0]388389 with app.test_request_context():390 assert flask.session.get("missing_key") is None391 expect_exception(flask.session.__setitem__, "foo", 42)392 expect_exception(flask.session.pop, "foo")393394Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 395–396why, one step back395def test_session_expiration(app, client):396 permanent = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 397–400why, one step back397398 @app.route("/")399 def index():400 flask.session["test"] = 42Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 401why, one step back401 flask.session.permanent = permanentMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 402–405why, one step back402 return ""403404 @app.route("/test")405 def test():remove _compat moduleDavid Lordbefore adoption662c245
line 406why, one step back406 return str(flask.session.permanent)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 407–410why, one step back407408 rv = client.get("/")409 assert "set-cookie" in rv.headers410 match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 411–415why, one step back411 expires = parse_date(match.group())412 expected = datetime.utcnow() + app.permanent_session_lifetime413 assert expires.year == expected.year414 assert expires.month == expected.month415 assert expires.day == expected.dayMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 416–419why, one step back416417 rv = client.get("/test")418 assert rv.data == b"True"419Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 420why, one step back420 permanent = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 421–423why, one step back421 rv = client.get("/")422 assert "set-cookie" in rv.headers423 match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 424why, one step back424 assert match is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 425–426why, one step back425426Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 427why, one step back427def test_session_stored_last(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 428why, one step back428 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 429why, one step back429 def modify_session(response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 430–440why, one step back430 flask.session["foo"] = 42431 return response432433 @app.route("/")434 def dump_session_contents():435 return repr(flask.session.get("foo"))436437 assert client.get("/").data == b"None"438 assert client.get("/").data == b"42"439440Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 441–443why, one step back441def test_session_special_types(app, client):442 now = datetime.utcnow().replace(microsecond=0)443 the_uuid = uuid.uuid4()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 444–458why, one step back444445 @app.route("/")446 def dump_session_contents():447 flask.session["t"] = (1, 2, 3)448 flask.session["b"] = b"\xff"449 flask.session["m"] = flask.Markup("<html>")450 flask.session["u"] = the_uuid451 flask.session["d"] = now452 flask.session["t_tag"] = {" t": "not-a-tuple"}453 flask.session["di_t_tag"] = {" t__": "not-a-tuple"}454 flask.session["di_tag"] = {" di": "not-a-dict"}455 return "", 204456457 with client:458 client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 459why, one step back459 s = flask.sessionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 460–471why, one step back460 assert s["t"] == (1, 2, 3)461 assert type(s["b"]) == bytes462 assert s["b"] == b"\xff"463 assert type(s["m"]) == flask.Markup464 assert s["m"] == flask.Markup("<html>")465 assert s["u"] == the_uuid466 assert s["d"] == now467 assert s["t_tag"] == {" t": "not-a-tuple"}468 assert s["di_t_tag"] == {" t__": "not-a-tuple"}469 assert s["di_tag"] == {" di": "not-a-dict"}470471Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 472why, one step back472def test_session_cookie_setting(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 473–475why, one step back473 is_permanent = True474475 @app.route("/bump")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 476why, one step back476 def bump():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 477why, one step back477 rv = flask.session["foo"] = flask.session.get("foo", 0) + 1Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 478–479why, one step back478 flask.session.permanent = is_permanent479 return str(rv)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 480–481why, one step back480481 @app.route("/read")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 482why, one step back482 def read():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 483–484why, one step back483 return str(flask.session.get("foo", 0))484Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 485–486why, one step back485 def run_test(expect_header):486 with app.test_client() as c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 487–492why, one step back487 assert c.get("/bump").data == b"1"488 assert c.get("/bump").data == b"2"489 assert c.get("/bump").data == b"3"490491 rv = c.get("/read")492 set_cookie = rv.headers.get("set-cookie")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 493why, one step back493 assert (set_cookie is not None) == expect_headerMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 494–497why, one step back494 assert rv.data == b"3"495496 is_permanent = True497 app.config["SESSION_REFRESH_EACH_REQUEST"] = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 498why, one step back498 run_test(expect_header=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 499–512why, one step back499500 is_permanent = True501 app.config["SESSION_REFRESH_EACH_REQUEST"] = False502 run_test(expect_header=False)503504 is_permanent = False505 app.config["SESSION_REFRESH_EACH_REQUEST"] = True506 run_test(expect_header=False)507508 is_permanent = False509 app.config["SESSION_REFRESH_EACH_REQUEST"] = False510 run_test(expect_header=False)511512Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 513why, one step back513def test_session_vary_cookie(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 514why, one step back514 @app.route("/set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 515why, one step back515 def set_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 516–523why, one step back516 flask.session["test"] = "test"517 return ""518519 @app.route("/get")520 def get():521 return flask.session.get("test")522523 @app.route("/getitem")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 524why, one step back524 def getitem():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 525–527why, one step back525 return flask.session["test"]526527 @app.route("/setdefault")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 528why, one step back528 def setdefault():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 529–531why, one step back529 return flask.session.setdefault("test", "default")530531 @app.route("/vary-cookie-header-set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 532why, one step back532 def vary_cookie_header_set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 533–538why, one step back533 response = flask.Response()534 response.vary.add("Cookie")535 flask.session["test"] = "test"536 return response537538 @app.route("/vary-header-set")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 539why, one step back539 def vary_header_set():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 540–545why, one step back540 response = flask.Response()541 response.vary.update(("Accept-Encoding", "Accept-Language"))542 flask.session["test"] = "test"543 return response544545 @app.route("/no-vary-header")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 546why, one step back546 def no_vary_header():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 547–549why, one step back547 return ""548549 def expect(path, header_value="Cookie"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 550why, one step back550 rv = client.get(path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 551why, one step back551Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 552–553why, one step back552 if header_value:553 # The 'Vary' key should exist in the headers only once.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 554–567why, one step back554 assert len(rv.headers.get_all("Vary")) == 1555 assert rv.headers["Vary"] == header_value556 else:557 assert "Vary" not in rv.headers558559 expect("/set")560 expect("/get")561 expect("/getitem")562 expect("/setdefault")563 expect("/vary-cookie-header-set")564 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")565 expect("/no-vary-header", None)566567Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 568–569why, one step back568def test_flashes(app, req_ctx):569 assert not flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 570why, one step back570 flask.flash("Zap")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 571why, one step back571 flask.session.modified = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 572why, one step back572 flask.flash("Zip")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 573why, one step back573 assert flask.session.modifiedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 574–576why, one step back574 assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]575576Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 577–582why, one step back577def test_extended_flashing(app):578 # Be sure app.testing=True below, else tests can fail silently.579 #580 # Specifically, if app.testing is not set to True, the AssertionErrors581 # in the view functions will cause a 500 response to the test client582 # instead of propagating exceptions.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 583–592why, one step back583584 @app.route("/")585 def index():586 flask.flash(u"Hello World")587 flask.flash(u"Hello World", "error")588 flask.flash(flask.Markup(u"<em>Testing</em>"), "warning")589 return ""590591 @app.route("/test/")592 def test():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 593why, one step back593 messages = flask.get_flashed_messages()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 594–601why, one step back594 assert list(messages) == [595 u"Hello World",596 u"Hello World",597 flask.Markup(u"<em>Testing</em>"),598 ]599 return ""600601 @app.route("/test_with_categories/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 602–604why, one step back602 def test_with_categories():603 messages = flask.get_flashed_messages(with_categories=True)604 assert len(messages) == 3Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 605–612why, one step back605 assert list(messages) == [606 ("message", u"Hello World"),607 ("error", u"Hello World"),608 ("warning", flask.Markup(u"<em>Testing</em>")),609 ]610 return ""611612 @app.route("/test_filter/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 613why, one step back613 def test_filter():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 614–620why, one step back614 messages = flask.get_flashed_messages(615 category_filter=["message"], with_categories=True616 )617 assert list(messages) == [("message", u"Hello World")]618 return ""619620 @app.route("/test_filters/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 621why, one step back621 def test_filters():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 622–631why, one step back622 messages = flask.get_flashed_messages(623 category_filter=["message", "warning"], with_categories=True624 )625 assert list(messages) == [626 ("message", u"Hello World"),627 ("warning", flask.Markup(u"<em>Testing</em>")),628 ]629 return ""630631 @app.route("/test_filters_without_returning_categories/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 632why, one step back632 def test_filters2():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 633why, one step back633 messages = flask.get_flashed_messages(category_filter=["message", "warning"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 634why, one step back634 assert len(messages) == 2Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 635–638why, one step back635 assert messages[0] == u"Hello World"636 assert messages[1] == flask.Markup(u"<em>Testing</em>")637 return ""638Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 639why, one step back639 # Create new test client on each test to clean flashed messages.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 640–657why, one step back640641 client = app.test_client()642 client.get("/")643 client.get("/test_with_categories/")644645 client = app.test_client()646 client.get("/")647 client.get("/test_filter/")648649 client = app.test_client()650 client.get("/")651 client.get("/test_filters/")652653 client = app.test_client()654 client.get("/")655 client.get("/test_filters_without_returning_categories/")656657Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 658why, one step back658def test_request_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 659–682why, one step back659 evts = []660661 @app.before_request662 def before_request():663 evts.append("before")664665 @app.after_request666 def after_request(response):667 response.data += b"|after"668 evts.append("after")669 return response670671 @app.route("/")672 def index():673 assert "before" in evts674 assert "after" not in evts675 return "request"676677 assert "after" not in evts678 rv = client.get("/").data679 assert "after" in evts680 assert rv == b"request|after"681682Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 683why, one step back683def test_request_preprocessing_early_return(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 684–686why, one step back684 evts = []685686 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 687–688why, one step back687 def before_request1():688 evts.append(1)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 689–690why, one step back689690 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 691–693why, one step back691 def before_request2():692 evts.append(2)693 return "hello"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 694–695why, one step back694695 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 696–698why, one step back696 def before_request3():697 evts.append(3)698 return "bye"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 699–702why, one step back699700 @app.route("/")701 def index():702 evts.append("index")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 703why, one step back703 return "damnit"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 704–706why, one step back704705 rv = client.get("/").data.strip()706 assert rv == b"hello"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 707why, one step back707 assert evts == [1, 2]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 708–709why, one step back708709Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 710why, one step back710def test_after_request_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 711–712why, one step back711 @app.route("/")712 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 713–714why, one step back713 @flask.after_this_request714 def foo(response):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 715why, one step back715 response.headers["X-Foo"] = "a header"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 716why, one step back716 return responseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 717–720why, one step back717718 return "Test"719720 resp = client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 721why, one step back721 assert resp.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 722–724why, one step back722 assert resp.headers["X-Foo"] == "a header"723724Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 725why, one step back725def test_teardown_request_handler(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 726–742why, one step back726 called = []727728 @app.teardown_request729 def teardown_request(exc):730 called.append(True)731 return "Ignored"732733 @app.route("/")734 def root():735 return "Response"736737 rv = client.get("/")738 assert rv.status_code == 200739 assert b"Response" in rv.data740 assert len(called) == 1741742Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 743why, one step back743def test_teardown_request_handler_debug_mode(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 744–760why, one step back744 called = []745746 @app.teardown_request747 def teardown_request(exc):748 called.append(True)749 return "Ignored"750751 @app.route("/")752 def root():753 return "Response"754755 rv = client.get("/")756 assert rv.status_code == 200757 assert b"Response" in rv.data758 assert len(called) == 1759760Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 761why, one step back761def test_teardown_request_handler_error(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 762–765why, one step back762 called = []763 app.testing = False764765 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 766why, one step back766 def teardown_request1(exc):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 767–773why, one step back767 assert type(exc) == ZeroDivisionError768 called.append(True)769 # This raises a new error and blows away sys.exc_info(), so we can770 # test that all teardown_requests get passed the same original771 # exception.772 try:773 raise TypeError()Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 774why, one step back774 except Exception:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 775–777why, one step back775 pass776777 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 778why, one step back778 def teardown_request2(exc):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 779–785why, one step back779 assert type(exc) == ZeroDivisionError780 called.append(True)781 # This raises a new error and blows away sys.exc_info(), so we can782 # test that all teardown_requests get passed the same original783 # exception.784 try:785 raise TypeError()Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 786why, one step back786 except Exception:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 787–789why, one step back787 pass788789 @app.route("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 790why, one step back790 def fails():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 791–795why, one step back791 1 // 0792793 rv = client.get("/")794 assert rv.status_code == 500795 assert b"Internal Server Error" in rv.dataMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 796why, one step back796 assert len(called) == 2Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 797–798why, one step back797798Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 799why, one step back799def test_before_after_request_order(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 800–802why, one step back800 called = []801802 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 803–804why, one step back803 def before1():804 called.append(1)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 805–806why, one step back805806 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 807–808why, one step back807 def before2():808 called.append(2)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 809–810why, one step back809810 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 811–812why, one step back811 def after1(response):812 called.append(4)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 813–815why, one step back813 return response814815 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 816–817why, one step back816 def after2(response):817 called.append(3)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 818–820why, one step back818 return response819820 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 821–822why, one step back821 def finish1(exc):822 called.append(6)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 823–824why, one step back823824 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 825–826why, one step back825 def finish2(exc):826 called.append(5)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 827–833why, one step back827828 @app.route("/")829 def index():830 return "42"831832 rv = client.get("/")833 assert rv.data == b"42"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 834why, one step back834 assert called == [1, 2, 3, 4, 5, 6]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 835–836why, one step back835836Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 837why, one step back837def test_error_handling(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 838–840why, one step back838 app.testing = False839840 @app.errorhandler(404)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 841why, one step back841 def not_found(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 842–847why, one step back842 return "not found", 404843844 @app.errorhandler(500)845 def internal_server_error(e):846 return "internal server error", 500847Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 848–849why, one step back848 @app.errorhandler(Forbidden)849 def forbidden(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 850–856why, one step back850 return "forbidden", 403851852 @app.route("/")853 def index():854 flask.abort(404)855856 @app.route("/error")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 857why, one step back857 def error():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 858–860why, one step back858 1 // 0859860 @app.route("/forbidden")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 861why, one step back861 def error2():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 862–870why, one step back862 flask.abort(403)863864 rv = client.get("/")865 assert rv.status_code == 404866 assert rv.data == b"not found"867 rv = client.get("/error")868 assert rv.status_code == 500869 assert b"internal server error" == rv.data870 rv = client.get("/forbidden")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 871why, one step back871 assert rv.status_code == 403Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 872–874why, one step back872 assert b"forbidden" == rv.data873874Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 875–876why, one step back875def test_error_handler_unknown_code(app):876 with pytest.raises(KeyError) as exc_info:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 877–881why, one step back877 app.register_error_handler(999, lambda e: ("999", 999))878879 assert "Use a subclass" in exc_info.value.args[0]880881Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 882why, one step back882def test_error_handling_processing(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 883–893why, one step back883 app.testing = False884885 @app.errorhandler(500)886 def internal_server_error(e):887 return "internal server error", 500888889 @app.route("/")890 def broken_func():891 1 // 0892893 @app.after_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 894why, one step back894 def after_request(resp):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 895why, one step back895 resp.mimetype = "text/x-special"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 896why, one step back896 return respMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 897–902why, one step back897898 resp = client.get("/")899 assert resp.mimetype == "text/x-special"900 assert resp.data == b"internal server error"901902Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 903why, one step back903def test_baseexception_error_handling(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 904–907why, one step back904 app.testing = False905906 @app.route("/")907 def broken_func():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 908why, one step back908 raise KeyboardInterrupt()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 909why, one step back909Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 910why, one step back910 with pytest.raises(KeyboardInterrupt):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 911–912why, one step back911 client.get("/")912Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 913–915why, one step back913 ctx = flask._request_ctx_stack.top914 assert ctx.preserved915 assert type(ctx._preserved_exc) is KeyboardInterruptMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 916–917why, one step back916917Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 918why, one step back918def test_before_request_and_routing_errors(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 919why, one step back919 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 920why, one step back920 def attach_something():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 921–923why, one step back921 flask.g.something = "value"922923 @app.errorhandler(404)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 924–925why, one step back924 def return_something(error):925 return flask.g.something, 404Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 926–931why, one step back926927 rv = client.get("/")928 assert rv.status_code == 404929 assert rv.data == b"value"930931Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 932–933why, one step back932def test_user_error_handling(app, client):933 class MyException(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 934–935why, one step back934 pass935Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 936–938why, one step back936 @app.errorhandler(MyException)937 def handle_my_exception(e):938 assert isinstance(e, MyException)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 939–942why, one step back939 return "42"940941 @app.route("/")942 def index():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 943why, one step back943 raise MyException()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 944–947why, one step back944945 assert client.get("/").data == b"42"946947Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 948–949why, one step back948def test_http_error_subclass_handling(app, client):949 class ForbiddenSubclass(Forbidden):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 950–951why, one step back950 pass951Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 952why, one step back952 @app.errorhandler(ForbiddenSubclass)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 953why, one step back953 def handle_forbidden_subclass(e):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 954why, one step back954 assert isinstance(e, ForbiddenSubclass)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 955–956why, one step back955 return "banana"956Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 957why, one step back957 @app.errorhandler(403)Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 958why, one step back958 def handle_403(e):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 959–960why, one step back959 assert not isinstance(e, ForbiddenSubclass)960 assert isinstance(e, Forbidden)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 961–963why, one step back961 return "apple"962963 @app.route("/1")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 964–965why, one step back964 def index1():965 raise ForbiddenSubclass()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 966–971why, one step back966967 @app.route("/2")968 def index2():969 flask.abort(403)970971 @app.route("/3")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 972–973why, one step back972 def index3():973 raise Forbidden()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 974–979why, one step back974975 assert client.get("/1").data == b"banana"976 assert client.get("/2").data == b"apple"977 assert client.get("/3").data == b"apple"978979Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 980–981why, one step back980def test_errorhandler_precedence(app, client):981 class E1(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 982–983why, one step back982 pass983Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 984why, one step back984 class E2(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 985–986why, one step back985 pass986Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 987why, one step back987 class E3(E1, E2):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 988–989why, one step back988 pass989Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 990–991why, one step back990 @app.errorhandler(E2)991 def handle_e2(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 992–993why, one step back992 return "E2"993Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 994–995why, one step back994 @app.errorhandler(Exception)995 def handle_exception(e):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 996–998why, one step back996 return "Exception"997998 @app.route("/E1")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 999–1000why, one step back999 def raise_e1():1000 raise E1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1001–1002why, one step back10011002 @app.route("/E3")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1003–1004why, one step back1003 def raise_e3():1004 raise E3Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1005–1012why, one step back10051006 rv = client.get("/E1")1007 assert rv.data == b"Exception"10081009 rv = client.get("/E3")1010 assert rv.data == b"E2"10111012Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1013why, one step back1013def test_trapping_of_bad_request_key_errors(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1014–1018why, one step back1014 @app.route("/key")1015 def fail():1016 flask.request.form["missing_key"]10171018 @app.route("/abort")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
lines 1019–1020why, one step back1019 def allow_abort():1020 flask.abort(400)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1021–1028why, one step back10211022 rv = client.get("/key")1023 assert rv.status_code == 4001024 assert b"missing_key" not in rv.data1025 rv = client.get("/abort")1026 assert rv.status_code == 40010271028 app.debug = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1029why, one step back1029 with pytest.raises(KeyError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1030why, one step back1030 client.get("/key")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1031why, one step back1031 assert e.errisinstance(BadRequest)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1032–1037why, one step back1032 assert "missing_key" in e.value.get_description()1033 rv = client.get("/abort")1034 assert rv.status_code == 40010351036 app.debug = False1037 app.config["TRAP_BAD_REQUEST_ERRORS"] = TrueMerge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 1038why, one step back1038 with pytest.raises(KeyError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1039why, one step back1039 client.get("/key")Merge branch '1.0-maintenance'David Lordbefore adoption1fa9185
line 1040why, one step back1040 with pytest.raises(BadRequest):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1041–1043why, one step back1041 client.get("/abort")10421043Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1044why, one step back1044def test_trapping_of_all_http_exceptions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1045–1050why, one step back1045 app.config["TRAP_HTTP_EXCEPTIONS"] = True10461047 @app.route("/fail")1048 def fail():1049 flask.abort(404)1050Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1051why, one step back1051 with pytest.raises(NotFound):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1052–1054why, one step back1052 client.get("/fail")10531054Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1055why, one step back1055def test_error_handler_after_processor_error(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1056–1059why, one step back1056 app.testing = False10571058 @app.before_request1059 def before_request():Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1060why, one step back1060 if _trigger == "before":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1061–1064why, one step back1061 1 // 010621063 @app.after_request1064 def after_request(response):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1065why, one step back1065 if _trigger == "after":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1066–1076why, one step back1066 1 // 01067 return response10681069 @app.route("/")1070 def index():1071 return "Foo"10721073 @app.errorhandler(500)1074 def internal_server_error(e):1075 return "Hello Server Error", 5001076Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1077why, one step back1077 for _trigger in "before", "after":Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1078why, one step back1078 rv = client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1079why, one step back1079 assert rv.status_code == 500Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1080–1082why, one step back1080 assert rv.data == b"Hello Server Error"10811082Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1083–1084why, one step back1083def test_enctype_debug_helper(app, client):1084 from flask.debughelpers import DebugFilesKeyErrorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1085–1091why, one step back10851086 app.debug = True10871088 @app.route("/fail", methods=["POST"])1089 def index():1090 return flask.request.files["foo"].filename1091Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1092–1094why, one step back1092 # with statement is important because we leave an exception on the1093 # stack otherwise and we want to ensure that this is not the case1094 # to not negatively affect other tests.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1095why, one step back1095 with client:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1096why, one step back1096 with pytest.raises(DebugFilesKeyError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1097–1098why, one step back1097 client.post("/fail", data={"foo": "index.txt"})1098 assert "no file contents were transmitted" in str(e.value)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1099why, one step back1099 assert 'This was submitted: "index.txt"' in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1100–1101why, one step back11001101Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1102why, one step back1102def test_response_types(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1103why, one step back1103 @app.route("/text")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1104why, one step back1104 def from_text():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1105–1107why, one step back1105 return u"Hällo Wörld"11061107 @app.route("/bytes")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1108why, one step back1108 def from_bytes():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1109–1111why, one step back1109 return u"Hällo Wörld".encode("utf-8")11101111 @app.route("/full_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1112why, one step back1112 def from_full_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1113–1119why, one step back1113 return (1114 "Meh",1115 400,1116 {"X-Foo": "Testing", "Content-Type": "text/plain; charset=utf-8"},1117 )11181119 @app.route("/text_headers")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1120why, one step back1120 def from_text_headers():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1121–1123why, one step back1121 return "Hello", {"X-Foo": "Test", "Content-Type": "text/plain; charset=utf-8"}11221123 @app.route("/text_status")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1124why, one step back1124 def from_text_status():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1125–1127why, one step back1125 return "Hi, status!", 40011261127 @app.route("/response_headers")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1128why, one step back1128 def from_response_headers():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1129–1134why, one step back1129 return (1130 flask.Response("Hello world", 404, {"X-Foo": "Baz"}),1131 {"X-Foo": "Bar", "X-Bar": "Foo"},1132 )11331134 @app.route("/response_status")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1135why, one step back1135 def from_response_status():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1136–1138why, one step back1136 return app.response_class("Hello world", 400), 50011371138 @app.route("/wsgi")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1139–1140why, one step back1139 def from_wsgi():1140 return NotFound()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1141why, one step back1141Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1142why, one step back1142 @app.route("/dict")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
lines 1143–1144why, one step back1143 def from_dict():1144 return {"foo": "bar"}, 201Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1145why, one step back1145Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1146–1147why, one step back1146 assert client.get("/text").data == u"Hällo Wörld".encode("utf-8")1147 assert client.get("/bytes").data == u"Hällo Wörld".encode("utf-8")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
line 1148why, one step back1148Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1149–1178why, one step back1149 rv = client.get("/full_tuple")1150 assert rv.data == b"Meh"1151 assert rv.headers["X-Foo"] == "Testing"1152 assert rv.status_code == 4001153 assert rv.mimetype == "text/plain"11541155 rv = client.get("/text_headers")1156 assert rv.data == b"Hello"1157 assert rv.headers["X-Foo"] == "Test"1158 assert rv.status_code == 2001159 assert rv.mimetype == "text/plain"11601161 rv = client.get("/text_status")1162 assert rv.data == b"Hi, status!"1163 assert rv.status_code == 4001164 assert rv.mimetype == "text/html"11651166 rv = client.get("/response_headers")1167 assert rv.data == b"Hello world"1168 assert rv.headers.getlist("X-Foo") == ["Baz", "Bar"]1169 assert rv.headers["X-Bar"] == "Foo"1170 assert rv.status_code == 40411711172 rv = client.get("/response_status")1173 assert rv.data == b"Hello world"1174 assert rv.status_code == 50011751176 rv = client.get("/wsgi")1177 assert b"Not Found" in rv.data1178 assert rv.status_code == 404Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
line 1179why, one step back1179Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1180why, one step back1180 rv = client.get("/dict")Merge pull request #3111 from pgjones/masterDavid Lordbefore adoption855d59b
lines 1181–1182why, one step back1181 assert rv.json == {"foo": "bar"}1182 assert rv.status_code == 201Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1183–1184why, one step back11831184Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1185why, one step back1185def test_response_type_errors():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1186–1189why, one step back1186 app = flask.Flask(__name__)1187 app.testing = True11881189 @app.route("/none")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1190why, one step back1190 def from_none():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1191–1193why, one step back1191 pass11921193 @app.route("/small_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1194why, one step back1194 def from_small_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1195–1197why, one step back1195 return ("Hello",)11961197 @app.route("/large_tuple")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1198why, one step back1198 def from_large_tuple():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1199–1201why, one step back1199 return "Hello", 234, {"X-Foo": "Bar"}, "???"12001201 @app.route("/bad_type")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1202–1203why, one step back1202 def from_bad_type():1203 return TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1204–1205why, one step back12041205 @app.route("/bad_wsgi")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1206–1207why, one step back1206 def from_bad_wsgi():1207 return lambda: NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1208–1212why, one step back12081209 c = app.test_client()12101211 with pytest.raises(TypeError) as e:1212 c.get("/none")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1213why, one step back1213 assert "returned None" in str(e.value)Merge pull request #3498 from raymond-devries/3445-traceback-for-noneDavid Lordbefore adoptiona3e4395
line 1214why, one step back1214 assert "from_none" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1215–1217why, one step back12151216 with pytest.raises(TypeError) as e:1217 c.get("/small_tuple")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1218why, one step back1218 assert "tuple must have the form" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1219–1223why, one step back12191220 pytest.raises(TypeError, c.get, "/large_tuple")12211222 with pytest.raises(TypeError) as e:1223 c.get("/bad_type")Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1224why, one step back1224 assert "it was a bool" in str(e.value)Merge pull request #3235 from johnzeringue/better-return-type-errorDavid Lordbefore adoption52f9aa7
line 1225why, one step back1225Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1226–1228why, one step back1226 pytest.raises(TypeError, c.get, "/bad_wsgi")12271228Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1229–1230why, one step back1229def test_make_response(app, req_ctx):1230 rv = flask.make_response()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1231–1245why, one step back1231 assert rv.status_code == 2001232 assert rv.data == b""1233 assert rv.mimetype == "text/html"12341235 rv = flask.make_response("Awesome")1236 assert rv.status_code == 2001237 assert rv.data == b"Awesome"1238 assert rv.mimetype == "text/html"12391240 rv = flask.make_response("W00t", 404)1241 assert rv.status_code == 4041242 assert rv.data == b"W00t"1243 assert rv.mimetype == "text/html"12441245Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1246why, one step back1246def test_make_response_with_response_instance(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1247–1248why, one step back1247 rv = flask.make_response(flask.jsonify({"msg": "W00t"}), 400)1248 assert rv.status_code == 400Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1249why, one step back1249 assert rv.data == b'{"msg":"W00t"}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1250–1266why, one step back1250 assert rv.mimetype == "application/json"12511252 rv = flask.make_response(flask.Response(""), 400)1253 assert rv.status_code == 4001254 assert rv.data == b""1255 assert rv.mimetype == "text/html"12561257 rv = flask.make_response(1258 flask.Response("", headers={"Content-Type": "text/html"}),1259 400,1260 [("X-Foo", "bar")],1261 )1262 assert rv.status_code == 4001263 assert rv.headers["Content-Type"] == "text/html"1264 assert rv.headers["X-Foo"] == "bar"12651266Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1267–1269why, one step back1267def test_jsonify_no_prettyprint(app, req_ctx):1268 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": False})1269 compressed_msg = b'{"msg":{"submsg":"W00t"},"msg2":"foobar"}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1270–1272why, one step back1270 uncompressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}12711272 rv = flask.make_response(flask.jsonify(uncompressed_msg), 200)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1273why, one step back1273 assert rv.data == compressed_msgMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1274–1275why, one step back12741275Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1276–1278why, one step back1276def test_jsonify_prettyprint(app, req_ctx):1277 app.config.update({"JSONIFY_PRETTYPRINT_REGULAR": True})1278 compressed_msg = {"msg": {"submsg": "W00t"}, "msg2": "foobar"}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1279why, one step back1279 pretty_response = (Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1280why, one step back1280 b'{\n "msg": {\n "submsg": "W00t"\n }, \n "msg2": "foobar"\n}\n'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1281–1283why, one step back1281 )12821283 rv = flask.make_response(flask.jsonify(compressed_msg), 200)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1284why, one step back1284 assert rv.data == pretty_responseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1285–1286why, one step back12851286Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1287why, one step back1287def test_jsonify_mimetype(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1288–1292why, one step back1288 app.config.update({"JSONIFY_MIMETYPE": "application/vnd.api+json"})1289 msg = {"msg": {"submsg": "W00t"}}1290 rv = flask.make_response(flask.jsonify(msg), 200)1291 assert rv.mimetype == "application/vnd.api+json"1292Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
lines 1293–1296why, one step back12931294@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")1295def test_json_dump_dataclass(app, req_ctx):1296 from dataclasses import make_dataclassMerge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1297why, one step back1297Merge pull request #3195 from eruvanos/json_support_dataclassDavid Lordbefore adoptionb0185a6
lines 1298–1301why, one step back1298 Data = make_dataclass("Data", [("name", str)])1299 value = flask.json.dumps(Data("Flask"), app=app)1300 value = flask.json.loads(value, app=app)1301 assert value == {"name": "Flask"}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1302why, one step back1302Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
line 1303why, one step back1303Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1304why, one step back1304def test_jsonify_args_and_kwargs_check(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1305–1309why, one step back1305 with pytest.raises(TypeError) as e:1306 flask.jsonify("fake args", kwargs="fake")1307 assert "behavior undefined" in str(e.value)13081309Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1310why, one step back1310def test_url_generation(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1311why, one step back1311 @app.route("/hello/<name>", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1312why, one step back1312 def hello():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1313–1321why, one step back1313 pass13141315 assert flask.url_for("hello", name="test x") == "/hello/test%20x"1316 assert (1317 flask.url_for("hello", name="test x", _external=True)1318 == "http://localhost/hello/test%20x"1319 )13201321Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1322–1323why, one step back1322def test_build_error_handler(app):1323 # Test base case, a URL which results in a BuildError.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1324–1326why, one step back1324 with app.test_request_context():1325 pytest.raises(BuildError, flask.url_for, "spam")1326Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1327why, one step back1327 # Verify the error is re-raised if not the current exception.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1328why, one step back1328 try:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1329why, one step back1329 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1330why, one step back1330 flask.url_for("spam")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1331–1332why, one step back1331 except BuildError as err:1332 error = errMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1333–1334why, one step back1333 try:1334 raise RuntimeError("Test case where BuildError is not current.")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1335why, one step back1335 except RuntimeError:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1336–1337why, one step back1336 pytest.raises(BuildError, app.handle_url_build_error, error, "spam", {})1337Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1338why, one step back1338 # Test a custom handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1339why, one step back1339 def handler(error, endpoint, values):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1340why, one step back1340 # Just a test.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1341–1342why, one step back1341 return "/test_handler/"1342Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1343why, one step back1343 app.url_build_error_handlers.append(handler)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1344–1347why, one step back1344 with app.test_request_context():1345 assert flask.url_for("spam") == "/test_handler/"13461347Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1348–1351why, one step back1348def test_build_error_handler_reraise(app):1349 # Test a custom handler which reraises the BuildError1350 def handler_raises_build_error(error, endpoint, values):1351 raise errorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1352why, one step back1352Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1353why, one step back1353 app.url_build_error_handlers.append(handler_raises_build_error)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1354–1358why, one step back13541355 with app.test_request_context():1356 pytest.raises(BuildError, flask.url_for, "not.existing")13571358Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1359–1360why, one step back1359def test_url_for_passes_special_values_to_build_error_handler(app):1360 @app.url_build_error_handlers.appendMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1361why, one step back1361 def handler(error, endpoint, values):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1362why, one step back1362 assert values == {Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1363–1373why, one step back1363 "_external": False,1364 "_anchor": None,1365 "_method": None,1366 "_scheme": None,1367 }1368 return "handled"13691370 with app.test_request_context():1371 flask.url_for("/")13721373Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1374why, one step back1374def test_static_files(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1375–1382why, one step back1375 rv = client.get("/static/index.html")1376 assert rv.status_code == 2001377 assert rv.data.strip() == b"<h1>Hello World!</h1>"1378 with app.test_request_context():1379 assert flask.url_for("static", filename="index.html") == "/static/index.html"1380 rv.close()13811382Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1383why, one step back1383def test_static_url_path():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1384–1393why, one step back1384 app = flask.Flask(__name__, static_url_path="/foo")1385 app.testing = True1386 rv = app.test_client().get("/foo/index.html")1387 assert rv.status_code == 2001388 rv.close()13891390 with app.test_request_context():1391 assert flask.url_for("static", filename="index.html") == "/foo/index.html"13921393Merge pull request #3182 from qil026/issue-3134-url-joinDavid Lordbefore adoptiondbd3840
lines 1394–1404why, one step back1394def test_static_url_path_with_ending_slash():1395 app = flask.Flask(__name__, static_url_path="/foo/")1396 app.testing = True1397 rv = app.test_client().get("/foo/index.html")1398 assert rv.status_code == 2001399 rv.close()14001401 with app.test_request_context():1402 assert flask.url_for("static", filename="index.html") == "/foo/index.html"14031404Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
line 1405why, one step back1405def test_static_url_empty_path(app):Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1406–1407why, one step back1406 app = flask.Flask(__name__, static_folder="", static_url_path="")1407 rv = app.test_client().open("/static/index.html", method="GET")Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
lines 1408–1412why, one step back1408 assert rv.status_code == 2001409 rv.close()141014111412def test_static_url_empty_path_default(app):Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1413–1414why, one step back1413 app = flask.Flask(__name__, static_folder="")1414 rv = app.test_client().open("/static/index.html", method="GET")Merge pull request #3124 from elbeardmorez/fix_static_url_pathDavid Lordbefore adoption754b729
lines 1415–1418why, one step back1415 assert rv.status_code == 2001416 rv.close()14171418Merge remote-tracking branch 'origin/1.1.x'David Lordbefore adoption64ba434
lines 1419–1429why, one step back1419def test_static_folder_with_ending_slash():1420 app = flask.Flask(__name__, static_folder="static/")14211422 @app.route("/<path:path>")1423 def catch_all(path):1424 return path14251426 rv = app.test_client().get("/catch/all")1427 assert rv.data == b"catch/all"14281429Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1430why, one step back1430def test_static_route_with_host_matching():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1431–1438why, one step back1431 app = flask.Flask(__name__, host_matching=True, static_host="example.com")1432 c = app.test_client()1433 rv = c.get("http://example.com/static/index.html")1434 assert rv.status_code == 2001435 rv.close()1436 with app.test_request_context():1437 rv = flask.url_for("static", filename="index.html", _external=True)1438 assert rv == "http://example.com/static/index.html"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1439why, one step back1439 # Providing static_host without host_matching=True should error.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1440–1441why, one step back1440 with pytest.raises(Exception):1441 flask.Flask(__name__, static_host="example.com")Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 1442–1443why, one step back1442 # Providing host_matching=True with static_folder1443 # but without static_host should error.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1444why, one step back1444 with pytest.raises(Exception):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1445why, one step back1445 flask.Flask(__name__, host_matching=True)Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
lines 1446–1447why, one step back1446 # Providing host_matching=True without static_host1447 # but with static_folder=None should not error.Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1448why, one step back1448 flask.Flask(__name__, host_matching=True, static_folder=None)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1449–1450why, one step back14491450Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1451why, one step back1451def test_request_locals():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1452why, one step back1452 assert repr(flask.g) == "<LocalProxy unbound>"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1453why, one step back1453 assert not flask.gMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1454–1455why, one step back14541455Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1456why, one step back1456def test_server_name_subdomain():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1457–1461why, one step back1457 app = flask.Flask(__name__, subdomain_matching=True)1458 client = app.test_client()14591460 @app.route("/")1461 def index():Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1462why, one step back1462 return "default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1463–1464why, one step back14631464 @app.route("/", subdomain="foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1465why, one step back1465 def subdomain():Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1466why, one step back1466 return "subdomain"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1467why, one step back1467Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1468why, one step back1468 app.config["SERVER_NAME"] = "dev.local:5000"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1469why, one step back1469 rv = client.get("/")Merge branch '1.0.x'David Lordbefore adoption29111a3
line 1470why, one step back1470 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1471why, one step back1471Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1472–1473why, one step back1472 rv = client.get("/", "http://dev.local:5000")1473 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1474why, one step back1474Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1475–1476why, one step back1475 rv = client.get("/", "https://dev.local:5000")1476 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1477why, one step back1477Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1478–1479why, one step back1478 app.config["SERVER_NAME"] = "dev.local:443"1479 rv = client.get("/", "https://dev.local")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1480why, one step back1480Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1481–1483why, one step back1481 # Werkzeug 1.0 fixes matching https scheme with 443 port1482 if rv.status_code != 404:1483 assert rv.data == b"default"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1484why, one step back1484Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1485–1490why, one step back1485 app.config["SERVER_NAME"] = "dev.local"1486 rv = client.get("/", "https://dev.local")1487 assert rv.data == b"default"14881489 # suppress Werkzeug 1.0 warning about name mismatch1490 with pytest.warns(None):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1491–1493why, one step back1491 rv = client.get("/", "http://foo.localhost")1492 assert rv.status_code == 4041493Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1494–1495why, one step back1494 rv = client.get("/", "http://foo.dev.local")1495 assert rv.data == b"subdomain"Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1496–1497why, one step back14961497Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1498–1499why, one step back1498def test_exception_propagation(app, client):1499 def apprunner(config_key):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1500–1503why, one step back1500 @app.route("/")1501 def index():1502 1 // 01503Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1504–1506why, one step back1504 if config_key is not None:1505 app.config[config_key] = True1506 with pytest.raises(Exception):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1507–1510why, one step back1507 client.get("/")1508 else:1509 assert client.get("/").status_code == 5001510Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1511–1514why, one step back1511 # we have to run this test in an isolated thread because if the1512 # debug flag is set to true and an exception happens the context is1513 # not torn down. This causes other tests that run after this fail1514 # when they expect no exception on the stack.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1515why, one step back1515 for config_key in "TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1516–1518why, one step back1516 t = Thread(target=apprunner, args=(config_key,))1517 t.start()1518 t.join()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1519–1535why, one step back151915201521@pytest.mark.parametrize("debug", [True, False])1522@pytest.mark.parametrize("use_debugger", [True, False])1523@pytest.mark.parametrize("use_reloader", [True, False])1524@pytest.mark.parametrize("propagate_exceptions", [None, True, False])1525def test_werkzeug_passthrough_errors(1526 monkeypatch, debug, use_debugger, use_reloader, propagate_exceptions, app1527):1528 rv = {}15291530 # Mocks werkzeug.serving.run_simple method1531 def run_simple_mock(*args, **kwargs):1532 rv["passthrough_errors"] = kwargs.get("passthrough_errors")15331534 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1535 app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptionsMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1536why, one step back1536 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1537–1538why, one step back15371538Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1539why, one step back1539def test_max_content_length(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1540–1542why, one step back1540 app.config["MAX_CONTENT_LENGTH"] = 6415411542 @app.before_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1543why, one step back1543 def always_first():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1544why, one step back1544 flask.request.form["myfile"]Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1545why, one step back1545 AssertionError()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1546–1547why, one step back15461547 @app.route("/accept", methods=["POST"])Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1548why, one step back1548 def accept_file():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1549why, one step back1549 flask.request.form["myfile"]Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1550why, one step back1550 AssertionError()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1551why, one step back1551Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1552–1553why, one step back1552 @app.errorhandler(413)1553 def catcher(error):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1554–1559why, one step back1554 return "42"15551556 rv = client.post("/accept", data={"myfile": "foo" * 100})1557 assert rv.data == b"42"15581559Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1560–1562why, one step back1560def test_url_processors(app, client):1561 @app.url_defaults1562 def add_language_code(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1563–1567why, one step back1563 if flask.g.lang_code is not None and app.url_map.is_endpoint_expecting(1564 endpoint, "lang_code"1565 ):1566 values.setdefault("lang_code", flask.g.lang_code)1567Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1568–1569why, one step back1568 @app.url_value_preprocessor1569 def pull_lang_code(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1570–1576why, one step back1570 flask.g.lang_code = values.pop("lang_code", None)15711572 @app.route("/<lang_code>/")1573 def index():1574 return flask.url_for("about")15751576 @app.route("/<lang_code>/about")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1577why, one step back1577 def about():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1578–1580why, one step back1578 return flask.url_for("something_else")15791580 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1581why, one step back1581 def something_else():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1582–1588why, one step back1582 return flask.url_for("about", lang_code="en")15831584 assert client.get("/de/").data == b"/de/about"1585 assert client.get("/de/about").data == b"/foo"1586 assert client.get("/foo").data == b"/en/about"15871588Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1589why, one step back1589def test_inject_blueprint_url_defaults(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1590–1591why, one step back1590 bp = flask.Blueprint("foo.bar.baz", __name__, template_folder="template")1591Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1592–1593why, one step back1592 @bp.url_defaults1593 def bp_defaults(endpoint, values):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1594–1596why, one step back1594 values["page"] = "login"15951596 @bp.route("/<page>")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1597why, one step back1597 def view(page):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1598–1599why, one step back1598 pass1599Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1600why, one step back1600 app.register_blueprint(bp)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1601why, one step back1601Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1602why, one step back1602 values = dict()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1603–1604why, one step back1603 app.inject_url_defaults("foo.bar.baz.view", values)1604 expected = dict(page="login")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1605why, one step back1605 assert values == expectedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1606–1609why, one step back16061607 with app.test_request_context("/somepage"):1608 url = flask.url_for("foo.bar.baz.view")1609 expected = "/login"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1610why, one step back1610 assert url == expectedMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1611–1612why, one step back16111612Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1613why, one step back1613def test_nonascii_pathinfo(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1614–1621why, one step back1614 @app.route(u"/киртест")1615 def index():1616 return "Hello World!"16171618 rv = client.get(u"/киртест")1619 assert rv.data == b"Hello World!"16201621Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1622why, one step back1622def test_debug_mode_complains_after_first_request(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1623–1628why, one step back1623 app.debug = True16241625 @app.route("/")1626 def index():1627 return "Awesome"1628Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1629why, one step back1629 assert not app.got_first_requestMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1630why, one step back1630 assert client.get("/").data == b"Awesome"Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1631why, one step back1631 with pytest.raises(AssertionError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1632–1633why, one step back16321633 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1634why, one step back1634 def broken():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1635–1636why, one step back1635 return "Meh"1636Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1637why, one step back1637 assert "A setup function was called" in str(e.value)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1638–1641why, one step back16381639 app.debug = False16401641 @app.route("/foo")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1642why, one step back1642 def working():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1643–1648why, one step back1643 return "Meh"16441645 assert client.get("/foo").data == b"Meh"1646 assert app.got_first_request16471648Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1649why, one step back1649def test_before_first_request_functions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1650–1662why, one step back1650 got = []16511652 @app.before_first_request1653 def foo():1654 got.append(42)16551656 client.get("/")1657 assert got == [42]1658 client.get("/")1659 assert got == [42]1660 assert app.got_first_request16611662Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1663why, one step back1663def test_before_first_request_functions_concurrent(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1664–1667why, one step back1664 got = []16651666 @app.before_first_request1667 def foo():Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1668why, one step back1668 time.sleep(0.2)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1669–1670why, one step back1669 got.append(42)1670Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1671why, one step back1671 def get_and_assert():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1672why, one step back1672 client.get("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1673why, one step back1673 assert got == [42]Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1674why, one step back1674Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1675–1678why, one step back1675 t = Thread(target=get_and_assert)1676 t.start()1677 get_and_assert()1678 t.join()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1679–1681why, one step back1679 assert app.got_first_request16801681Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1682why, one step back1682def test_routing_redirect_debugging(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1683–1689why, one step back1683 app.debug = True16841685 @app.route("/foo/", methods=["GET", "POST"])1686 def foo():1687 return "success"16881689 with client:Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1690why, one step back1690 with pytest.raises(AssertionError) as e:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1691why, one step back1691 client.post("/foo", data={})Merge branch '1.0.x'David Lordbefore adoptionb05a685
line 1692why, one step back1692 assert "http://localhost/foo/" in str(e.value)Merge pull request #3453 from noviluni/remove_redundant_parenthesesDavid Lordbefore adoption986871b
line 1693why, one step back1693 assert "Make sure to directly send your POST-request to this URL" in str(Merge branch '1.0.x'David Lordbefore adoptionb05a685
lines 1694–1695why, one step back1694 e.value1695 )Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1696–1705why, one step back16961697 rv = client.get("/foo", data={}, follow_redirects=True)1698 assert rv.data == b"success"16991700 app.debug = False1701 with client:1702 rv = client.post("/foo", data={}, follow_redirects=True)1703 assert rv.data == b"success"17041705Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1706why, one step back1706def test_route_decorator_custom_endpoint(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1707–1713why, one step back1707 app.debug = True17081709 @app.route("/foo/")1710 def foo():1711 return flask.request.endpoint17121713 @app.route("/bar/", endpoint="bar")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1714why, one step back1714 def for_bar():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1715–1717why, one step back1715 return flask.request.endpoint17161717 @app.route("/bar/123", endpoint="123")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1718why, one step back1718 def for_bar_foo():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1719–1730why, one step back1719 return flask.request.endpoint17201721 with app.test_request_context():1722 assert flask.url_for("foo") == "/foo/"1723 assert flask.url_for("bar") == "/bar/"1724 assert flask.url_for("123") == "/bar/123"17251726 assert client.get("/foo/").data == b"foo"1727 assert client.get("/bar/").data == b"bar"1728 assert client.get("/bar/123").data == b"123"17291730Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1731why, one step back1731def test_preserve_only_once(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1732–1737why, one step back1732 app.debug = True17331734 @app.route("/fail")1735 def fail_func():1736 1 // 01737Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 1738why, one step back1738 for _x in range(3):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1739why, one step back1739 with pytest.raises(ZeroDivisionError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1740–1741why, one step back1740 client.get("/fail")1741Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1742–1747why, one step back1742 assert flask._request_ctx_stack.top is not None1743 assert flask._app_ctx_stack.top is not None1744 # implicit appctx disappears too1745 flask._request_ctx_stack.top.pop()1746 assert flask._request_ctx_stack.top is None1747 assert flask._app_ctx_stack.top is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1748–1749why, one step back17481749Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1750why, one step back1750def test_preserve_remembers_exception(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1751why, one step back1751 app.debug = TrueMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1752why, one step back1752 errors = []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1753–1758why, one step back17531754 @app.route("/fail")1755 def fail_func():1756 1 // 017571758 @app.route("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1759why, one step back1759 def success_func():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1760–1762why, one step back1760 return "Okay"17611762 @app.teardown_requestMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1763–1764why, one step back1763 def teardown_handler(exc):1764 errors.append(exc)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
lines 1766–1767why, one step back1766 # After this failure we did not yet call the teardown handler1767 with pytest.raises(ZeroDivisionError):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1768why, one step back1768 client.get("/fail")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1769why, one step back1769 assert errors == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1770why, one step back1770Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1771why, one step back1771 # But this request triggers it, and it's an errorMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1772why, one step back1772 client.get("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1773–1774why, one step back1773 assert len(errors) == 21774 assert isinstance(errors[0], ZeroDivisionError)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1775why, one step back1775Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1776why, one step back1776 # At this point another request does nothing.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1777why, one step back1777 client.get("/success")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1778–1779why, one step back1778 assert len(errors) == 31779 assert errors[1] is NoneMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1780–1781why, one step back17801781Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1782why, one step back1782def test_get_method_on_g(app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1783–1784why, one step back1783 assert flask.g.get("x") is None1784 assert flask.g.get("x", 11) == 11Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1785why, one step back1785 flask.g.x = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1786why, one step back1786 assert flask.g.get("x") == 42Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1787why, one step back1787 assert flask.g.x == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1788–1789why, one step back17881789Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1790–1792why, one step back1790def test_g_iteration_protocol(app_ctx):1791 flask.g.foo = 231792 flask.g.bar = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1793–1797why, one step back1793 assert "foo" in flask.g1794 assert "foos" not in flask.g1795 assert sorted(flask.g) == ["bar", "foo"]17961797Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1798why, one step back1798def test_subdomain_basic_support():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1799–1803why, one step back1799 app = flask.Flask(__name__, subdomain_matching=True)1800 app.config["SERVER_NAME"] = "localhost.localdomain"1801 client = app.test_client()18021803 @app.route("/")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1804why, one step back1804 def normal_index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1805–1807why, one step back1805 return "normal index"18061807 @app.route("/", subdomain="test")Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1808why, one step back1808 def test_index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1809–1817why, one step back1809 return "test index"18101811 rv = client.get("/", "http://localhost.localdomain/")1812 assert rv.data == b"normal index"18131814 rv = client.get("/", "http://test.localhost.localdomain/")1815 assert rv.data == b"test index"18161817Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1818why, one step back1818def test_subdomain_matching():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1819–1830why, one step back1819 app = flask.Flask(__name__, subdomain_matching=True)1820 client = app.test_client()1821 app.config["SERVER_NAME"] = "localhost.localdomain"18221823 @app.route("/", subdomain="<user>")1824 def index(user):1825 return "index for %s" % user18261827 rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")1828 assert rv.data == b"index for mitsuhiko"18291830Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1831why, one step back1831def test_subdomain_matching_with_ports():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1832–1844why, one step back1832 app = flask.Flask(__name__, subdomain_matching=True)1833 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1834 client = app.test_client()18351836 @app.route("/", subdomain="<user>")1837 def index(user):1838 return "index for %s" % user18391840 rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")1841 assert rv.data == b"index for mitsuhiko"184218431844@pytest.mark.parametrize("matching", (False, True))Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1845–1846why, one step back1845def test_subdomain_matching_other_name(matching):1846 app = flask.Flask(__name__, subdomain_matching=matching)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1847–1853why, one step back1847 app.config["SERVER_NAME"] = "localhost.localdomain:3000"1848 client = app.test_client()18491850 @app.route("/")1851 def index():1852 return "", 2041853Merge branch '1.0.x'David Lordbefore adoption29111a3
lines 1854–1858why, one step back1854 # suppress Werkzeug 0.15 warning about name mismatch1855 with pytest.warns(None):1856 # ip address can't match name1857 rv = client.get("/", "http://127.0.0.1:3000/")1858 assert rv.status_code == 404 if matching else 204Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1859why, one step back1859Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1860why, one step back1860 # allow all subdomains if matching is disabledMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1861–1864why, one step back1861 rv = client.get("/", "http://www.localhost.localdomain:3000/")1862 assert rv.status_code == 404 if matching else 20418631864Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1865why, one step back1865def test_multi_route_rules(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1866–1868why, one step back1866 @app.route("/")1867 @app.route("/<test>/")1868 def index(test="a"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1869why, one step back1869 return testMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1870–1876why, one step back18701871 rv = client.open("/")1872 assert rv.data == b"a"1873 rv = client.open("/b/")1874 assert rv.data == b"b"18751876Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1877–1879why, one step back1877def test_multi_route_class_views(app, client):1878 class View(object):1879 def __init__(self, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1880–1883why, one step back1880 app.add_url_rule("/", "index", self.index)1881 app.add_url_rule("/<test>/", "index", self.index)18821883 def index(self, test="a"):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1884why, one step back1884 return testMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1885why, one step back1885Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1886why, one step back1886 _ = View(app)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1887–1892why, one step back1887 rv = client.open("/")1888 assert rv.data == b"a"1889 rv = client.open("/b/")1890 assert rv.data == b"b"18911892Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1893why, one step back1893def test_run_defaults(monkeypatch, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1894–1900why, one step back1894 rv = {}18951896 # Mocks werkzeug.serving.run_simple method1897 def run_simple_mock(*args, **kwargs):1898 rv["result"] = "running..."18991900 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1901why, one step back1901 app.run()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1902–1904why, one step back1902 assert rv["result"] == "running..."19031904Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1905why, one step back1905def test_run_server_port(monkeypatch, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1906–1908why, one step back1906 rv = {}19071908 # Mocks werkzeug.serving.run_simple methodMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1909why, one step back1909 def run_simple_mock(hostname, port, application, *args, **kwargs):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1910–1913why, one step back1910 rv["result"] = "running on %s:%s ..." % (hostname, port)19111912 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1913 hostname, port = "localhost", 8000Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1914why, one step back1914 app.run(hostname, port, debug=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1915–1918why, one step back1915 assert rv["result"] == "running on %s:%s ..." % (hostname, port)191619171918@pytest.mark.parametrize(Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
line 1919why, one step back1919 "host,port,server_name,expect_host,expect_port",Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1920why, one step back1920 (Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
lines 1921–1927why, one step back1921 (None, None, "pocoo.org:8080", "pocoo.org", 8080),1922 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1923 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1924 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1925 ("localhost", 0, "localhost:8080", "localhost", 0),1926 (None, None, "localhost:8080", "localhost", 8080),1927 (None, None, "localhost:0", "localhost", 0),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1928–1929why, one step back1928 ),1929)Merge pull request #3229 from lordmauve/style-fixDavid Lordbefore adoption240e398
lines 1930–1932why, one step back1930def test_run_from_config(1931 monkeypatch, host, port, server_name, expect_host, expect_port, app1932):Merge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
lines 1933–1935why, one step back1933 def run_simple_mock(hostname, port, *args, **kwargs):1934 assert hostname == expect_host1935 assert port == expect_portMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1936–1937why, one step back19361937 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2928 from vorelq/2926-default-port-overrides-zeroDavid Lordbefore adoptiond9fa28b
line 1938why, one step back1938 app.config["SERVER_NAME"] = server_nameMerge pull request #2685 from davidism/app-context-docsDavid Lordbefore adoption16d83d6
line 1939why, one step back1939 app.run(host, port)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1940–1941why, one step back19401941Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1942why, one step back1942def test_max_cookie_size(app, client, recwarn):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1943–1944why, one step back1943 app.config["MAX_COOKIE_SIZE"] = 1001944Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1945–1947why, one step back1945 # outside app context, default to Werkzeug static value,1946 # which is also the default config1947 response = flask.Response()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1948why, one step back1948 default = flask.Flask.default_config["MAX_COOKIE_SIZE"]Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1949why, one step back1949 assert response.max_cookie_size == defaultMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1950why, one step back1950Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1951–1953why, one step back1951 # inside app context, use app config1952 with app.app_context():1953 assert flask.Response().max_cookie_size == 100Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1954–1958why, one step back19541955 @app.route("/")1956 def index():1957 r = flask.Response("", status=204)1958 r.set_cookie("foo", "bar" * 100)Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1959why, one step back1959 return rMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1960–1961why, one step back19601961 client.get("/")Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
lines 1962–1963why, one step back1962 assert len(recwarn) == 11963 w = recwarn.pop()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1964–1968why, one step back1964 assert "cookie is too large" in str(w.message)19651966 app.config["MAX_COOKIE_SIZE"] = 019671968 client.get("/")Merge pull request #2693 from davidism/max-cookie-sizeDavid Lordbefore adoptiond8bf589
line 1969why, one step back1969 assert len(recwarn) == 0