Skip to content
Myr

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 file

Take 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 back
1# -*- coding: utf-8 -*-
2"""3 tests.testing4 ~~~~~~~~~~~~~56 Test client and more.7

Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c

line 8why, one step back
8 :copyright: © 2010 by the Pallets team.

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 9–10why, one step back
9 :license: BSD, see LICENSE for more details.
10"""

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

line 11why, one step back
11import click

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 12–17why, one step back
12import pytest
1314import flask15import werkzeug1617from flask._compat import text_type

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

line 18why, one step back
18from flask.cli import ScriptInfo

Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8

line 19why, one step back
19from flask.json import jsonify

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

line 20why, one step back
20from flask.testing import make_test_environ_builder, FlaskCliRunner

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 21–23why, one step back
21
2223def test_environ_defaults_from_config(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 24–25why, one step back
24 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 back
26

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 27why, one step back
27 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 28–31why, one step back
28 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 back
32 assert ctx.request.url == "http://example.com:1234/foo/"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 33why, one step back
33

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 34–35why, one step back
34 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 back
36
3738def test_environ_defaults(app, client, app_ctx, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 39why, one step back
39 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 40–43why, one step back
40 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 back
44 assert ctx.request.url == "http://localhost/"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 45why, one step back
45 with client:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 46–47why, one step back
46 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 back
48
4950def test_environ_base_default(app, client, app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 51why, one step back
51 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 52–55why, one step back
52 def index():
53 flask.g.user_agent = flask.request.headers["User-Agent"]54 return flask.request.remote_addr55

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 56–58why, one step back
56 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 back
59
6061def test_environ_base_modified(app, client, app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 62why, one step back
62 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 63–66why, one step back
63 def index():
64 flask.g.user_agent = flask.request.headers["User-Agent"]65 return flask.request.remote_addr66

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 67–71why, one step back
67 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 back
72

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 73–77why, one step back
73 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 back
78
7980def test_client_open_environ(app, client, request):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 81why, one step back
81 @app.route("/index")

support passing environ to test client (#2412)David Lordbefore adoption59f7966

lines 82–84why, one step back
82 def index():
83 return flask.request.remote_addr84

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 85why, one step back
85 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 back
86 request.addfinalizer(builder.close)
8788 rv = client.open(builder)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 89why, one step back
89 assert rv.data == b"127.0.0.1"

support passing environ to test client (#2412)David Lordbefore adoption59f7966

lines 90–91why, one step back
90
91 environ = builder.get_environ()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 92why, one step back
92 client.environ_base["REMOTE_ADDR"] = "127.0.0.2"

support passing environ to test client (#2412)David Lordbefore adoption59f7966

line 93why, one step back
93 rv = client.open(environ)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 94why, one step back
94 assert rv.data == b"127.0.0.2"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 95–97why, one step back
95
9697def test_specify_url_scheme(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 98why, one step back
98 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 99–101why, one step back
99 def index():
100 return flask.request.url101

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 102–103why, one step back
102 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 back
104

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 105–106why, one step back
105 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 back
107
108

Merge pull request #2430 from erebus1/env_url_scheme_fixDavid Lordbefore adoption85fa8aa

line 109why, one step back
109def test_path_is_url(app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 110–114why, one step back
110 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 back
115
116

Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20

lines 117–118why, one step back
117def 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 back
119 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 back
121 client = app.test_client()

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 122why, one step back
122

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 123why, one step back
123 bp = flask.Blueprint("company", __name__, subdomain="xxx")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 124why, one step back
124

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 125why, one step back
125 @bp.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 126–130why, one step back
126 def index():
127 return flask.request.url128129 app.register_blueprint(bp)130

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 131–132why, one step back
131 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 back
133 assert ctx.request.blueprint == bp.name
134

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 135–136why, one step back
135 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 back
137
138139def test_redirect_keep_session(app, client, app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 140why, one step back
140 @app.route("/", methods=["GET", "POST"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 141why, one step back
141 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 142–145why, one step back
142 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 back
146

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 147why, one step back
147 @app.route("/getsession")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 148why, one step back
148 def get_session():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 149why, one step back
149 return flask.session.get("data", "<missing>")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 150–151why, one step back
150
151 with client:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 152–153why, one step back
152 rv = client.get("/getsession")
153 assert rv.data == b"<missing>"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 154why, one step back
154

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 155–159why, one step back
155 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 back
160
161 # This support requires a new Werkzeug version

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 162–163why, one step back
162 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 back
164

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 165–166why, one step back
165 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 back
167
168169def test_session_transactions(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 170why, one step back
170 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 171why, one step back
171 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 172why, one step back
172 return text_type(flask.session["foo"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 173–176why, one step back
173
174 with client:175 with client.session_transaction() as sess:176 assert len(sess) == 0

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 177why, one step back
177 sess["foo"] = [42]

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 178why, one step back
178 assert len(sess) == 1

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 179–180why, one step back
179 rv = client.get("/")
180 assert rv.data == b"[42]"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 181–182why, one step back
181 with client.session_transaction() as sess:
182 assert len(sess) == 1

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 183why, one step back
183 assert sess["foo"] == [42]

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 184–193why, one step back
184
185186def 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 pass

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 194why, one step back
194 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 back
195
196197def test_session_transactions_keep_context(app, client, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 198why, one step back
198 rv = client.get("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 199–209why, one step back
199 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 pass

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 210why, one step back
210 assert "cookies" in str(e.value)

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 211–215why, one step back
211
212213def test_test_client_context_binding(app, client):214 app.testing = False215

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 216why, one step back
216 @app.route("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 217–218why, one step back
217 def index():
218 flask.g.value = 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 219why, one step back
219 return "Hello World!"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 220why, one step back
220

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 221why, one step back
221 @app.route("/other")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 222–225why, one step back
222 def other():
223 1 // 0224225 with client:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 226why, one step back
226 resp = client.get("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 227why, one step back
227 assert flask.g.value == 42

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 228why, one step back
228 assert resp.data == b"Hello World!"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 229–230why, one step back
229 assert resp.status_code == 200
230

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 231–233why, one step back
231 resp = client.get("/other")
232 assert not hasattr(flask.g, "value")233 assert b"Internal Server Error" in resp.data

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 234–241why, one step back
234 assert resp.status_code == 500
235 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 back
242 raise AssertionError("some kind of exception expected")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 243–248why, one step back
243
244245def test_reuse_client(client):246 c = client247248 with c:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 249why, one step back
249 assert client.get("/").status_code == 404

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 250–251why, one step back
250
251 with c:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 252why, one step back
252 assert client.get("/").status_code == 404

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 253–263why, one step back
253
254255def 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 back
264 client.get("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 265–270why, one step back
265 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 back
271 client.get("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 272why, one step back
272 assert called == []

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 273why, one step back
273 client.get("/")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 274–278why, one step back
274 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 back
279 @app.route("/action", methods=["POST"])

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 280why, one step back
280 def action():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 281why, one step back
281 return "x"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 282–283why, one step back
282
283 with client:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 284why, one step back
284 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 back
285 assert rv.status_code == 200

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 286–287why, one step back
286 assert "gin" in flask.request.form
287 assert "vodka" in flask.request.args

Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8

lines 288–290why, one step back
288
289290def test_json_request_and_response(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 291why, one step back
291 @app.route("/echo", methods=["POST"])

Merge pull request #2358 from davidism/json-mixinDavid Lordbefore adoption63129e8

lines 292–295why, one step back
292 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 back
296 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 back
298
299 # 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_data

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 307–308why, one step back
307
308

Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20

lines 309–310why, one step back
309def test_subdomain():
310 app = flask.Flask(__name__, subdomain_matching=True)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 311why, one step back
311 app.config["SERVER_NAME"] = "example.com"

Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20

line 312why, one step back
312 client = app.test_client()

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 313why, one step back
313

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 314why, one step back
314 @app.route("/", subdomain="<company_id>")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 315–318why, one step back
315 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 back
319 url = flask.url_for("view", company_id="xxx")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 320–324why, one step back
320
321 with client:322 response = client.get(url)323324 assert 200 == response.status_code

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 325why, one step back
325 assert b"xxx" == response.data

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 326–328why, one step back
326
327328def test_nosubdomain(app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 329why, one step back
329 app.config["SERVER_NAME"] = "example.com"

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

line 330why, one step back
330

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 331why, one step back
331 @app.route("/<company_id>")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 332–335why, one step back
332 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 back
336 url = flask.url_for("view", company_id="xxx")

Merge pull request #2353 from grantwwu/patch-1David Lordbefore adoption49f3e96

lines 337–341why, one step back
337
338 with client:339 response = client.get(url)340341 assert 200 == response.status_code

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 342why, one step back
342 assert b"xxx" == response.data

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

lines 343–357why, one step back
343
344345def 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 back
358 @app.cli.command("hello")

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

line 359why, one step back
359 def hello_command():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 360why, one step back
360 click.echo("Hello, World!")

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

lines 361–363why, one step back
361
362 runner = app.test_cli_runner()363 # invoke with command name

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 364–365why, one step back
364 result = runner.invoke(args=["hello"])
365 assert "Hello" in result.output

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

lines 366–367why, one step back
366 # invoke with command object
367 result = runner.invoke(hello_command)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 368why, one step back
368 assert "Hello" in result.output

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

lines 369–378why, one step back
369
370371def test_cli_custom_obj(app):372 class NS(object):373 called = False374375 def create_app():376 NS.called = True377 return app378

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 379why, one step back
379 @app.cli.command("hello")

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

line 380why, one step back
380 def hello_command():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 381why, one step back
381 click.echo("Hello, World!")

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

lines 382–386why, one step back
382
383 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