Skip to content
Myr

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 file

Take 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 back
1# -*- coding: utf-8 -*-
2"""3 tests.templating4 ~~~~~~~~~~~~~~~~56 Template functionality7

Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c

line 8why, one step back
8 :copyright: © 2010 by the Pallets team.

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 9–22why, one step back
9 :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 back
23 return {"injected_value": 42}

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 24why, one step back
24

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 27why, one step back
27 return flask.render_template("context_template.html", value=23)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 28why, one step back
28

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

lines 29–30why, one step back
29 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 back
31
3233def test_original_win(app, client):

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 36why, one step back
36 return flask.render_template_string("{{ config }}", config=42)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 37why, one step back
37

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

lines 38–39why, one step back
38 rv = client.get("/")
39 assert rv.data == b"42"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 40–42why, one step back
40
4142def test_request_less_rendering(app, app_ctx):

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

line 43why, one step back
43 app.config["WORLD_NAME"] = "Special World"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 44–48why, one step back
44
45 @app.context_processor46 def context_processor():47 return dict(foo=42)48

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

lines 49–50why, one step back
49 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 back
51
5253def test_standard_context(app, client):

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 55–56why, one step back
55 def index():
56 flask.g.foo = 23

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

lines 57–59why, one step back
57 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 back
60 {{ 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 back
64 """
65 )

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 66why, one step back
66

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

lines 67–68why, one step back
67 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 back
69
7071def test_escaping(app, client):

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

line 72why, one step back
72 text = "<p>Hello World!"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 73why, one step back
73

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

lines 76–78why, one step back
76 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 back
79

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

line 80why, one step back
80 lines = client.get("/").data.splitlines()

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 81why, one step back
81 assert lines == [

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

lines 82–87why, one step back
82 b"&lt;p&gt;Hello World!",
83 b"<p>Hello World!",84 b"<p>Hello World!",85 b"<p>Hello World!",86 b"&lt;p&gt;Hello World!",87 b"<p>Hello World!",

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 88–91why, one step back
88 ]
899091def test_no_escaping(app, client):

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

line 92why, one step back
92 text = "<p>Hello World!"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 93why, one step back
93

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

lines 96–98why, one step back
96 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 back
99

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

line 100why, one step back
100 lines = client.get("/").data.splitlines()

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 101why, one step back
101 assert lines == [

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

lines 102–109why, one step back
102 b"<p>Hello World!",
103 b"<p>Hello World!",104 b"<p>Hello World!",105 b"<p>Hello World!",106 b"&lt;p&gt;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 back
110 ]
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 back
114 assert flask.render_template_string("{{ foo }}", foo="<test>") == "&lt;test&gt;"
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 back
116
117118def test_macros(app, req_ctx):

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

lines 119–120why, one step back
119 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 back
121
122123def test_template_filter(app):124 @app.template_filter()125 def my_reverse(s):126 return s[::-1]127

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

lines 128–130why, one step back
128 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 back
131
132133def 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 back
138 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 back
141
142143def test_template_filter_with_name(app):

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

line 144why, one step back
144 @app.template_filter("strrev")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 145–147why, one step back
145 def my_reverse(s):
146 return s[::-1]147

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

lines 148–150why, one step back
148 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 back
151
152153def test_add_template_filter_with_name(app):154 def my_reverse(s):155 return s[::-1]156

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

lines 157–160why, one step back
157 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 back
161
162163def test_template_filter_with_template(app, client):164 @app.template_filter()165 def super_reverse(s):166 return s[::-1]167

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 170why, one step back
170 return flask.render_template("template_filter.html", value="abcd")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 171why, one step back
171

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

lines 172–173why, one step back
172 rv = client.get("/")
173 assert rv.data == b"dcba"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 174–181why, one step back
174
175176def test_add_template_filter_with_template(app, client):177 def super_reverse(s):178 return s[::-1]179180 app.add_template_filter(super_reverse)181

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 184why, one step back
184 return flask.render_template("template_filter.html", value="abcd")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 185why, one step back
185

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 188–190why, one step back
188
189190def test_template_filter_with_name_and_template(app, client):

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

line 191why, one step back
191 @app.template_filter("super_reverse")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 192–194why, one step back
192 def my_reverse(s):
193 return s[::-1]194

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 197why, one step back
197 return flask.render_template("template_filter.html", value="abcd")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 198why, one step back
198

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

lines 199–200why, one step back
199 rv = client.get("/")
200 assert rv.data == b"dcba"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 201–206why, one step back
201
202203def test_add_template_filter_with_name_and_template(app, client):204 def my_reverse(s):205 return s[::-1]206

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

line 207why, one step back
207 app.add_template_filter(my_reverse, "super_reverse")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 208why, one step back
208

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 211why, one step back
211 return flask.render_template("template_filter.html", value="abcd")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 212why, one step back
212

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

lines 213–214why, one step back
213 rv = client.get("/")
214 assert rv.data == b"dcba"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 215–221why, one step back
215
216217def test_template_test(app):218 @app.template_test()219 def boolean(value):220 return isinstance(value, bool)221

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

lines 222–224why, one step back
222 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 back
225
226227def 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 back
232 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 back
235
236237def test_template_test_with_name(app):

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

line 238why, one step back
238 @app.template_test("boolean")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 239–241why, one step back
239 def is_boolean(value):
240 return isinstance(value, bool)241

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

lines 242–244why, one step back
242 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 back
245
246247def test_add_template_test_with_name(app):248 def is_boolean(value):249 return isinstance(value, bool)250

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

lines 251–254why, one step back
251 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 back
255
256257def test_template_test_with_template(app, client):258 @app.template_test()259 def boolean(value):260 return isinstance(value, bool)261

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 264why, one step back
264 return flask.render_template("template_test.html", value=False)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 265why, one step back
265

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

lines 266–267why, one step back
266 rv = client.get("/")
267 assert b"Success!" in rv.data

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 268–275why, one step back
268
269270def test_add_template_test_with_template(app, client):271 def boolean(value):272 return isinstance(value, bool)273274 app.add_template_test(boolean)275

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 278why, one step back
278 return flask.render_template("template_test.html", value=False)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 279why, one step back
279

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

lines 280–281why, one step back
280 rv = client.get("/")
281 assert b"Success!" in rv.data

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 282–284why, one step back
282
283284def test_template_test_with_name_and_template(app, client):

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

line 285why, one step back
285 @app.template_test("boolean")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 286–288why, one step back
286 def is_boolean(value):
287 return isinstance(value, bool)288

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 291why, one step back
291 return flask.render_template("template_test.html", value=False)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 292why, one step back
292

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

lines 293–294why, one step back
293 rv = client.get("/")
294 assert b"Success!" in rv.data

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 295–300why, one step back
295
296297def test_add_template_test_with_name_and_template(app, client):298 def is_boolean(value):299 return isinstance(value, bool)300

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

line 301why, one step back
301 app.add_template_test(is_boolean, "boolean")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 302why, one step back
302

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 305why, one step back
305 return flask.render_template("template_test.html", value=False)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 306why, one step back
306

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

lines 307–308why, one step back
307 rv = client.get("/")
308 assert b"Success!" in rv.data

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 309–315why, one step back
309
310311def test_add_template_global(app, app_ctx):312 @app.template_global()313 def get_stuff():314 return 42315

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

lines 316–318why, one step back
316 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"](), 42

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 319why, one step back
319

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

lines 320–321why, one step back
320 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 back
322
323324def test_custom_template_loader(client):325 class MyFlask(flask.Flask):326 def create_global_jinja_loader(self):327 from jinja2 import DictLoader328

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

lines 329–330why, one step back
329 return DictLoader({"index.html": "Hello Custom World!"})
330

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 331–332why, one step back
331 app = MyFlask(__name__)
332

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

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

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

line 335why, one step back
335 return flask.render_template("index.html")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 336–337why, one step back
336
337 c = app.test_client()

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

lines 338–339why, one step back
338 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 back
340
341342def 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 back
345 return {"whiskey": "Jameson"}

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 346why, one step back
346

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

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 348–349why, one step back
348 def index():
349 return flask.render_template(

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

lines 350–356why, one step back
350 [
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 back
357

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

lines 358–359why, one step back
358 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 back
360
361362def test_templates_auto_reload(app):363 # debug is False, config option is None364 assert app.debug is False

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

line 365why, one step back
365 assert app.config["TEMPLATES_AUTO_RELOAD"] is None

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 366–368why, one step back
366 assert app.jinja_env.auto_reload is False
367 # 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 back
369 app.config["TEMPLATES_AUTO_RELOAD"] = False

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 370–373why, one step back
370 assert app.debug is False
371 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 back
374 app.config["TEMPLATES_AUTO_RELOAD"] = True

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 375–378why, one step back
375 assert app.debug is False
376 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 back
379 app.config["DEBUG"] = True
380 assert app.config["TEMPLATES_AUTO_RELOAD"] is None

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 381–383why, one step back
381 assert app.jinja_env.auto_reload is True
382 # 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 back
384 app.config["DEBUG"] = True
385 app.config["TEMPLATES_AUTO_RELOAD"] = False

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 386–388why, one step back
386 assert app.jinja_env.auto_reload is False
387 # 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 back
389 app.config["DEBUG"] = True
390 app.config["TEMPLATES_AUTO_RELOAD"] = True

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 391–392why, one step back
391 assert app.jinja_env.auto_reload is True
392

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

line 393why, one step back
393

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 394–397why, one step back
394def test_templates_auto_reload_debug_run(app, monkeypatch):
395 def run_simple_mock(*args, **kwargs):396 pass397

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

line 398why, one step back
398 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 399–418why, one step back
399
400 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 text

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

lines 419–429why, one step back
419 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 text

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 430–431why, one step back
430
431 with app.test_client() as c:

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

lines 432–433why, one step back
432 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 back
434
435 with pytest.raises(TemplateNotFound) as excinfo:

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

line 436why, one step back
436 c.get("/missing")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 437why, one step back
437

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

line 438why, one step back
438 assert "missing_template.html" in str(excinfo.value)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 439–451why, one step back
439
440 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)