From b7ade645290ecf45530fe7211f8f759fc9cf9971 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 26 Sep 2015 20:15:26 +0200 Subject: Fixed #25468 -- Made DjangoJSONEncoder lazy string aware Thanks Stavros Korokithakis for the report and Tim Graham for the review. --- tests/serializers/test_json.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py index 4239dcef8d..d8d445d1f9 100644 --- a/tests/serializers/test_json.py +++ b/tests/serializers/test_json.py @@ -6,7 +6,9 @@ import re from django.core import serializers from django.core.serializers.base import DeserializationError -from django.test import TestCase, TransactionTestCase +from django.core.serializers.json import DjangoJSONEncoder +from django.test import SimpleTestCase, TestCase, TransactionTestCase +from django.utils.translation import override, ugettext_lazy from .models import Score from .tests import SerializersTestBase, SerializersTransactionTestBase @@ -271,3 +273,16 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact "name": "Agnes" } }]""" + + +class DjangoJSONEncoderTests(SimpleTestCase): + def test_lazy_string_encoding(self): + self.assertEqual( + json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder), + '{"lang": "French"}' + ) + with override('fr'): + self.assertEqual( + json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder), + '{"lang": "Fran\\u00e7ais"}' + ) -- cgit v1.3