test_testing.py
This file
Path
tests/test_testing.py
386 lines · 10.0 KiB · Python
Last changed by
Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
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–17why, one step back12import pytest1314import flask15import werkzeug1617from flask._compat import text_typeMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 18why, one step back18from flask.cli import ScriptInfoMerge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
line 19why, one step back19from flask.json import jsonifyMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 20why, one step back20from flask.testing import make_test_environ_builder, FlaskCliRunnerMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 21–23why, one step back212223def test_environ_defaults_from_config(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 24–25why, one step back24 app.config["SERVER_NAME"] = "example.com:1234"25 app.config["APPLICATION_ROOT"] = "/foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 26why, one step back26Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 27why, one step back27 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 28–31why, one step back28 def index():29 return flask.request.url3031 ctx = app.test_request_context()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 32why, one step back32 assert ctx.request.url == "http://example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 33why, one step back33Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 34–35why, one step back34 rv = client.get("/")35 assert rv.data == b"http://example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 36–38why, one step back363738def test_environ_defaults(app, client, app_ctx, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 39why, one step back39 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 40–43why, one step back40 def index():41 return flask.request.url4243 ctx = app.test_request_context()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 44why, one step back44 assert ctx.request.url == "http://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 45why, one step back45 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 46–47why, one step back46 rv = client.get("/")47 assert rv.data == b"http://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 48–50why, one step back484950def test_environ_base_default(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 51why, one step back51 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 52–55why, one step back52 def index():53 flask.g.user_agent = flask.request.headers["User-Agent"]54 return flask.request.remote_addr55Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 56–58why, one step back56 rv = client.get("/")57 assert rv.data == b"127.0.0.1"58 assert flask.g.user_agent == "werkzeug/" + werkzeug.__version__Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 59–61why, one step back596061def test_environ_base_modified(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 62why, one step back62 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 63–66why, one step back63 def index():64 flask.g.user_agent = flask.request.headers["User-Agent"]65 return flask.request.remote_addr66Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 67–71why, one step back67 client.environ_base["REMOTE_ADDR"] = "0.0.0.0"68 client.environ_base["HTTP_USER_AGENT"] = "Foo"69 rv = client.get("/")70 assert rv.data == b"0.0.0.0"71 assert flask.g.user_agent == "Foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 72why, one step back72Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 73–77why, one step back73 client.environ_base["REMOTE_ADDR"] = "0.0.0.1"74 client.environ_base["HTTP_USER_AGENT"] = "Bar"75 rv = client.get("/")76 assert rv.data == b"0.0.0.1"77 assert flask.g.user_agent == "Bar"support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 78–80why, one step back787980def test_client_open_environ(app, client, request):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 81why, one step back81 @app.route("/index")support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 82–84why, one step back82 def index():83 return flask.request.remote_addr84Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 85why, one step back85 builder = make_test_environ_builder(app, path="/index", method="GET")support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 86–88why, one step back86 request.addfinalizer(builder.close)8788 rv = client.open(builder)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 89why, one step back89 assert rv.data == b"127.0.0.1"support passing environ to test client (#2412)David Lordbefore adoption59f7966
lines 90–91why, one step back9091 environ = builder.get_environ()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 92why, one step back92 client.environ_base["REMOTE_ADDR"] = "127.0.0.2"support passing environ to test client (#2412)David Lordbefore adoption59f7966
line 93why, one step back93 rv = client.open(environ)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 94why, one step back94 assert rv.data == b"127.0.0.2"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 95–97why, one step back959697def test_specify_url_scheme(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 98why, one step back98 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 99–101why, one step back99 def index():100 return flask.request.url101Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 102–103why, one step back102 ctx = app.test_request_context(url_scheme="https")103 assert ctx.request.url == "https://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 104why, one step back104Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 105–106why, one step back105 rv = client.get("/", url_scheme="https")106 assert rv.data == b"https://localhost/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 107–108why, one step back107108Merge pull request #2430 from erebus1/env_url_scheme_fixDavid Lordbefore adoption85fa8aa
line 109why, one step back109def test_path_is_url(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 110–114why, one step back110 eb = make_test_environ_builder(app, "https://example.com/")111 assert eb.url_scheme == "https"112 assert eb.host == "example.com"113 assert eb.script_root == ""114 assert eb.path == "/"Merge pull request #2430 from erebus1/env_url_scheme_fixDavid Lordbefore adoption85fa8aa
lines 115–116why, one step back115116Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 117–118why, one step back117def test_blueprint_with_subdomain():118 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 119–120why, one step back119 app.config["SERVER_NAME"] = "example.com:1234"120 app.config["APPLICATION_ROOT"] = "/foo"Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
line 121why, one step back121 client = app.test_client()Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 122why, one step back122Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 123why, one step back123 bp = flask.Blueprint("company", __name__, subdomain="xxx")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 124why, one step back124Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 125why, one step back125 @bp.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 126–130why, one step back126 def index():127 return flask.request.url128129 app.register_blueprint(bp)130Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 131–132why, one step back131 ctx = app.test_request_context("/", subdomain="xxx")132 assert ctx.request.url == "http://xxx.example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 133–134why, one step back133 assert ctx.request.blueprint == bp.name134Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 135–136why, one step back135 rv = client.get("/", subdomain="xxx")136 assert rv.data == b"http://xxx.example.com:1234/foo/"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 137–139why, one step back137138139def test_redirect_keep_session(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 140why, one step back140 @app.route("/", methods=["GET", "POST"])Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 141why, one step back141 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 142–145why, one step back142 if flask.request.method == "POST":143 return flask.redirect("/getsession")144 flask.session["data"] = "foo"145 return "index"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 146why, one step back146Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 147why, one step back147 @app.route("/getsession")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 148why, one step back148 def get_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 149why, one step back149 return flask.session.get("data", "<missing>")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 150–151why, one step back150151 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 152–153why, one step back152 rv = client.get("/getsession")153 assert rv.data == b"<missing>"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 154why, one step back154Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 155–159why, one step back155 rv = client.get("/")156 assert rv.data == b"index"157 assert flask.session.get("data") == "foo"158 rv = client.post("/", data={}, follow_redirects=True)159 assert rv.data == b"foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 160–161why, one step back160161 # This support requires a new Werkzeug versionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 162–163why, one step back162 if not hasattr(client, "redirect_client"):163 assert flask.session.get("data") == "foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 164why, one step back164Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 165–166why, one step back165 rv = client.get("/getsession")166 assert rv.data == b"foo"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 167–169why, one step back167168169def test_session_transactions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 170why, one step back170 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 171why, one step back171 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 172why, one step back172 return text_type(flask.session["foo"])Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 173–176why, one step back173174 with client:175 with client.session_transaction() as sess:176 assert len(sess) == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 177why, one step back177 sess["foo"] = [42]Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 178why, one step back178 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 179–180why, one step back179 rv = client.get("/")180 assert rv.data == b"[42]"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 181–182why, one step back181 with client.session_transaction() as sess:182 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 183why, one step back183 assert sess["foo"] == [42]Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 184–193why, one step back184185186def test_session_transactions_no_null_sessions():187 app = flask.Flask(__name__)188 app.testing = True189190 with app.test_client() as c:191 with pytest.raises(RuntimeError) as e:192 with c.session_transaction() as sess:193 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 194why, one step back194 assert "Session backend did not open a session" in str(e.value)Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 195–197why, one step back195196197def test_session_transactions_keep_context(app, client, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 198why, one step back198 rv = client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 199–209why, one step back199 req = flask.request._get_current_object()200 assert req is not None201 with client.session_transaction():202 assert req is flask.request._get_current_object()203204205def test_session_transaction_needs_cookies(app):206 c = app.test_client(use_cookies=False)207 with pytest.raises(RuntimeError) as e:208 with c.session_transaction() as s:209 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 210why, one step back210 assert "cookies" in str(e.value)Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 211–215why, one step back211212213def test_test_client_context_binding(app, client):214 app.testing = False215Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 216why, one step back216 @app.route("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 217–218why, one step back217 def index():218 flask.g.value = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 219why, one step back219 return "Hello World!"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 220why, one step back220Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 221why, one step back221 @app.route("/other")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 222–225why, one step back222 def other():223 1 // 0224225 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 226why, one step back226 resp = client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 227why, one step back227 assert flask.g.value == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 228why, one step back228 assert resp.data == b"Hello World!"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 229–230why, one step back229 assert resp.status_code == 200230Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 231–233why, one step back231 resp = client.get("/other")232 assert not hasattr(flask.g, "value")233 assert b"Internal Server Error" in resp.dataMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 234–241why, one step back234 assert resp.status_code == 500235 flask.g.value = 23236237 try:238 flask.g.value239 except (AttributeError, RuntimeError):240 pass241 else:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 242why, one step back242 raise AssertionError("some kind of exception expected")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 243–248why, one step back243244245def test_reuse_client(client):246 c = client247248 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 249why, one step back249 assert client.get("/").status_code == 404Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 250–251why, one step back250251 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 252why, one step back252 assert client.get("/").status_code == 404Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 253–263why, one step back253254255def test_test_client_calls_teardown_handlers(app, client):256 called = []257258 @app.teardown_request259 def remember(error):260 called.append(error)261262 with client:263 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 264why, one step back264 client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 265–270why, one step back265 assert called == []266 assert called == [None]267268 del called[:]269 with client:270 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 271why, one step back271 client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 272why, one step back272 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 273why, one step back273 client.get("/")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 274–278why, one step back274 assert called == [None]275 assert called == [None, None]276277278def test_full_url_request(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 279why, one step back279 @app.route("/action", methods=["POST"])Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 280why, one step back280 def action():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 281why, one step back281 return "x"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 282–283why, one step back282283 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 284why, one step back284 rv = client.post("http://domain.com/action?vodka=42", data={"gin": 43})Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 285why, one step back285 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 286–287why, one step back286 assert "gin" in flask.request.form287 assert "vodka" in flask.request.argsMerge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
lines 288–290why, one step back288289290def test_json_request_and_response(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 291why, one step back291 @app.route("/echo", methods=["POST"])Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
lines 292–295why, one step back292 def echo():293 return jsonify(flask.request.get_json())294295 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 296–297why, one step back296 json_data = {"drink": {"gin": 1, "tonic": True}, "price": 10}297 rv = client.post("/echo", json=json_data)Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8
lines 298–306why, one step back298299 # Request should be in JSON300 assert flask.request.is_json301 assert flask.request.get_json() == json_data302303 # Response should be in JSON304 assert rv.status_code == 200305 assert rv.is_json306 assert rv.get_json() == json_dataMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 307–308why, one step back307308Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 309–310why, one step back309def test_subdomain():310 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 311why, one step back311 app.config["SERVER_NAME"] = "example.com"Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
line 312why, one step back312 client = app.test_client()Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 313why, one step back313Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 314why, one step back314 @app.route("/", subdomain="<company_id>")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 315–318why, one step back315 def view(company_id):316 return company_id317318 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 319why, one step back319 url = flask.url_for("view", company_id="xxx")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 320–324why, one step back320321 with client:322 response = client.get(url)323324 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 325why, one step back325 assert b"xxx" == response.dataMerge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 326–328why, one step back326327328def test_nosubdomain(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 329why, one step back329 app.config["SERVER_NAME"] = "example.com"Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
line 330why, one step back330Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 331why, one step back331 @app.route("/<company_id>")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 332–335why, one step back332 def view(company_id):333 return company_id334335 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 336why, one step back336 url = flask.url_for("view", company_id="xxx")Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96
lines 337–341why, one step back337338 with client:339 response = client.get(url)340341 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 342why, one step back342 assert b"xxx" == response.dataMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 343–357why, one step back343344345def test_cli_runner_class(app):346 runner = app.test_cli_runner()347 assert isinstance(runner, FlaskCliRunner)348349 class SubRunner(FlaskCliRunner):350 pass351352 app.test_cli_runner_class = SubRunner353 runner = app.test_cli_runner()354 assert isinstance(runner, SubRunner)355356357def test_cli_invoke(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 358why, one step back358 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 359why, one step back359 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 360why, one step back360 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 361–363why, one step back361362 runner = app.test_cli_runner()363 # invoke with command nameMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 364–365why, one step back364 result = runner.invoke(args=["hello"])365 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 366–367why, one step back366 # invoke with command object367 result = runner.invoke(hello_command)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 368why, one step back368 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 369–378why, one step back369370371def test_cli_custom_obj(app):372 class NS(object):373 called = False374375 def create_app():376 NS.called = True377 return app378Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 379why, one step back379 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 380why, one step back380 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 381why, one step back381 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 382–386why, one step back382383 script_info = ScriptInfo(create_app=create_app)384 runner = app.test_cli_runner()385 runner.invoke(hello_command, obj=script_info)386 assert NS.called