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 fileTake 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 back1# -*- coding: utf-8 -*-2"""3 tests.testing4 ~~~~~~~~~~~~~56 Test client and more.7Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c
line 8why, one step back8 :copyright: © 2010 by the Pallets team.Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 9–10why, one step back9 :license: BSD, see LICENSE for more details.10"""Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 11why, one step back11import clickMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 12–16why, one step back12import pytest1314import flask15import werkzeug16Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 17why, one step back17from flask import appcontext_poppedMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 18why, one step back18from flask._compat import text_typeMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 19why, one step back19from flask.cli import ScriptInfoMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 20why, one step back20from flask.json import jsonifyMerge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 21why, one step back21from flask.testing import make_test_environ_builder, FlaskCliRunner, EnvironBuilderMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 22why, one step back22Merge branch '1.0.x'David Lordbefore adoption05a4e15
lines 23–26why, one step back23try:24 import blinker25except ImportError:26 blinker = NoneMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 27why, one step back27Merge branch '1.0.x'David Lordbefore adoption05a4e15
line 28why, one step back28Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 29why, one step back29def test_environ_defaults_from_config(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 30–31why, one step back30 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 back32Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 33why, one step back33 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 34–37why, one step back34 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 back38 assert ctx.request.url == "http://example.com:1234/foo/"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 39why, one step back39Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 40–41why, one step back40 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 back424344def test_environ_defaults(app, client, app_ctx, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 45why, one step back45 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 46–49why, one step back46 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 back50 assert ctx.request.url == "http://localhost/"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 51why, one step back51 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 52–53why, one step back52 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 back545556def test_environ_base_default(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 57why, one step back57 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 58–61why, one step back58 def index():59 flask.g.user_agent = flask.request.headers["User-Agent"]60 return flask.request.remote_addr61Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 62–64why, one step back62 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 back656667def test_environ_base_modified(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 68why, one step back68 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 69–72why, one step back69 def index():70 flask.g.user_agent = flask.request.headers["User-Agent"]71 return flask.request.remote_addr72Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 73–77why, one step back73 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 back78Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 79–83why, one step back79 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 back848586def test_client_open_environ(app, client, request):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 87why, one step back87 @app.route("/index")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 88–90why, one step back88 def index():89 return flask.request.remote_addr90Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 91why, one step back91 builder = EnvironBuilder(app, path="/index", method="GET")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 92–94why, one step back92 request.addfinalizer(builder.close)9394 rv = client.open(builder)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 95why, one step back95 assert rv.data == b"127.0.0.1"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 96–97why, one step back9697 environ = builder.get_environ()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 98why, one step back98 client.environ_base["REMOTE_ADDR"] = "127.0.0.2"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 99why, one step back99 rv = client.open(environ)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 100why, one step back100 assert rv.data == b"127.0.0.2"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 101–103why, one step back101102103def test_specify_url_scheme(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 104why, one step back104 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 105–107why, one step back105 def index():106 return flask.request.url107Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 108–109why, one step back108 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 back110Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 111–112why, one step back111 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 back113114115def test_path_is_url(app):Merge pull request #3232 from lordmauve/environbuilderDavid Lordbefore adoption5e15850
line 116why, one step back116 eb = EnvironBuilder(app, "https://example.com/")Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 117–120why, one step back117 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 back121122123def 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 back137138Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 139–140why, one step back139def 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 back141 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 back143 client = app.test_client()Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 144why, one step back144Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 145why, one step back145 bp = flask.Blueprint("company", __name__, subdomain="xxx")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 146why, one step back146Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 147why, one step back147 @bp.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 148–152why, one step back148 def index():149 return flask.request.url150151 app.register_blueprint(bp)152Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 153–154why, one step back153 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 back155 assert ctx.request.blueprint == bp.name156Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 157–158why, one step back157 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 back159160161def test_redirect_keep_session(app, client, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 162why, one step back162 @app.route("/", methods=["GET", "POST"])Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 163why, one step back163 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 164–167why, one step back164 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 back168Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 169why, one step back169 @app.route("/getsession")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 170why, one step back170 def get_session():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 171why, one step back171 return flask.session.get("data", "<missing>")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 172–173why, one step back172173 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 174–175why, one step back174 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 back176Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 177–181why, one step back177 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 back182183 # This support requires a new Werkzeug versionMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 184–185why, one step back184 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 back186Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 187–188why, one step back187 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 back189190191def test_session_transactions(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 192why, one step back192 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 193why, one step back193 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 194why, one step back194 return text_type(flask.session["foo"])Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 195–198why, one step back195196 with client:197 with client.session_transaction() as sess:198 assert len(sess) == 0Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 199why, one step back199 sess["foo"] = [42]Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 200why, one step back200 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 201–202why, one step back201 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 back203 with client.session_transaction() as sess:204 assert len(sess) == 1Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 205why, one step back205 assert sess["foo"] == [42]Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 206–213why, one step back206207208def 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 back214 with c.session_transaction():Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 215why, one step back215 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 216why, one step back216 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 back217218219def test_session_transactions_keep_context(app, client, req_ctx):Merge pull request #3241 from jon-stumpf/jss-updatesDavid Lordbefore adoption48d0e86
line 220why, one step back220 client.get("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 221–229why, one step back221 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 back230 with c.session_transaction():Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 231why, one step back231 passMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 232why, one step back232 assert "cookies" in str(e.value)Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 233–237why, one step back233234235def test_test_client_context_binding(app, client):236 app.testing = False237Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 238why, one step back238 @app.route("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 239–240why, one step back239 def index():240 flask.g.value = 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 241why, one step back241 return "Hello World!"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 242why, one step back242Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 243why, one step back243 @app.route("/other")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 244–247why, one step back244 def other():245 1 // 0246247 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 248why, one step back248 resp = client.get("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 249why, one step back249 assert flask.g.value == 42Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 250why, one step back250 assert resp.data == b"Hello World!"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 251–252why, one step back251 assert resp.status_code == 200252Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 253–255why, one step back253 resp = client.get("/other")254 assert not hasattr(flask.g, "value")255 assert b"Internal Server Error" in resp.dataMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 256–263why, one step back256 assert resp.status_code == 500257 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 back264 raise AssertionError("some kind of exception expected")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 265–270why, one step back265266267def test_reuse_client(client):268 c = client269270 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 271why, one step back271 assert client.get("/").status_code == 404Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 272–273why, one step back272273 with c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 274why, one step back274 assert client.get("/").status_code == 404Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 275–285why, one step back275276277def 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 back286 client.get("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 287–292why, one step back287 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 back293 client.get("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 294why, one step back294 assert called == []Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 295why, one step back295 client.get("/")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 296–300why, one step back296 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 back301 @app.route("/action", methods=["POST"])Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 302why, one step back302 def action():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 303why, one step back303 return "x"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 304–305why, one step back304305 with client:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 306why, one step back306 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 back307 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 308–309why, one step back308 assert "gin" in flask.request.form309 assert "vodka" in flask.request.argsMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 310–312why, one step back310311312def test_json_request_and_response(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 313why, one step back313 @app.route("/echo", methods=["POST"])Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 314–317why, one step back314 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 back318 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 back320321 # 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_dataMerge branch '1.0.x'David Lordbefore adoption05a4e15
lines 329–349why, one step back329330331@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 == 1Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 350–351why, one step back350351Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
lines 352–353why, one step back352def test_subdomain():353 app = flask.Flask(__name__, subdomain_matching=True)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 354why, one step back354 app.config["SERVER_NAME"] = "example.com"Merge pull request #2635 from pallets/feature/server-name-routingDavid Lordbefore adoptionf808c20
line 355why, one step back355 client = app.test_client()Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 356why, one step back356Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 357why, one step back357 @app.route("/", subdomain="<company_id>")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 358–361why, one step back358 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 back362 url = flask.url_for("view", company_id="xxx")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 363–367why, one step back363364 with client:365 response = client.get(url)366367 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 368why, one step back368 assert b"xxx" == response.dataMention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 369–371why, one step back369370371def test_nosubdomain(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 372why, one step back372 app.config["SERVER_NAME"] = "example.com"Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
line 373why, one step back373Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 374why, one step back374 @app.route("/<company_id>")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 375–378why, one step back375 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 back379 url = flask.url_for("view", company_id="xxx")Mention Flask instead of Jinja in the issue templateJaap Broekhuizenbefore adoption62a6aab
lines 380–384why, one step back380381 with client:382 response = client.get(url)383384 assert 200 == response.status_codeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 385why, one step back385 assert b"xxx" == response.dataMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 386–400why, one step back386387388def 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 back401 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 402why, one step back402 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 403why, one step back403 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 404–406why, one step back404405 runner = app.test_cli_runner()406 # invoke with command nameMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 407–408why, one step back407 result = runner.invoke(args=["hello"])408 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 409–410why, one step back409 # invoke with command object410 result = runner.invoke(hello_command)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 411why, one step back411 assert "Hello" in result.outputMerge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 412–421why, one step back412413414def test_cli_custom_obj(app):415 class NS(object):416 called = False417418 def create_app():419 NS.called = True420 return app421Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 422why, one step back422 @app.cli.command("hello")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
line 423why, one step back423 def hello_command():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 424why, one step back424 click.echo("Hello, World!")Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66
lines 425–429why, one step back425426 script_info = ScriptInfo(create_app=create_app)427 runner = app.test_cli_runner()428 runner.invoke(hello_command, obj=script_info)429 assert NS.calledMerge pull request #3157 from fantix/fix-test-client-teardownDavid Lordbefore adoption2c68f86
lines 430–444why, one step back430431432def 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