aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_filters.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_filters.py b/tests/test_filters.py
index ba57136d..1a8a1640 100644
--- a/tests/test_filters.py
+++ b/tests/test_filters.py
@@ -576,3 +576,16 @@ class TestFilter(object):
tmpl = env.from_string('{{ users|rejectattr("id", "odd")|'
'map(attribute="name")|join("|") }}')
assert tmpl.render(users=users) == 'jane'
+
+ def test_json_dump(self):
+ env = Environment(autoescape=True)
+ t = env.from_string('{{ x|tojson }}')
+ assert t.render(x={'foo': 'bar'}) == '{"foo": "bar"}'
+ assert t.render(x='"bar\'') == '"\"bar\u0027"'
+
+ def my_dumps(value, **options):
+ assert options == {'foo': 'bar'}
+ return '42'
+ env.policies['json.dumps_function'] = my_dumps
+ env.policies['json.dumps_kwargs'] = {'foo': 'bar'}
+ assert t.render(x=23) == '42'