Skip to content
Myr

test_testing.py

This file

Path

tests/test_testing.py

447 lines · 11.7 KiB · Python

Last changed by

Merge branch '1.0.x'David Lordbefore adoption1351d0a

History of this file

Take it

The walk stopped after 200 commits: lines older than 40745bb point at it.

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 1–7why, one step back
1# -*- coding: utf-8 -*-
2"""3 tests.testing4 ~~~~~~~~~~~~~56 Test client and more.7

Merge branch '1.0.x'David Lordbefore adoption1351d0a

lines 8–9why, one step back
8 :copyright: 2010 Pallets
9 :license: BSD-3-Clause

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 10why, one step back
10"""

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

line 11why, one step back
11import click

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 12–14why, one step back
12import pytest
13import werkzeug14

Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697

line 15why, one step back
15import flask

Merge branch '1.0.x'David Lordbefore adoption05a4e15

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 17why, one step back
17from 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 #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697

lines 20–22why, one step back
20from flask.testing import EnvironBuilder
21from flask.testing import FlaskCliRunner22from flask.testing import make_test_environ_builder

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 23why, one step back
23

Merge branch '1.0.x'David Lordbefore adoption05a4e15

lines 24–27why, one step back
24try:
25 import blinker26except ImportError:27 blinker = None

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 28why, one step back
28

Merge branch '1.0.x'David Lordbefore adoption05a4e15

line 29why, one step back
29

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 33why, one step back
33

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 35–38why, one step back
35 def index():
36 return flask.request.url3738 ctx = app.test_request_context()

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

line 39why, one step back
39 assert ctx.request.url == "http://example.com:1234/foo/"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 40why, one step back
40

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 43–45why, one step back
43
4445def test_environ_defaults(app, client, app_ctx, req_ctx):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 47–50why, one step back
47 def index():
48 return flask.request.url4950 ctx = app.test_request_context()

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

line 51why, one step back
51 assert ctx.request.url == "http://localhost/"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 52why, one step back
52 with client:

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

lines 53–54why, one step back
53 rv = client.get("/")
54 assert rv.data == b"http://localhost/"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 55–57why, one step back
55
5657def test_environ_base_default(app, client, app_ctx):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

lines 63–65why, one step back
63 rv = client.get("/")
64 assert rv.data == b"127.0.0.1"65 assert flask.g.user_agent == "werkzeug/" + werkzeug.__version__

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 66–68why, one step back
66
6768def test_environ_base_modified(app, client, app_ctx):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

lines 74–78why, one step back
74 client.environ_base["REMOTE_ADDR"] = "0.0.0.0"
75 client.environ_base["HTTP_USER_AGENT"] = "Foo"76 rv = client.get("/")77 assert rv.data == b"0.0.0.0"78 assert flask.g.user_agent == "Foo"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 79why, one step back
79

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

lines 80–84why, one step back
80 client.environ_base["REMOTE_ADDR"] = "0.0.0.1"
81 client.environ_base["HTTP_USER_AGENT"] = "Bar"82 rv = client.get("/")83 assert rv.data == b"0.0.0.1"84 assert flask.g.user_agent == "Bar"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 85–87why, one step back
85
8687def test_client_open_environ(app, client, request):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 93–95why, one step back
93 request.addfinalizer(builder.close)
9495 rv = client.open(builder)

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 102–104why, one step back
102
103104def test_specify_url_scheme(app, client):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

lines 109–110why, one step back
109 ctx = app.test_request_context(url_scheme="https")
110 assert ctx.request.url == "https://localhost/"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 111why, one step back
111

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

lines 112–113why, one step back
112 rv = client.get("/", url_scheme="https")
113 assert rv.data == b"https://localhost/"

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 114–116why, one step back
114
115116def test_path_is_url(app):

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

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

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

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

Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 138–139why, one step back
138
139

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

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

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

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 145why, one step back
145

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 147why, one step back
147

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 149–153why, one step back
149 def index():
150 return flask.request.url151152 app.register_blueprint(bp)153

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

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

Merge pull request #3104 from eladm26/adding_models_converterDavid Lordbefore adoption2fa30f6

lines 156–158why, one step back
156
157 with ctx:158 assert ctx.request.blueprint == bp.name

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 159why, one step back
159

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 162–164why, one step back
162
163164def test_redirect_keep_session(app, client, app_ctx):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 171why, one step back
171

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 175–176why, one step back
175
176 with client:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 179why, one step back
179

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 185–186why, one step back
185
186 # This support requires a new Werkzeug version

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 189why, one step back
189

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 192–194why, one step back
192
193194def test_session_transactions(app, client):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 198–201why, one step back
198
199 with client:200 with client.session_transaction() as sess:201 assert len(sess) == 0

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 209–216why, one step back
209
210211def test_session_transactions_no_null_sessions():212 app = flask.Flask(__name__)213 app.testing = True214215 with app.test_client() as c:216 with pytest.raises(RuntimeError) as e:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 218why, one step back
218 pass

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 220–222why, one step back
220
221222def test_session_transactions_keep_context(app, client, req_ctx):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 224–232why, one step back
224 req = flask.request._get_current_object()
225 assert req is not None226 with client.session_transaction():227 assert req is flask.request._get_current_object()228229230def test_session_transaction_needs_cookies(app):231 c = app.test_client(use_cookies=False)232 with pytest.raises(RuntimeError) as e:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 234why, one step back
234 pass

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 236–240why, one step back
236
237238def test_test_client_context_binding(app, client):239 app.testing = False240

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 245why, one step back
245

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 247–250why, one step back
247 def other():
248 1 // 0249250 with client:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 254–255why, one step back
254 assert resp.status_code == 200
255

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 259–266why, one step back
259 assert resp.status_code == 500
260 flask.g.value = 23261262 try:263 flask.g.value264 except (AttributeError, RuntimeError):265 pass266 else:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 268–273why, one step back
268
269270def test_reuse_client(client):271 c = client272273 with c:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 275–276why, one step back
275
276 with c:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 278–288why, one step back
278
279280def test_test_client_calls_teardown_handlers(app, client):281 called = []282283 @app.teardown_request284 def remember(error):285 called.append(error)286287 with client:288 assert called == []

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 290–295why, one step back
290 assert called == []
291 assert called == [None]292293 del called[:]294 with client:295 assert called == []

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 299–303why, one step back
299 assert called == [None]
300 assert called == [None, None]301302303def test_full_url_request(app, client):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 307–308why, one step back
307
308 with client:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 313–315why, one step back
313
314315def test_json_request_and_response(app, client):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 317–320why, one step back
317 def echo():
318 return jsonify(flask.request.get_json())319320 with client:

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 323–331why, one step back
323
324 # Request should be in JSON325 assert flask.request.is_json326 assert flask.request.get_json() == json_data327328 # Response should be in JSON329 assert rv.status_code == 200330 assert rv.is_json331 assert rv.get_json() == json_data

Merge branch '1.0.x'David Lordbefore adoption05a4e15

lines 332–352why, one step back
332
333334@pytest.mark.skipif(blinker is None, reason="blinker is not installed")335def test_client_json_no_app_context(app, client):336 @app.route("/hello", methods=["POST"])337 def hello():338 return "Hello, {}!".format(flask.request.json["name"])339340 class Namespace(object):341 count = 0342343 def add(self, app):344 self.count += 1345346 ns = Namespace()347348 with appcontext_popped.connected_to(ns.add, app):349 rv = client.post("/hello", json={"name": "Flask"})350351 assert rv.get_data(as_text=True) == "Hello, Flask!"352 assert ns.count == 1

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 353–354why, one step back
353
354

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

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

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

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

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 359why, one step back
359

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 361–364why, one step back
361 def view(company_id):
362 return company_id363364 with app.test_request_context():

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 366–370why, one step back
366
367 with client:368 response = client.get(url)369370 assert 200 == response.status_code

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 372–374why, one step back
372
373374def test_nosubdomain(app, client):

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

line 376why, one step back
376

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 378–381why, one step back
378 def view(company_id):
379 return company_id380381 with app.test_request_context():

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

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

Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb

lines 383–387why, one step back
383
384 with client:385 response = client.get(url)386387 assert 200 == response.status_code

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

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

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

lines 389–403why, one step back
389
390391def test_cli_runner_class(app):392 runner = app.test_cli_runner()393 assert isinstance(runner, FlaskCliRunner)394395 class SubRunner(FlaskCliRunner):396 pass397398 app.test_cli_runner_class = SubRunner399 runner = app.test_cli_runner()400 assert isinstance(runner, SubRunner)401402403def test_cli_invoke(app):

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

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

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

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

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

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

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

lines 407–409why, one step back
407
408 runner = app.test_cli_runner()409 # invoke with command name

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

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

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

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

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

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

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

lines 415–424why, one step back
415
416417def test_cli_custom_obj(app):418 class NS(object):419 called = False420421 def create_app():422 NS.called = True423 return app424

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

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

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

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

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

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

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

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

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

lines 433–447why, one step back
433
434435def test_client_pop_all_preserved(app, req_ctx, client):436 @app.route("/")437 def index():438 # stream_with_context pushes a third context, preserved by client439 return flask.Response(flask.stream_with_context("hello"))440441 # req_ctx fixture pushed an initial context, not marked preserved442 with client:443 # request pushes a second request context, preserved by client444 client.get("/")445446 # only req_ctx fixture should still be pushed447 assert flask._request_ctx_stack.top is req_ctx