summaryrefslogtreecommitdiff
path: root/tests/utils_tests/test_html.py
diff options
context:
space:
mode:
authorHrushikesh Vaidya <hrushikeshrv@gmail.com>2022-06-23 14:20:20 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-28 10:54:38 +0200
commit72e41a0df6db23410135364223eeda83ac2a8b27 (patch)
tree4c173f6eae2977140cf30bb1f1c10ab9c623c044 /tests/utils_tests/test_html.py
parent0ee03a439b7016c068ab2e0c477d5c84f750a82c (diff)
Fixed #33779 -- Allowed customizing encoder class in django.utils.html.json_script().
Diffstat (limited to 'tests/utils_tests/test_html.py')
-rw-r--r--tests/utils_tests/test_html.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index 22a43fd4cd..b7a7396075 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -1,6 +1,7 @@
import os
from datetime import datetime
+from django.core.serializers.json import DjangoJSONEncoder
from django.test import SimpleTestCase
from django.utils.functional import lazystr
from django.utils.html import (
@@ -211,6 +212,16 @@ class TestUtilsHtml(SimpleTestCase):
with self.subTest(arg=arg):
self.assertEqual(json_script(arg, "test_id"), expected)
+ def test_json_script_custom_encoder(self):
+ class CustomDjangoJSONEncoder(DjangoJSONEncoder):
+ def encode(self, o):
+ return '{"hello": "world"}'
+
+ self.assertHTMLEqual(
+ json_script({}, encoder=CustomDjangoJSONEncoder),
+ '<script type="application/json">{"hello": "world"}</script>',
+ )
+
def test_json_script_without_id(self):
self.assertHTMLEqual(
json_script({"key": "value"}),