test_testing.py
This file
Path
tests/test_testing.py
413 lines · 10.6 KiB · Python
Last changed by
Merge branch '1.0.x'David Lordbefore adoption05a4e15
History of this fileTake it
The walk stopped after 200 commits: lines older than 49f3e96 point at it.
Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 tests.testing4 ~~~~~~~~~~~~~56 Test client and more.7Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c
line 8why, one step back8 :copyright: © 2010 by the Pallets team.Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 9–10why, one step back9 :license: BSD, see LICENSE for more details.10"""Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 11why, one step back11import clickMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 12–16why, one step back12import pytest1314import flask15import werkzeug16Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 17why, one step back17from flask import appcontext_poppedMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 18why, one step back18from flask._compat import text_typeMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 19why, one step back19from flask.cli import ScriptInfoMerge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
line 20why, one step back20from flask.json import jsonifyMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 21why, one step back21from flask.testing import make_test_environ_builder, FlaskCliRunnerMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 22why, one step back22Merge branch '1.0.x'David Lordbefore adoption05a4e15
lines 23–26why, one step back23try:24 import blinker25except ImportError:26 blinker = NoneMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 27why, one step back27Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 28why, one step back28Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 29why, one step back29def test_environ_defaults_from_config(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 30–31why, one step back30 app.config["SERVER_NAME"] = "example.com:1234"31 app.config["APPLICATION_ROOT"] = "/foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 32why, one step back32Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 33why, one step back33 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 34–37why, one step back34 def index():35 return flask.request.url3637 ctx = app.test_request_context()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 38why, one step back38 assert ctx.request.url == "http://example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 39why, one step back39Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 40–41why, one step back40 rv = client.get("/")41 assert rv.data == b"http://example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 42–44why, one step back424344def test_environ_defaults(app, client, app_ctx, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 45why, one step back45 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 46–49why, one step back46 def index():47 return flask.request.url4849 ctx = app.test_request_context()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 50why, one step back50 assert ctx.request.url == "http://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 51why, one step back51 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 52–53why, one step back52 rv = client.get("/")53 assert rv.data == b"http://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 54–56why, one step back545556def test_environ_base_default(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 57why, one step back57 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
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–64why, one step back62 rv = client.get("/")63 assert rv.data == b"127.0.0.1"64 assert flask.g.user_agent == "werkzeug/" + werkzeug.__version__Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 65–67why, one step back656667def test_environ_base_modified(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 68why, one step back68 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 69–72why, one step back69 def index():70 flask.g.user_agent = flask.request.headers["User-Agent"]71 return flask.request.remote_addr72Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 73–77why, one step back73 client.environ_base["REMOTE_ADDR"] = "0.0.0.0"74 client.environ_base["HTTP_USER_AGENT"] = "Foo"75 rv = client.get("/")76 assert rv.data == b"0.0.0.0"77 assert flask.g.user_agent == "Foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 78why, one step back78Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 79–83why, one step back79 client.environ_base["REMOTE_ADDR"] = "0.0.0.1"80 client.environ_base["HTTP_USER_AGENT"] = "Bar"81 rv = client.get("/")82 assert rv.data == b"0.0.0.1"83 assert flask.g.user_agent == "Bar"support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 84–86why, one step back848586def test_client_open_environ(app, client, request):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 87why, one step back87 @app.route("/index")support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 88–90why, one step back88 def index():89 return flask.request.remote_addr90Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 91why, one step back91 builder = make_test_environ_builder(app, path="/index", method="GET")support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 92–94why, one step back92 request.addfinalizer(builder.close)9394 rv = client.open(builder)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 95why, one step back95 assert rv.data == b"127.0.0.1"support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 96–97why, one step back9697 environ = builder.get_environ()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 98why, one step back98 client.environ_base["REMOTE_ADDR"] = "127.0.0.2"support passing environ to test client (#2412)David Lordbefore adoption59f7966
line 99why, one step back99 rv = client.open(environ)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 100why, one step back100 assert rv.data == b"127.0.0.2"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 101–103why, one step back101102103def test_specify_url_scheme(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 104why, one step back104 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 105–107why, one step back105 def index():106 return flask.request.url107Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 108–109why, one step back108 ctx = app.test_request_context(url_scheme="https")109 assert ctx.request.url == "https://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 110why, one step back110Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 111–112why, one step back111 rv = client.get("/", url_scheme="https")112 assert rv.data == b"https://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 113–114why, one step back113114Merge pull request #2430 from erebus1/env_url_scheme_fixDavid Lordbefore adoption85fa8aa
line 115why, one step back115def test_path_is_url(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 116–120why, one step back116 eb = make_test_environ_builder(app, "https://example.com/")117 assert eb.url_scheme == "https"118 assert eb.host == "example.com"119 assert eb.script_root == ""120 assert eb.path == "/"Merge pull request #2430 from erebus1/env_url_scheme_fixDavid Lordbefore adoption85fa8aa
lines 121–122why, one step back121122Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 123–124why, one step back123def test_blueprint_with_subdomain():124 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 125–126why, one step back125 app.config["SERVER_NAME"] = "example.com:1234"126 app.config["APPLICATION_ROOT"] = "/foo"Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
line 127why, one step back127 client = app.test_client()Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 128why, one step back128Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 129why, one step back129 bp = flask.Blueprint("company", __name__, subdomain="xxx")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 130why, one step back130Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 131why, one step back131 @bp.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 132–136why, one step back132 def index():133 return flask.request.url134135 app.register_blueprint(bp)136Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 137–138why, one step back137 ctx = app.test_request_context("/", subdomain="xxx")138 assert ctx.request.url == "http://xxx.example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 139–140why, one step back139 assert ctx.request.blueprint == bp.name140Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 141–142why, one step back141 rv = client.get("/", subdomain="xxx")142 assert rv.data == b"http://xxx.example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 143–145why, one step back143144145def test_redirect_keep_session(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 146why, one step back146 @app.route("/", methods=["GET", "POST"])Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 147why, one step back147 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 148–151why, one step back148 if flask.request.method == "POST":149 return flask.redirect("/getsession")150 flask.session["data"] = "foo"151 return "index"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 152why, one step back152Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 153why, one step back153 @app.route("/getsession")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 154why, one step back154 def get_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 155why, one step back155 return flask.session.get("data", "<missing>")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 156–157why, one step back156157 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 158–159why, one step back158 rv = client.get("/getsession")159 assert rv.data == b"<missing>"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 160why, one step back160Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 161–165why, one step back161 rv = client.get("/")162 assert rv.data == b"index"163 assert flask.session.get("data") == "foo"164 rv = client.post("/", data={}, follow_redirects=True)165 assert rv.data == b"foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 166–167why, one step back166167 # This support requires a new Werkzeug versionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 168–169why, one step back168 if not hasattr(client, "redirect_client"):169 assert flask.session.get("data") == "foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 170why, one step back170Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 171–172why, one step back171 rv = client.get("/getsession")172 assert rv.data == b"foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 173–175why, one step back173174175def test_session_transactions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 176why, one step back176 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 177why, one step back177 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 178why, one step back178 return text_type(flask.session["foo"])Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 179–182why, one step back179180 with client:181 with client.session_transaction() as sess:182 assert len(sess) == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 183why, one step back183 sess["foo"] = [42]Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 184why, one step back184 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 185–186why, one step back185 rv = client.get("/")186 assert rv.data == b"[42]"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 187–188why, one step back187 with client.session_transaction() as sess:188 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 189why, one step back189 assert sess["foo"] == [42]Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 190–199why, one step back190191192def test_session_transactions_no_null_sessions():193 app = flask.Flask(__name__)194 app.testing = True195196 with app.test_client() as c:197 with pytest.raises(RuntimeError) as e:198 with c.session_transaction() as sess:199 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 200why, one step back200 assert "Session backend did not open a session" in str(e.value)Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 201–203why, one step back201202203def test_session_transactions_keep_context(app, client, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 204why, one step back204 rv = client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 205–215why, one step back205 req = flask.request._get_current_object()206 assert req is not None207 with client.session_transaction():208 assert req is flask.request._get_current_object()209210211def test_session_transaction_needs_cookies(app):212 c = app.test_client(use_cookies=False)213 with pytest.raises(RuntimeError) as e:214 with c.session_transaction() as s:215 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 216why, one step back216 assert "cookies" in str(e.value)Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 217–221why, one step back217218219def test_test_client_context_binding(app, client):220 app.testing = False221Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 222why, one step back222 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 223–224why, one step back223 def index():224 flask.g.value = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 225why, one step back225 return "Hello World!"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 226why, one step back226Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 227why, one step back227 @app.route("/other")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 228–231why, one step back228 def other():229 1 // 0230231 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 232why, one step back232 resp = client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 233why, one step back233 assert flask.g.value == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 234why, one step back234 assert resp.data == b"Hello World!"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 235–236why, one step back235 assert resp.status_code == 200236Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 237–239why, one step back237 resp = client.get("/other")238 assert not hasattr(flask.g, "value")239 assert b"Internal Server Error" in resp.dataMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 240–247why, one step back240 assert resp.status_code == 500241 flask.g.value = 23242243 try:244 flask.g.value245 except (AttributeError, RuntimeError):246 pass247 else:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 248why, one step back248 raise AssertionError("some kind of exception expected")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 249–254why, one step back249250251def test_reuse_client(client):252 c = client253254 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 255why, one step back255 assert client.get("/").status_code == 404Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 256–257why, one step back256257 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 258why, one step back258 assert client.get("/").status_code == 404Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 259–269why, one step back259260261def test_test_client_calls_teardown_handlers(app, client):262 called = []263264 @app.teardown_request265 def remember(error):266 called.append(error)267268 with client:269 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 270why, one step back270 client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 271–276why, one step back271 assert called == []272 assert called == [None]273274 del called[:]275 with client:276 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 277why, one step back277 client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 278why, one step back278 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 279why, one step back279 client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 280–284why, one step back280 assert called == [None]281 assert called == [None, None]282283284def test_full_url_request(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 285why, one step back285 @app.route("/action", methods=["POST"])Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 286why, one step back286 def action():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 287why, one step back287 return "x"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 288–289why, one step back288289 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 290why, one step back290 rv = client.post("http://domain.com/action?vodka=42", data={"gin": 43})Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 291why, one step back291 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 292–293why, one step back292 assert "gin" in flask.request.form293 assert "vodka" in flask.request.argsMerge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
lines 294–296why, one step back294295296def test_json_request_and_response(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 297why, one step back297 @app.route("/echo", methods=["POST"])Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
lines 298–301why, one step back298 def echo():299 return jsonify(flask.request.get_json())300301 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 302–303why, one step back302 json_data = {"drink": {"gin": 1, "tonic": True}, "price": 10}303 rv = client.post("/echo", json=json_data)Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
lines 304–312why, one step back304305 # Request should be in JSON306 assert flask.request.is_json307 assert flask.request.get_json() == json_data308309 # Response should be in JSON310 assert rv.status_code == 200311 assert rv.is_json312 assert rv.get_json() == json_dataMerge branch '1.0.x'David Lordbefore adoption05a4e15
lines 313–333why, one step back313314315@pytest.mark.skipif(blinker is None, reason="blinker is not installed")316def test_client_json_no_app_context(app, client):317 @app.route("/hello", methods=["POST"])318 def hello():319 return "Hello, {}!".format(flask.request.json["name"])320321 class Namespace(object):322 count = 0323324 def add(self, app):325 self.count += 1326327 ns = Namespace()328329 with appcontext_popped.connected_to(ns.add, app):330 rv = client.post("/hello", json={"name": "Flask"})331332 assert rv.get_data(as_text=True) == "Hello, Flask!"333 assert ns.count == 1Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 334–335why, one step back334335Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 336–337why, one step back336def test_subdomain():337 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 338why, one step back338 app.config["SERVER_NAME"] = "example.com"Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
line 339why, one step back339 client = app.test_client()Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 340why, one step back340Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 341why, one step back341 @app.route("/", subdomain="<company_id>")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 342–345why, one step back342 def view(company_id):343 return company_id344345 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 346why, one step back346 url = flask.url_for("view", company_id="xxx")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 347–351why, one step back347348 with client:349 response = client.get(url)350351 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 352why, one step back352 assert b"xxx" == response.dataMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 353–355why, one step back353354355def test_nosubdomain(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 356why, one step back356 app.config["SERVER_NAME"] = "example.com"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 357why, one step back357Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 358why, one step back358 @app.route("/<company_id>")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 359–362why, one step back359 def view(company_id):360 return company_id361362 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 363why, one step back363 url = flask.url_for("view", company_id="xxx")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 364–368why, one step back364365 with client:366 response = client.get(url)367368 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 369why, one step back369 assert b"xxx" == response.dataMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 370–384why, one step back370371372def test_cli_runner_class(app):373 runner = app.test_cli_runner()374 assert isinstance(runner, FlaskCliRunner)375376 class SubRunner(FlaskCliRunner):377 pass378379 app.test_cli_runner_class = SubRunner380 runner = app.test_cli_runner()381 assert isinstance(runner, SubRunner)382383384def test_cli_invoke(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 385why, one step back385 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 386why, one step back386 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 387why, one step back387 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 388–390why, one step back388389 runner = app.test_cli_runner()390 # invoke with command nameMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 391–392why, one step back391 result = runner.invoke(args=["hello"])392 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 393–394why, one step back393 # invoke with command object394 result = runner.invoke(hello_command)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 395why, one step back395 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 396–405why, one step back396397398def test_cli_custom_obj(app):399 class NS(object):400 called = False401402 def create_app():403 NS.called = True404 return app405Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 406why, one step back406 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 407why, one step back407 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 408why, one step back408 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 409–413why, one step back409410 script_info = ScriptInfo(create_app=create_app)411 runner = app.test_cli_runner()412 runner.invoke(hello_command, obj=script_info)413 assert NS.called