Add tests for rendering with dict ctor

This commit is contained in:
Matt Mayfield 2023-05-17 21:57:07 -04:00
parent 005407c87f
commit 72f70c7410
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1 @@
{{ greeting }}{{ name }}

View file

@ -39,6 +39,41 @@ def test_simple_stream(app, client):
assert rv.data == b"42" assert rv.data == b"42"
@pytest.mark.parametrize(
"render_func, template_arg",
[
(flask.render_template, "multi_vars.html"),
(flask.render_template_string, "{{ greeting }}{{ name }}"),
(flask.stream_template, "multi_vars.html"),
(flask.stream_template_string, "{{ greeting }}{{ name }}"),
],
)
@pytest.mark.parametrize(
"context",
[
{"greeting": "Hello"},
[("greeting", "Hello")],
(("greeting", "Hello"),),
],
)
class TestRenderDictCtor:
def test_with_kargs(self, app, client, render_func, template_arg, context):
@app.route("/")
def index():
return render_func(template_arg, context, name="World")
rv = client.get("/")
assert rv.data == b"HelloWorld"
def test_no_kargs(self, app, client, render_func, template_arg, context):
@app.route("/")
def index():
return render_func(template_arg, context)
rv = client.get("/")
assert rv.data == b"Hello"
def test_request_less_rendering(app, app_ctx): def test_request_less_rendering(app, app_ctx):
app.config["WORLD_NAME"] = "Special World" app.config["WORLD_NAME"] = "Special World"