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 fileTake 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 back1# -*- coding: utf-8 -*-2"""3 tests.testing4 ~~~~~~~~~~~~~56 Test client and more.7Merge branch '1.0.x'David Lordbefore adoption1351d0a
lines 8–9why, one step back8 :copyright: 2010 Pallets9 :license: BSD-3-ClauseMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 10why, one step back10"""Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 11why, one step back11import clickMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 12–14why, one step back12import pytest13import werkzeug14Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
line 15why, one step back15import flaskMerge branch '1.0.x'David Lordbefore adoption05a4e15
line 16why, one step back16from flask import appcontext_poppedMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 17why, one step back17from flask._compat import text_typeMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 18why, one step back18from flask.cli import ScriptInfoMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 19why, one step back19from flask.json import jsonifyMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 20–22why, one step back20from flask.testing import EnvironBuilder21from flask.testing import FlaskCliRunner22from flask.testing import make_test_environ_builderMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 23why, one step back23Merge branch '1.0.x'David Lordbefore adoption05a4e15
lines 24–27why, one step back24try:25 import blinker26except ImportError:27 blinker = NoneMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 28why, one step back28Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 29why, one step back29Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 30why, one step back30def test_environ_defaults_from_config(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 31–32why, one step back31 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 back33Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 34why, one step back34 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 35–38why, one step back35 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 back39 assert ctx.request.url == "http://example.com:1234/foo/"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 40why, one step back40Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 41–42why, one step back41 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 back434445def test_environ_defaults(app, client, app_ctx, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 46why, one step back46 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 47–50why, one step back47 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 back51 assert ctx.request.url == "http://localhost/"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 52why, one step back52 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 53–54why, one step back53 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 back555657def test_environ_base_default(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 58why, one step back58 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 59–62why, one step back59 def index():60 flask.g.user_agent = flask.request.headers["User-Agent"]61 return flask.request.remote_addr62Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 63–65why, one step back63 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 back666768def test_environ_base_modified(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 69why, one step back69 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 70–73why, one step back70 def index():71 flask.g.user_agent = flask.request.headers["User-Agent"]72 return flask.request.remote_addr73Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 74–78why, one step back74 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 back79Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 80–84why, one step back80 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 back858687def test_client_open_environ(app, client, request):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 88why, one step back88 @app.route("/index")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 89–91why, one step back89 def index():90 return flask.request.remote_addr91Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 92why, one step back92 builder = EnvironBuilder(app, path="/index", method="GET")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 93–95why, one step back93 request.addfinalizer(builder.close)9495 rv = client.open(builder)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 96why, one step back96 assert rv.data == b"127.0.0.1"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 97–98why, one step back9798 environ = builder.get_environ()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 99why, one step back99 client.environ_base["REMOTE_ADDR"] = "127.0.0.2"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 100why, one step back100 rv = client.open(environ)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 101why, one step back101 assert rv.data == b"127.0.0.2"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 102–104why, one step back102103104def test_specify_url_scheme(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 105why, one step back105 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 106–108why, one step back106 def index():107 return flask.request.url108Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 109–110why, one step back109 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 back111Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 112–113why, one step back112 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 back114115116def test_path_is_url(app):Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 117why, one step back117 eb = EnvironBuilder(app, "https://example.com/")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 118–121why, one step back118 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 back122123124def 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 back138139Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 140–141why, one step back140def 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 back142 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 back144 client = app.test_client()Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 145why, one step back145Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 146why, one step back146 bp = flask.Blueprint("company", __name__, subdomain="xxx")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 147why, one step back147Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 148why, one step back148 @bp.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 149–153why, one step back149 def index():150 return flask.request.url151152 app.register_blueprint(bp)153Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 154–155why, one step back154 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 back156157 with ctx:158 assert ctx.request.blueprint == bp.nameMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 159why, one step back159Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 160–161why, one step back160 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 back162163164def test_redirect_keep_session(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 165why, one step back165 @app.route("/", methods=["GET", "POST"])Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 166why, one step back166 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 167–170why, one step back167 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 back171Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 172why, one step back172 @app.route("/getsession")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 173why, one step back173 def get_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 174why, one step back174 return flask.session.get("data", "<missing>")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 175–176why, one step back175176 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 177–178why, one step back177 rv = client.get("/getsession")178 assert rv.data == b"<missing>"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 179why, one step back179Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 180–184why, one step back180 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 back185186 # This support requires a new Werkzeug versionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 187–188why, one step back187 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 back189Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 190–191why, one step back190 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 back192193194def test_session_transactions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 195why, one step back195 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 196why, one step back196 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 197why, one step back197 return text_type(flask.session["foo"])Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 198–201why, one step back198199 with client:200 with client.session_transaction() as sess:201 assert len(sess) == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 202why, one step back202 sess["foo"] = [42]Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 203why, one step back203 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 204–205why, one step back204 rv = client.get("/")205 assert rv.data == b"[42]"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 206–207why, one step back206 with client.session_transaction() as sess:207 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 208why, one step back208 assert sess["foo"] == [42]Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 209–216why, one step back209210211def 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 back217 with c.session_transaction():Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 218why, one step back218 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 219why, one step back219 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 back220221222def test_session_transactions_keep_context(app, client, req_ctx):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 223why, one step back223 client.get("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 224–232why, one step back224 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 back233 with c.session_transaction():Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 234why, one step back234 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 235why, one step back235 assert "cookies" in str(e.value)Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 236–240why, one step back236237238def test_test_client_context_binding(app, client):239 app.testing = False240Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 241why, one step back241 @app.route("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 242–243why, one step back242 def index():243 flask.g.value = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 244why, one step back244 return "Hello World!"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 245why, one step back245Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 246why, one step back246 @app.route("/other")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 247–250why, one step back247 def other():248 1 // 0249250 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 251why, one step back251 resp = client.get("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 252why, one step back252 assert flask.g.value == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 253why, one step back253 assert resp.data == b"Hello World!"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 254–255why, one step back254 assert resp.status_code == 200255Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 256–258why, one step back256 resp = client.get("/other")257 assert not hasattr(flask.g, "value")258 assert b"Internal Server Error" in resp.dataMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 259–266why, one step back259 assert resp.status_code == 500260 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 back267 raise AssertionError("some kind of exception expected")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 268–273why, one step back268269270def test_reuse_client(client):271 c = client272273 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 274why, one step back274 assert client.get("/").status_code == 404Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 275–276why, one step back275276 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 277why, one step back277 assert client.get("/").status_code == 404Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 278–288why, one step back278279280def 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 back289 client.get("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 290–295why, one step back290 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 back296 client.get("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 297why, one step back297 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 298why, one step back298 client.get("/")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 299–303why, one step back299 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 back304 @app.route("/action", methods=["POST"])Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 305why, one step back305 def action():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 306why, one step back306 return "x"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 307–308why, one step back307308 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 309why, one step back309 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 back310 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 311–312why, one step back311 assert "gin" in flask.request.form312 assert "vodka" in flask.request.argsMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 313–315why, one step back313314315def test_json_request_and_response(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 316why, one step back316 @app.route("/echo", methods=["POST"])Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 317–320why, one step back317 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 back321 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 back323324 # 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_dataMerge branch '1.0.x'David Lordbefore adoption05a4e15
lines 332–352why, one step back332333334@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 == 1Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 353–354why, one step back353354Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 355–356why, one step back355def test_subdomain():356 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 357why, one step back357 app.config["SERVER_NAME"] = "example.com"Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
line 358why, one step back358 client = app.test_client()Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 359why, one step back359Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 360why, one step back360 @app.route("/", subdomain="<company_id>")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 361–364why, one step back361 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 back365 url = flask.url_for("view", company_id="xxx")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 366–370why, one step back366367 with client:368 response = client.get(url)369370 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 371why, one step back371 assert b"xxx" == response.dataMerge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 372–374why, one step back372373374def test_nosubdomain(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 375why, one step back375 app.config["SERVER_NAME"] = "example.com"Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
line 376why, one step back376Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 377why, one step back377 @app.route("/<company_id>")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 378–381why, one step back378 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 back382 url = flask.url_for("view", company_id="xxx")Merge pull request #2581 from pallets/config-enotdirDavid Lordbefore adoption40745bb
lines 383–387why, one step back383384 with client:385 response = client.get(url)386387 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 388why, one step back388 assert b"xxx" == response.dataMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 389–403why, one step back389390391def 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 back404 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 405why, one step back405 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 406why, one step back406 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 407–409why, one step back407408 runner = app.test_cli_runner()409 # invoke with command nameMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 410–411why, one step back410 result = runner.invoke(args=["hello"])411 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 412–413why, one step back412 # invoke with command object413 result = runner.invoke(hello_command)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 414why, one step back414 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 415–424why, one step back415416417def test_cli_custom_obj(app):418 class NS(object):419 called = False420421 def create_app():422 NS.called = True423 return app424Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 425why, one step back425 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 426why, one step back426 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 427why, one step back427 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 428–432why, one step back428429 script_info = ScriptInfo(create_app=create_app)430 runner = app.test_cli_runner()431 runner.invoke(hello_command, obj=script_info)432 assert NS.calledMerge pull request #3157 from fantix/fix-test-client-teardownDavid Lordbefore adoption2c68f86
lines 433–447why, one step back433434435def 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