Skip to content
Myr

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 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–16why, one step back
12import pytest
1314import flask15import werkzeug16

Merge branch '1.0.x'David Lordbefore adoption05a4e15

line 17why, one step back
17from flask import appcontext_popped

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

line 18why, one step back
18from flask._compat import text_type

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

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

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

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

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

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

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

line 22why, one step back
22

Merge branch '1.0.x'David Lordbefore adoption05a4e15

lines 23–26why, one step back
23try:
24 import blinker25except ImportError:26 blinker = None

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

line 27why, one step back
27

Merge branch '1.0.x'David Lordbefore adoption05a4e15

line 28why, one step back
28

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

line 29why, one step back
29def test_environ_defaults_from_config(app, client):

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

lines 30–31why, one step back
30 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 back
32

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

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

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

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

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

line 39why, one step back
39

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

lines 40–41why, one step back
40 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 back
42
4344def test_environ_defaults(app, client, app_ctx, req_ctx):

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

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

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

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

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

line 51why, one step back
51 with client:

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

lines 52–53why, one step back
52 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 back
54
5556def test_environ_base_default(app, client, app_ctx):

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

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

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

lines 58–61why, one step back
58 def index():
59 flask.g.user_agent = flask.request.headers["User-Agent"]60 return flask.request.remote_addr61

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

lines 62–64why, one step back
62 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 back
65
6667def test_environ_base_modified(app, client, app_ctx):

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

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

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

lines 69–72why, one step back
69 def index():
70 flask.g.user_agent = flask.request.headers["User-Agent"]71 return flask.request.remote_addr72

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.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 back
78

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

lines 79–83why, one step back
79 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 back
84
8586def test_client_open_environ(app, client, request):

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

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

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

lines 88–90why, one step back
88 def index():
89 return flask.request.remote_addr90

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

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

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

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

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

lines 96–97why, one step back
96
97 environ = builder.get_environ()

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

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

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

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

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

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

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

lines 101–103why, one step back
101
102103def test_specify_url_scheme(app, client):

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

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

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

lines 105–107why, one step back
105 def index():
106 return flask.request.url107

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

lines 108–109why, one step back
108 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 back
110

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

lines 111–112why, one step back
111 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 back
113
114

Merge pull request #2430 from erebus1/env_url_scheme_fixDavid Lordbefore adoption85fa8aa

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

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

lines 116–120why, one step back
116 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 back
121
122

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

lines 123–124why, one step back
123def 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 back
125 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 back
127 client = app.test_client()

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

line 128why, one step back
128

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

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

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

line 130why, one step back
130

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

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

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

lines 132–136why, one step back
132 def index():
133 return flask.request.url134135 app.register_blueprint(bp)136

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

lines 137–138why, one step back
137 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 back
139 assert ctx.request.blueprint == bp.name
140

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

lines 141–142why, one step back
141 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 back
143
144145def test_redirect_keep_session(app, client, app_ctx):

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

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

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

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

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

lines 148–151why, one step back
148 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 back
152

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

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

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

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

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

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

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

lines 156–157why, one step back
156
157 with client:

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

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

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

line 160why, one step back
160

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

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

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

lines 168–169why, one step back
168 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 back
170

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

lines 171–172why, one step back
171 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 back
173
174175def test_session_transactions(app, client):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

line 200why, one step back
200 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 back
201
202203def test_session_transactions_keep_context(app, client, req_ctx):

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

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

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

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

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

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

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

lines 217–221why, one step back
217
218219def test_test_client_context_binding(app, client):220 app.testing = False221

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

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

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

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

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

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

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

line 226why, one step back
226

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

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

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

lines 228–231why, one step back
228 def other():
229 1 // 0230231 with client:

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

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

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

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

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

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

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

lines 235–236why, one step back
235 assert resp.status_code == 200
236

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

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

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

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

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

lines 249–254why, one step back
249
250251def test_reuse_client(client):252 c = client253254 with c:

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

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

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

lines 256–257why, one step back
256
257 with c:

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

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

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

lines 259–269why, one step back
259
260261def 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 back
270 client.get("/")

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

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

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

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

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

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

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

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

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

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

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

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

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

lines 288–289why, one step back
288
289 with client:

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

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

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

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

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

lines 294–296why, one step back
294
295296def test_json_request_and_response(app, client):

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

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

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

lines 298–301why, one step back
298 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 back
302 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 back
304
305 # 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_data

Merge branch '1.0.x'David Lordbefore adoption05a4e15

lines 313–333why, one step back
313
314315@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 == 1

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

lines 334–335why, one step back
334
335

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

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

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

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

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

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

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

line 340why, one step back
340

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

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

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

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

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

lines 347–351why, one step back
347
348 with client:349 response = client.get(url)350351 assert 200 == response.status_code

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

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

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

lines 353–355why, one step back
353
354355def test_nosubdomain(app, client):

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

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

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

line 357why, one step back
357

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

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

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

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

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

lines 364–368why, one step back
364
365 with client:366 response = client.get(url)367368 assert 200 == response.status_code

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

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

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

lines 370–384why, one step back
370
371372def 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 back
385 @app.cli.command("hello")

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

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

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

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

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

lines 388–390why, one step back
388
389 runner = app.test_cli_runner()390 # invoke with command name

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

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

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

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

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

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

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

lines 396–405why, one step back
396
397398def test_cli_custom_obj(app):399 class NS(object):400 called = False401402 def create_app():403 NS.called = True404 return app405

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

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

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

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

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

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

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

lines 409–413why, one step back
409
410 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