Skip to content
Myr

test_testing.py

This file

Path

tests/test_testing.py

444 lines · 11.6 KiB · Python

Last changed by

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

History of this file

Take it

The walk stopped after 200 commits: lines older than 62a6aab point at it.

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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.

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 27why, one step back
27

Merge branch '1.0.x'David Lordbefore adoption05a4e15

line 28why, one step back
28

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 32why, one step back
32

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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("/")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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("/")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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__

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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("/")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

line 91why, one step back
91 builder = EnvironBuilder(app, path="/index", method="GET")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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("/")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 113–115why, one step back
113
114115def test_path_is_url(app):

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

line 116why, one step back
116 eb = EnvironBuilder(app, "https://example.com/")

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

lines 117–120why, one step back
117 assert eb.url_scheme == "https"
118 assert eb.host == "example.com"119 assert eb.script_root == ""120 assert eb.path == "/"

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

lines 121–136why, one step back
121
122123def test_make_test_environ_builder(app):124 with pytest.deprecated_call():125 eb = make_test_environ_builder(app, "https://example.com/")126 assert eb.url_scheme == "https"127 assert eb.host == "example.com"128 assert eb.script_root == ""129 assert eb.path == "/"130131132def test_environbuilder_json_dumps(app):133 """EnvironBuilder.json_dumps() takes settings from the app."""134 app.config["JSON_AS_ASCII"] = False135 eb = EnvironBuilder(app, json=u"\u20ac")136 assert eb.input_stream.read().decode("utf8") == u'"\u20ac"'

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 137–138why, one step back
137
138

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

lines 139–140why, one step back
139def test_blueprint_with_subdomain():
140 app = flask.Flask(__name__, subdomain_matching=True)

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

lines 141–142why, one step back
141 app.config["SERVER_NAME"] = "example.com:1234"
142 app.config["APPLICATION_ROOT"] = "/foo"

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 144why, one step back
144

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 146why, one step back
146

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 148–152why, one step back
148 def index():
149 return flask.request.url150151 app.register_blueprint(bp)152

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

lines 153–154why, one step back
153 ctx = app.test_request_context("/", subdomain="xxx")
154 assert ctx.request.url == "http://xxx.example.com:1234/foo/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 155–156why, one step back
155 assert ctx.request.blueprint == bp.name
156

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

lines 157–158why, one step back
157 rv = client.get("/", subdomain="xxx")
158 assert rv.data == b"http://xxx.example.com:1234/foo/"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 159–161why, one step back
159
160161def test_redirect_keep_session(app, client, app_ctx):

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

lines 164–167why, one step back
164 if flask.request.method == "POST":
165 return flask.redirect("/getsession")166 flask.session["data"] = "foo"167 return "index"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 168why, one step back
168

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 172–173why, one step back
172
173 with client:

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 176why, one step back
176

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

lines 177–181why, one step back
177 rv = client.get("/")
178 assert rv.data == b"index"179 assert flask.session.get("data") == "foo"180 rv = client.post("/", data={}, follow_redirects=True)181 assert rv.data == b"foo"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 182–183why, one step back
182
183 # This support requires a new Werkzeug version

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

lines 184–185why, one step back
184 if not hasattr(client, "redirect_client"):
185 assert flask.session.get("data") == "foo"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 186why, one step back
186

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

lines 187–188why, one step back
187 rv = client.get("/getsession")
188 assert rv.data == b"foo"

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 189–191why, one step back
189
190191def test_session_transactions(app, client):

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 195–198why, one step back
195
196 with client:197 with client.session_transaction() as sess:198 assert len(sess) == 0

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 206–213why, one step back
206
207208def test_session_transactions_no_null_sessions():209 app = flask.Flask(__name__)210 app.testing = True211212 with app.test_client() as c:213 with pytest.raises(RuntimeError) as e:

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 214why, one step back
214 with c.session_transaction():

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 215why, one step back
215 pass

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

line 216why, one step back
216 assert "Session backend did not open a session" in str(e.value)

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 217–219why, one step back
217
218219def test_session_transactions_keep_context(app, client, req_ctx):

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 221–229why, one step back
221 req = flask.request._get_current_object()
222 assert req is not None223 with client.session_transaction():224 assert req is flask.request._get_current_object()225226227def test_session_transaction_needs_cookies(app):228 c = app.test_client(use_cookies=False)229 with pytest.raises(RuntimeError) as e:

Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86

line 230why, one step back
230 with c.session_transaction():

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 231why, one step back
231 pass

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 233–237why, one step back
233
234235def test_test_client_context_binding(app, client):236 app.testing = False237

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 242why, one step back
242

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 244–247why, one step back
244 def other():
245 1 // 0246247 with client:

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 251–252why, one step back
251 assert resp.status_code == 200
252

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 256–263why, one step back
256 assert resp.status_code == 500
257 flask.g.value = 23258259 try:260 flask.g.value261 except (AttributeError, RuntimeError):262 pass263 else:

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

line 264why, one step back
264 raise AssertionError("some kind of exception expected")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 265–270why, one step back
265
266267def test_reuse_client(client):268 c = client269270 with c:

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 272–273why, one step back
272
273 with c:

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 275–285why, one step back
275
276277def test_test_client_calls_teardown_handlers(app, client):278 called = []279280 @app.teardown_request281 def remember(error):282 called.append(error)283284 with client:285 assert called == []

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 287–292why, one step back
287 assert called == []
288 assert called == [None]289290 del called[:]291 with client:292 assert called == []

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 296–300why, one step back
296 assert called == [None]
297 assert called == [None, None]298299300def test_full_url_request(app, client):

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 304–305why, one step back
304
305 with client:

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

line 306why, one step back
306 rv = client.post("http://domain.com/action?vodka=42", data={"gin": 43})

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 307why, one step back
307 assert rv.status_code == 200

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 310–312why, one step back
310
311312def test_json_request_and_response(app, client):

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 314–317why, one step back
314 def echo():
315 return jsonify(flask.request.get_json())316317 with client:

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

lines 318–319why, one step back
318 json_data = {"drink": {"gin": 1, "tonic": True}, "price": 10}
319 rv = client.post("/echo", json=json_data)

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 320–328why, one step back
320
321 # Request should be in JSON322 assert flask.request.is_json323 assert flask.request.get_json() == json_data324325 # Response should be in JSON326 assert rv.status_code == 200327 assert rv.is_json328 assert rv.get_json() == json_data

Merge branch '1.0.x'David Lordbefore adoption05a4e15

lines 329–349why, one step back
329
330331@pytest.mark.skipif(blinker is None, reason="blinker is not installed")332def test_client_json_no_app_context(app, client):333 @app.route("/hello", methods=["POST"])334 def hello():335 return "Hello, {}!".format(flask.request.json["name"])336337 class Namespace(object):338 count = 0339340 def add(self, app):341 self.count += 1342343 ns = Namespace()344345 with appcontext_popped.connected_to(ns.add, app):346 rv = client.post("/hello", json={"name": "Flask"})347348 assert rv.get_data(as_text=True) == "Hello, Flask!"349 assert ns.count == 1

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 350–351why, one step back
350
351

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

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

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

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

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 356why, one step back
356

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 358–361why, one step back
358 def view(company_id):
359 return company_id360361 with app.test_request_context():

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

line 362why, one step back
362 url = flask.url_for("view", company_id="xxx")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 363–367why, one step back
363
364 with client:365 response = client.get(url)366367 assert 200 == response.status_code

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 369–371why, one step back
369
370371def test_nosubdomain(app, client):

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

line 373why, one step back
373

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

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

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 375–378why, one step back
375 def view(company_id):
376 return company_id377378 with app.test_request_context():

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

line 379why, one step back
379 url = flask.url_for("view", company_id="xxx")

Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab

lines 380–384why, one step back
380
381 with client:382 response = client.get(url)383384 assert 200 == response.status_code

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

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

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

lines 386–400why, one step back
386
387388def test_cli_runner_class(app):389 runner = app.test_cli_runner()390 assert isinstance(runner, FlaskCliRunner)391392 class SubRunner(FlaskCliRunner):393 pass394395 app.test_cli_runner_class = SubRunner396 runner = app.test_cli_runner()397 assert isinstance(runner, SubRunner)398399400def test_cli_invoke(app):

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

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

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

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

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

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

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

lines 404–406why, one step back
404
405 runner = app.test_cli_runner()406 # invoke with command name

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

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

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

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

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

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

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

lines 412–421why, one step back
412
413414def test_cli_custom_obj(app):415 class NS(object):416 called = False417418 def create_app():419 NS.called = True420 return app421

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

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

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

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

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

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

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

lines 425–429why, one step back
425
426 script_info = ScriptInfo(create_app=create_app)427 runner = app.test_cli_runner()428 runner.invoke(hello_command, obj=script_info)429 assert NS.called

Merge pull request #3157 from fantix/fix-test-client-teardownDavid Lordbefore adoption2c68f86

lines 430–444why, one step back
430
431432def test_client_pop_all_preserved(app, req_ctx, client):433 @app.route("/")434 def index():435 # stream_with_context pushes a third context, preserved by client436 return flask.Response(flask.stream_with_context("hello"))437438 # req_ctx fixture pushed an initial context, not marked preserved439 with client:440 # request pushes a second request context, preserved by client441 client.get("/")442443 # only req_ctx fixture should still be pushed444 assert flask._request_ctx_stack.top is req_ctx