test_templating.py
This file
Path
tests/test_templating.py
451 lines · 12.1 KiB · Python
Last changed by
Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
History of this fileTake it
The walk stopped after 200 commits: lines older than c74f469 point at it.
Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 tests.templating4 ~~~~~~~~~~~~~~~~56 Template functionality7Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c
line 8why, one step back8 :copyright: © 2010 by the Pallets team.Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 9–22why, one step back9 :license: BSD, see LICENSE for more details.10"""1112import pytest1314import flask15import logging16from jinja2 import TemplateNotFound17import werkzeug.serving181920def test_context_processing(app, client):21 @app.context_processor22 def context_processor():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 23why, one step back23 return {"injected_value": 42}Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 24why, one step back24Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 25why, one step back25 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 26why, one step back26 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 27why, one step back27 return flask.render_template("context_template.html", value=23)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 28why, one step back28Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 29–30why, one step back29 rv = client.get("/")30 assert rv.data == b"<p>23|42"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 31–33why, one step back313233def test_original_win(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 34why, one step back34 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 35why, one step back35 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 36why, one step back36 return flask.render_template_string("{{ config }}", config=42)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 37why, one step back37Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 38–39why, one step back38 rv = client.get("/")39 assert rv.data == b"42"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 40–42why, one step back404142def test_request_less_rendering(app, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 43why, one step back43 app.config["WORLD_NAME"] = "Special World"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 44–48why, one step back4445 @app.context_processor46 def context_processor():47 return dict(foo=42)48Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 49–50why, one step back49 rv = flask.render_template_string("Hello {{ config.WORLD_NAME }} " "{{ foo }}")50 assert rv == "Hello Special World 42"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 51–53why, one step back515253def test_standard_context(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 54why, one step back54 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 55–56why, one step back55 def index():56 flask.g.foo = 23Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 57–59why, one step back57 flask.session["test"] = "aha"58 return flask.render_template_string(59 """Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 60–63why, one step back60 {{ request.args.foo }}61 {{ g.foo }}62 {{ config.DEBUG }}63 {{ session.test }}Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 64–65why, one step back64 """65 )Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 66why, one step back66Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 67–68why, one step back67 rv = client.get("/?foo=42")68 assert rv.data.split() == [b"42", b"23", b"False", b"aha"]Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 69–71why, one step back697071def test_escaping(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 72why, one step back72 text = "<p>Hello World!"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 73why, one step back73Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 74why, one step back74 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 75why, one step back75 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 76–78why, one step back76 return flask.render_template(77 "escaping_template.html", text=text, html=flask.Markup(text)78 )Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 79why, one step back79Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 80why, one step back80 lines = client.get("/").data.splitlines()Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 81why, one step back81 assert lines == [Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 82–87why, one step back82 b"<p>Hello World!",83 b"<p>Hello World!",84 b"<p>Hello World!",85 b"<p>Hello World!",86 b"<p>Hello World!",87 b"<p>Hello World!",Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 88–91why, one step back88 ]899091def test_no_escaping(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 92why, one step back92 text = "<p>Hello World!"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 93why, one step back93Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 94why, one step back94 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 95why, one step back95 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 96–98why, one step back96 return flask.render_template(97 "non_escaping_template.txt", text=text, html=flask.Markup(text)98 )Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 99why, one step back99Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 100why, one step back100 lines = client.get("/").data.splitlines()Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 101why, one step back101 assert lines == [Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 102–109why, one step back102 b"<p>Hello World!",103 b"<p>Hello World!",104 b"<p>Hello World!",105 b"<p>Hello World!",106 b"<p>Hello World!",107 b"<p>Hello World!",108 b"<p>Hello World!",109 b"<p>Hello World!",Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 110–113why, one step back110 ]111112113def test_escaping_without_template_filename(app, client, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 114–115why, one step back114 assert flask.render_template_string("{{ foo }}", foo="<test>") == "<test>"115 assert flask.render_template("mail.txt", foo="<test>") == "<test> Mail"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 116–118why, one step back116117118def test_macros(app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 119–120why, one step back119 macro = flask.get_template_attribute("_macro.html", "hello")120 assert macro("World") == "Hello World!"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 121–127why, one step back121122123def test_template_filter(app):124 @app.template_filter()125 def my_reverse(s):126 return s[::-1]127Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 128–130why, one step back128 assert "my_reverse" in app.jinja_env.filters.keys()129 assert app.jinja_env.filters["my_reverse"] == my_reverse130 assert app.jinja_env.filters["my_reverse"]("abcd") == "dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 131–137why, one step back131132133def test_add_template_filter(app):134 def my_reverse(s):135 return s[::-1]136137 app.add_template_filter(my_reverse)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 138–140why, one step back138 assert "my_reverse" in app.jinja_env.filters.keys()139 assert app.jinja_env.filters["my_reverse"] == my_reverse140 assert app.jinja_env.filters["my_reverse"]("abcd") == "dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 141–143why, one step back141142143def test_template_filter_with_name(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 144why, one step back144 @app.template_filter("strrev")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 145–147why, one step back145 def my_reverse(s):146 return s[::-1]147Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 148–150why, one step back148 assert "strrev" in app.jinja_env.filters.keys()149 assert app.jinja_env.filters["strrev"] == my_reverse150 assert app.jinja_env.filters["strrev"]("abcd") == "dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 151–156why, one step back151152153def test_add_template_filter_with_name(app):154 def my_reverse(s):155 return s[::-1]156Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 157–160why, one step back157 app.add_template_filter(my_reverse, "strrev")158 assert "strrev" in app.jinja_env.filters.keys()159 assert app.jinja_env.filters["strrev"] == my_reverse160 assert app.jinja_env.filters["strrev"]("abcd") == "dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 161–167why, one step back161162163def test_template_filter_with_template(app, client):164 @app.template_filter()165 def super_reverse(s):166 return s[::-1]167Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 168why, one step back168 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 169why, one step back169 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 170why, one step back170 return flask.render_template("template_filter.html", value="abcd")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 171why, one step back171Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 172–173why, one step back172 rv = client.get("/")173 assert rv.data == b"dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 174–181why, one step back174175176def test_add_template_filter_with_template(app, client):177 def super_reverse(s):178 return s[::-1]179180 app.add_template_filter(super_reverse)181Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 182why, one step back182 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 183why, one step back183 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 184why, one step back184 return flask.render_template("template_filter.html", value="abcd")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 185why, one step back185Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 186–187why, one step back186 rv = client.get("/")187 assert rv.data == b"dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 188–190why, one step back188189190def test_template_filter_with_name_and_template(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 191why, one step back191 @app.template_filter("super_reverse")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 192–194why, one step back192 def my_reverse(s):193 return s[::-1]194Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 195why, one step back195 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 196why, one step back196 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 197why, one step back197 return flask.render_template("template_filter.html", value="abcd")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 198why, one step back198Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 199–200why, one step back199 rv = client.get("/")200 assert rv.data == b"dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 201–206why, one step back201202203def test_add_template_filter_with_name_and_template(app, client):204 def my_reverse(s):205 return s[::-1]206Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 207why, one step back207 app.add_template_filter(my_reverse, "super_reverse")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 208why, one step back208Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 209why, one step back209 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 210why, one step back210 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 211why, one step back211 return flask.render_template("template_filter.html", value="abcd")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 212why, one step back212Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 213–214why, one step back213 rv = client.get("/")214 assert rv.data == b"dcba"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 215–221why, one step back215216217def test_template_test(app):218 @app.template_test()219 def boolean(value):220 return isinstance(value, bool)221Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 222–224why, one step back222 assert "boolean" in app.jinja_env.tests.keys()223 assert app.jinja_env.tests["boolean"] == boolean224 assert app.jinja_env.tests["boolean"](False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 225–231why, one step back225226227def test_add_template_test(app):228 def boolean(value):229 return isinstance(value, bool)230231 app.add_template_test(boolean)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 232–234why, one step back232 assert "boolean" in app.jinja_env.tests.keys()233 assert app.jinja_env.tests["boolean"] == boolean234 assert app.jinja_env.tests["boolean"](False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 235–237why, one step back235236237def test_template_test_with_name(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 238why, one step back238 @app.template_test("boolean")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 239–241why, one step back239 def is_boolean(value):240 return isinstance(value, bool)241Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 242–244why, one step back242 assert "boolean" in app.jinja_env.tests.keys()243 assert app.jinja_env.tests["boolean"] == is_boolean244 assert app.jinja_env.tests["boolean"](False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 245–250why, one step back245246247def test_add_template_test_with_name(app):248 def is_boolean(value):249 return isinstance(value, bool)250Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 251–254why, one step back251 app.add_template_test(is_boolean, "boolean")252 assert "boolean" in app.jinja_env.tests.keys()253 assert app.jinja_env.tests["boolean"] == is_boolean254 assert app.jinja_env.tests["boolean"](False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 255–261why, one step back255256257def test_template_test_with_template(app, client):258 @app.template_test()259 def boolean(value):260 return isinstance(value, bool)261Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 262why, one step back262 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 263why, one step back263 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 264why, one step back264 return flask.render_template("template_test.html", value=False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 265why, one step back265Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 266–267why, one step back266 rv = client.get("/")267 assert b"Success!" in rv.dataMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 268–275why, one step back268269270def test_add_template_test_with_template(app, client):271 def boolean(value):272 return isinstance(value, bool)273274 app.add_template_test(boolean)275Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 276why, one step back276 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 277why, one step back277 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 278why, one step back278 return flask.render_template("template_test.html", value=False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 279why, one step back279Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 280–281why, one step back280 rv = client.get("/")281 assert b"Success!" in rv.dataMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 282–284why, one step back282283284def test_template_test_with_name_and_template(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 285why, one step back285 @app.template_test("boolean")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 286–288why, one step back286 def is_boolean(value):287 return isinstance(value, bool)288Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 289why, one step back289 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 290why, one step back290 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 291why, one step back291 return flask.render_template("template_test.html", value=False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 292why, one step back292Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 293–294why, one step back293 rv = client.get("/")294 assert b"Success!" in rv.dataMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 295–300why, one step back295296297def test_add_template_test_with_name_and_template(app, client):298 def is_boolean(value):299 return isinstance(value, bool)300Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 301why, one step back301 app.add_template_test(is_boolean, "boolean")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 302why, one step back302Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 303why, one step back303 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 304why, one step back304 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 305why, one step back305 return flask.render_template("template_test.html", value=False)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 306why, one step back306Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 307–308why, one step back307 rv = client.get("/")308 assert b"Success!" in rv.dataMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 309–315why, one step back309310311def test_add_template_global(app, app_ctx):312 @app.template_global()313 def get_stuff():314 return 42315Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 316–318why, one step back316 assert "get_stuff" in app.jinja_env.globals.keys()317 assert app.jinja_env.globals["get_stuff"] == get_stuff318 assert app.jinja_env.globals["get_stuff"](), 42Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 319why, one step back319Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 320–321why, one step back320 rv = flask.render_template_string("{{ get_stuff() }}")321 assert rv == "42"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 322–328why, one step back322323324def test_custom_template_loader(client):325 class MyFlask(flask.Flask):326 def create_global_jinja_loader(self):327 from jinja2 import DictLoader328Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 329–330why, one step back329 return DictLoader({"index.html": "Hello Custom World!"})330Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 331–332why, one step back331 app = MyFlask(__name__)332Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 333why, one step back333 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 334why, one step back334 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 335why, one step back335 return flask.render_template("index.html")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 336–337why, one step back336337 c = app.test_client()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 338–339why, one step back338 rv = c.get("/")339 assert rv.data == b"Hello Custom World!"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 340–344why, one step back340341342def test_iterable_loader(app, client):343 @app.context_processor344 def context_processor():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 345why, one step back345 return {"whiskey": "Jameson"}Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 346why, one step back346Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 347why, one step back347 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 348–349why, one step back348 def index():349 return flask.render_template(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 350–356why, one step back350 [351 "no_template.xml", # should skip this one352 "simple_template.html", # should render this353 "context_template.html",354 ],355 value=23,356 )Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 357why, one step back357Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 358–359why, one step back358 rv = client.get("/")359 assert rv.data == b"<h1>Jameson</h1>"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 360–364why, one step back360361362def test_templates_auto_reload(app):363 # debug is False, config option is None364 assert app.debug is FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 365why, one step back365 assert app.config["TEMPLATES_AUTO_RELOAD"] is NoneMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 366–368why, one step back366 assert app.jinja_env.auto_reload is False367 # debug is False, config option is False368 app = flask.Flask(__name__)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 369why, one step back369 app.config["TEMPLATES_AUTO_RELOAD"] = FalseMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 370–373why, one step back370 assert app.debug is False371 assert app.jinja_env.auto_reload is False372 # debug is False, config option is True373 app = flask.Flask(__name__)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 374why, one step back374 app.config["TEMPLATES_AUTO_RELOAD"] = TrueMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 375–378why, one step back375 assert app.debug is False376 assert app.jinja_env.auto_reload is True377 # debug is True, config option is None378 app = flask.Flask(__name__)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 379–380why, one step back379 app.config["DEBUG"] = True380 assert app.config["TEMPLATES_AUTO_RELOAD"] is NoneMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 381–383why, one step back381 assert app.jinja_env.auto_reload is True382 # debug is True, config option is False383 app = flask.Flask(__name__)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 384–385why, one step back384 app.config["DEBUG"] = True385 app.config["TEMPLATES_AUTO_RELOAD"] = FalseMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 386–388why, one step back386 assert app.jinja_env.auto_reload is False387 # debug is True, config option is True388 app = flask.Flask(__name__)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 389–390why, one step back389 app.config["DEBUG"] = True390 app.config["TEMPLATES_AUTO_RELOAD"] = TrueMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 391–392why, one step back391 assert app.jinja_env.auto_reload is True392Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 393why, one step back393Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 394–397why, one step back394def test_templates_auto_reload_debug_run(app, monkeypatch):395 def run_simple_mock(*args, **kwargs):396 pass397Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 398why, one step back398 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 399–418why, one step back399400 app.run()401 assert app.templates_auto_reload == False402 assert app.jinja_env.auto_reload == False403404 app.run(debug=True)405 assert app.templates_auto_reload == True406 assert app.jinja_env.auto_reload == True407408409def test_template_loader_debugging(test_apps, monkeypatch):410 from blueprintapp import app411412 called = []413414 class _TestHandler(logging.Handler):415 def handle(x, record):416 called.append(True)417 text = str(record.msg)418 assert '1: trying loader of application "blueprintapp"' in textMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 419–429why, one step back419 assert (420 '2: trying loader of blueprint "admin" ' "(blueprintapp.apps.admin)"421 ) in text422 assert (423 'trying loader of blueprint "frontend" ' "(blueprintapp.apps.frontend)"424 ) in text425 assert "Error: the template could not be found" in text426 assert (427 "looked up from an endpoint that belongs to " 'the blueprint "frontend"'428 ) in text429 assert "See http://flask.pocoo.org/docs/blueprints/#templates" in textMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 430–431why, one step back430431 with app.test_client() as c:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 432–433why, one step back432 monkeypatch.setitem(app.config, "EXPLAIN_TEMPLATE_LOADING", True)433 monkeypatch.setattr(logging.getLogger("flask"), "handlers", [_TestHandler()])Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 434–435why, one step back434435 with pytest.raises(TemplateNotFound) as excinfo:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 436why, one step back436 c.get("/missing")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 437why, one step back437Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 438why, one step back438 assert "missing_template.html" in str(excinfo.value)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 439–451why, one step back439440 assert len(called) == 1441442443def test_custom_jinja_env():444 class CustomEnvironment(flask.templating.Environment):445 pass446447 class CustomFlask(flask.Flask):448 jinja_environment = CustomEnvironment449450 app = CustomFlask(__name__)451 assert isinstance(app.jinja_env, CustomEnvironment)