test_testing.py
This file
Path
tests/test_testing.py
424 lines · 11.0 KiB · Python
Last changed by
remove unused module docstringsDavid Lordbefore adoptionf2f027d
History of this fileTake it
The walk stopped after 200 commits: lines older than e102e5c point at it.
Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 1–4why, one step back1import click2import pytest3import werkzeug4Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
line 5why, one step back5import flaskMerge branch '1.0.x'David Lordbefore adoption05a4e15
line 6why, one step back6from flask import appcontext_poppedMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 7–8why, one step back7from flask.cli import ScriptInfo8from flask.json import jsonifyMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 9–10why, one step back9from flask.testing import EnvironBuilder10from flask.testing import FlaskCliRunnerMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 11why, one step back11Merge branch '1.0.x'David Lordbefore adoption05a4e15
lines 12–15why, one step back12try:13 import blinker14except ImportError:15 blinker = NoneMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 16why, one step back16Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 17why, one step back17Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 18why, one step back18def test_environ_defaults_from_config(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 19–20why, one step back19 app.config["SERVER_NAME"] = "example.com:1234"20 app.config["APPLICATION_ROOT"] = "/foo"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 21why, one step back21Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 22why, one step back22 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 23–26why, one step back23 def index():24 return flask.request.url2526 ctx = app.test_request_context()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 27why, one step back27 assert ctx.request.url == "http://example.com:1234/foo/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 28why, one step back28Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 29–30why, one step back29 rv = client.get("/")30 assert rv.data == b"http://example.com:1234/foo/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 31–33why, one step back313233def test_environ_defaults(app, client, app_ctx, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 34why, one step back34 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 35–38why, one step back35 def index():36 return flask.request.url3738 ctx = app.test_request_context()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 39why, one step back39 assert ctx.request.url == "http://localhost/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 40why, one step back40 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 41–42why, one step back41 rv = client.get("/")42 assert rv.data == b"http://localhost/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 43–45why, one step back434445def test_environ_base_default(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 46why, one step back46 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 47–50why, one step back47 def index():48 flask.g.user_agent = flask.request.headers["User-Agent"]49 return flask.request.remote_addr50Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 51–52why, one step back51 rv = client.get("/")52 assert rv.data == b"127.0.0.1"Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 53why, one step back53 assert flask.g.user_agent == f"werkzeug/{werkzeug.__version__}"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 54–56why, one step back545556def test_environ_base_modified(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 57why, one step back57 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 58–61why, one step back58 def index():59 flask.g.user_agent = flask.request.headers["User-Agent"]60 return flask.request.remote_addr61Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 62–66why, one step back62 client.environ_base["REMOTE_ADDR"] = "0.0.0.0"63 client.environ_base["HTTP_USER_AGENT"] = "Foo"64 rv = client.get("/")65 assert rv.data == b"0.0.0.0"66 assert flask.g.user_agent == "Foo"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 67why, one step back67Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 68–72why, one step back68 client.environ_base["REMOTE_ADDR"] = "0.0.0.1"69 client.environ_base["HTTP_USER_AGENT"] = "Bar"70 rv = client.get("/")71 assert rv.data == b"0.0.0.1"72 assert flask.g.user_agent == "Bar"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 73–75why, one step back737475def test_client_open_environ(app, client, request):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 76why, one step back76 @app.route("/index")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 77–79why, one step back77 def index():78 return flask.request.remote_addr79Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 80why, one step back80 builder = EnvironBuilder(app, path="/index", method="GET")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 81–83why, one step back81 request.addfinalizer(builder.close)8283 rv = client.open(builder)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 84why, one step back84 assert rv.data == b"127.0.0.1"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 85–86why, one step back8586 environ = builder.get_environ()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 87why, one step back87 client.environ_base["REMOTE_ADDR"] = "127.0.0.2"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 88why, one step back88 rv = client.open(environ)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 89why, one step back89 assert rv.data == b"127.0.0.2"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 90–92why, one step back909192def test_specify_url_scheme(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 93why, one step back93 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 94–96why, one step back94 def index():95 return flask.request.url96Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 97–98why, one step back97 ctx = app.test_request_context(url_scheme="https")98 assert ctx.request.url == "https://localhost/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 99why, one step back99Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 100–101why, one step back100 rv = client.get("/", url_scheme="https")101 assert rv.data == b"https://localhost/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 102–104why, one step back102103104def test_path_is_url(app):Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 105why, one step back105 eb = EnvironBuilder(app, "https://example.com/")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 106–109why, one step back106 assert eb.url_scheme == "https"107 assert eb.host == "example.com"108 assert eb.script_root == ""109 assert eb.path == "/"Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
lines 110–114why, one step back110111112def test_environbuilder_json_dumps(app):113 """EnvironBuilder.json_dumps() takes settings from the app."""114 app.config["JSON_AS_ASCII"] = FalseMerge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
lines 115–116why, one step back115 eb = EnvironBuilder(app, json="\u20ac")116 assert eb.input_stream.read().decode("utf8") == '"\u20ac"'Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 117–120why, one step back117118119def test_blueprint_with_subdomain():120 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 121–122why, one step back121 app.config["SERVER_NAME"] = "example.com:1234"122 app.config["APPLICATION_ROOT"] = "/foo"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 123–124why, one step back123 client = app.test_client()124Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 125why, one step back125 bp = flask.Blueprint("company", __name__, subdomain="xxx")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 126why, one step back126Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 127why, one step back127 @bp.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 128–132why, one step back128 def index():129 return flask.request.url130131 app.register_blueprint(bp)132Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 133–134why, one step back133 ctx = app.test_request_context("/", subdomain="xxx")134 assert ctx.request.url == "http://xxx.example.com:1234/foo/"Merge pull request #3104 from eladm26/adding_models_converterDavid Lordbefore adoption2fa30f6
lines 135–137why, one step back135136 with ctx:137 assert ctx.request.blueprint == bp.nameMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 138why, one step back138Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 139–140why, one step back139 rv = client.get("/", subdomain="xxx")140 assert rv.data == b"http://xxx.example.com:1234/foo/"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 141–143why, one step back141142143def test_redirect_keep_session(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 144why, one step back144 @app.route("/", methods=["GET", "POST"])Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 145why, one step back145 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 146–149why, one step back146 if flask.request.method == "POST":147 return flask.redirect("/getsession")148 flask.session["data"] = "foo"149 return "index"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 150why, one step back150Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 151why, one step back151 @app.route("/getsession")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 152why, one step back152 def get_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 153why, one step back153 return flask.session.get("data", "<missing>")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 154–155why, one step back154155 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 156–157why, one step back156 rv = client.get("/getsession")157 assert rv.data == b"<missing>"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 158why, one step back158Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 159–161why, one step back159 rv = client.get("/")160 assert rv.data == b"index"161 assert flask.session.get("data") == "foo"Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 162why, one step back162Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 163–164why, one step back163 rv = client.post("/", data={}, follow_redirects=True)164 assert rv.data == b"foo"Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 165why, one step back165 assert flask.session.get("data") == "foo"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 166why, one step back166Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 167–168why, one step back167 rv = client.get("/getsession")168 assert rv.data == b"foo"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 169–171why, one step back169170171def test_session_transactions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 172why, one step back172 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 173why, one step back173 def index():Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 174why, one step back174 return str(flask.session["foo"])Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 175–178why, one step back175176 with client:177 with client.session_transaction() as sess:178 assert len(sess) == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 179why, one step back179 sess["foo"] = [42]Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 180why, one step back180 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 181–182why, one step back181 rv = client.get("/")182 assert rv.data == b"[42]"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 183–184why, one step back183 with client.session_transaction() as sess:184 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 185why, one step back185 assert sess["foo"] == [42]Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 186–193why, one step back186187188def test_session_transactions_no_null_sessions():189 app = flask.Flask(__name__)190 app.testing = True191192 with app.test_client() as c:193 with pytest.raises(RuntimeError) as e:Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 194why, one step back194 with c.session_transaction():Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 195why, one step back195 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 196why, one step back196 assert "Session backend did not open a session" in str(e.value)Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 197–199why, one step back197198199def test_session_transactions_keep_context(app, client, req_ctx):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 200why, one step back200 client.get("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 201–209why, one step back201 req = flask.request._get_current_object()202 assert req is not None203 with client.session_transaction():204 assert req is flask.request._get_current_object()205206207def test_session_transaction_needs_cookies(app):208 c = app.test_client(use_cookies=False)209 with pytest.raises(RuntimeError) as e:Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 210why, one step back210 with c.session_transaction():Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 211why, one step back211 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 212why, one step back212 assert "cookies" in str(e.value)Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 213–217why, one step back213214215def test_test_client_context_binding(app, client):216 app.testing = False217Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 218why, one step back218 @app.route("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 219–220why, one step back219 def index():220 flask.g.value = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 221why, one step back221 return "Hello World!"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 222why, one step back222Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 223why, one step back223 @app.route("/other")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 224–227why, one step back224 def other():225 1 // 0226227 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 228why, one step back228 resp = client.get("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 229why, one step back229 assert flask.g.value == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 230why, one step back230 assert resp.data == b"Hello World!"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 231–232why, one step back231 assert resp.status_code == 200232Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 233–235why, one step back233 resp = client.get("/other")234 assert not hasattr(flask.g, "value")235 assert b"Internal Server Error" in resp.dataMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 236–243why, one step back236 assert resp.status_code == 500237 flask.g.value = 23238239 try:240 flask.g.value241 except (AttributeError, RuntimeError):242 pass243 else:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 244why, one step back244 raise AssertionError("some kind of exception expected")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 245–250why, one step back245246247def test_reuse_client(client):248 c = client249250 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 251why, one step back251 assert client.get("/").status_code == 404Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 252–253why, one step back252253 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 254why, one step back254 assert client.get("/").status_code == 404Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 255–265why, one step back255256257def test_test_client_calls_teardown_handlers(app, client):258 called = []259260 @app.teardown_request261 def remember(error):262 called.append(error)263264 with client:265 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 266why, one step back266 client.get("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 267–272why, one step back267 assert called == []268 assert called == [None]269270 del called[:]271 with client:272 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 273why, one step back273 client.get("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 274why, one step back274 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 275why, one step back275 client.get("/")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 276–280why, one step back276 assert called == [None]277 assert called == [None, None]278279280def test_full_url_request(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 281why, one step back281 @app.route("/action", methods=["POST"])Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 282why, one step back282 def action():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 283why, one step back283 return "x"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 284–285why, one step back284285 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 286why, one step back286 rv = client.post("http://domain.com/action?vodka=42", data={"gin": 43})Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 287why, one step back287 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 288–289why, one step back288 assert "gin" in flask.request.form289 assert "vodka" in flask.request.argsMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 290–292why, one step back290291292def test_json_request_and_response(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 293why, one step back293 @app.route("/echo", methods=["POST"])Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 294–297why, one step back294 def echo():295 return jsonify(flask.request.get_json())296297 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 298–299why, one step back298 json_data = {"drink": {"gin": 1, "tonic": True}, "price": 10}299 rv = client.post("/echo", json=json_data)Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 300–308why, one step back300301 # Request should be in JSON302 assert flask.request.is_json303 assert flask.request.get_json() == json_data304305 # Response should be in JSON306 assert rv.status_code == 200307 assert rv.is_json308 assert rv.get_json() == json_dataMerge branch '1.0.x'David Lordbefore adoption05a4e15
lines 309–314why, one step back309310311@pytest.mark.skipif(blinker is None, reason="blinker is not installed")312def test_client_json_no_app_context(app, client):313 @app.route("/hello", methods=["POST"])314 def hello():Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 315why, one step back315 return f"Hello, {flask.request.json['name']}!"Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 316why, one step back316Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 317why, one step back317 class Namespace:Merge branch '1.0.x'David Lordbefore adoption05a4e15
lines 318–329why, one step back318 count = 0319320 def add(self, app):321 self.count += 1322323 ns = Namespace()324325 with appcontext_popped.connected_to(ns.add, app):326 rv = client.post("/hello", json={"name": "Flask"})327328 assert rv.get_data(as_text=True) == "Hello, Flask!"329 assert ns.count == 1Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 330–333why, one step back330331332def test_subdomain():333 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 334why, one step back334 app.config["SERVER_NAME"] = "example.com"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 335–336why, one step back335 client = app.test_client()336Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 337why, one step back337 @app.route("/", subdomain="<company_id>")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 338–341why, one step back338 def view(company_id):339 return company_id340341 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 342why, one step back342 url = flask.url_for("view", company_id="xxx")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 343–347why, one step back343344 with client:345 response = client.get(url)346347 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 348why, one step back348 assert b"xxx" == response.dataMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 349–351why, one step back349350351def test_nosubdomain(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 352why, one step back352 app.config["SERVER_NAME"] = "example.com"Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 353why, one step back353Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 354why, one step back354 @app.route("/<company_id>")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 355–358why, one step back355 def view(company_id):356 return company_id357358 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 359why, one step back359 url = flask.url_for("view", company_id="xxx")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 360–364why, one step back360361 with client:362 response = client.get(url)363364 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 365why, one step back365 assert b"xxx" == response.dataMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 366–380why, one step back366367368def test_cli_runner_class(app):369 runner = app.test_cli_runner()370 assert isinstance(runner, FlaskCliRunner)371372 class SubRunner(FlaskCliRunner):373 pass374375 app.test_cli_runner_class = SubRunner376 runner = app.test_cli_runner()377 assert isinstance(runner, SubRunner)378379380def test_cli_invoke(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 381why, one step back381 @app.cli.command("hello")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 382why, one step back382 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 383why, one step back383 click.echo("Hello, World!")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 384–386why, one step back384385 runner = app.test_cli_runner()386 # invoke with command nameMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 387–388why, one step back387 result = runner.invoke(args=["hello"])388 assert "Hello" in result.outputMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 389–390why, one step back389 # invoke with command object390 result = runner.invoke(hello_command)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 391why, one step back391 assert "Hello" in result.outputMerge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 392–394why, one step back392393394def test_cli_custom_obj(app):Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 395why, one step back395 class NS:Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 396–401why, one step back396 called = False397398 def create_app():399 NS.called = True400 return app401Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 402why, one step back402 @app.cli.command("hello")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
line 403why, one step back403 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 404why, one step back404 click.echo("Hello, World!")Merge pull request #2707 from rochacbruno/lazy_loader_messageDavid Lordbefore adoptione102e5c
lines 405–409why, one step back405406 script_info = ScriptInfo(create_app=create_app)407 runner = app.test_cli_runner()408 runner.invoke(hello_command, obj=script_info)409 assert NS.calledMerge pull request #3157 from fantix/fix-test-client-teardownDavid Lordbefore adoption2c68f86
lines 410–424why, one step back410411412def test_client_pop_all_preserved(app, req_ctx, client):413 @app.route("/")414 def index():415 # stream_with_context pushes a third context, preserved by client416 return flask.Response(flask.stream_with_context("hello"))417418 # req_ctx fixture pushed an initial context, not marked preserved419 with client:420 # request pushes a second request context, preserved by client421 client.get("/")422423 # only req_ctx fixture should still be pushed424 assert flask._request_ctx_stack.top is req_ctx