1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #25468 -- Made DjangoJSONEncoder lazy string aware

Thanks Stavros Korokithakis for the report and Tim Graham for the
review.
This commit is contained in:
Claude Paroz
2015-09-26 20:15:26 +02:00
parent 87630bc304
commit b7ade64529
4 changed files with 28 additions and 5 deletions

View File

@@ -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"}'
)