Commit 0081d744 by Matteo Suppo

Added tests for issue 747 in serializer.py

parent 9fdb661c
......@@ -1082,3 +1082,32 @@ class DeserializeListTestCase(TestCase):
self.assertFalse(serializer.is_valid())
expected = [{}, {'email': ['This field is required.']}, {}]
self.assertEqual(serializer.errors, expected)
# test for issue 747
class LazyStringModel(object):
def __init__(self, lazystring):
self.lazystring = lazystring
class LazyStringSerializer(serializers.Serializer):
lazystring = serializers.Field()
def restore_object(self, attrs, instance=None):
if instance is not None:
instance.lazystring = attrs.get('lazystring', instance.lazystring)
return instance
return Comment(**attrs)
class LazyStringsTestCase(TestCase):
def setUp(self):
from django.utils.translation import ugettext_lazy as _
self.model = LazyStringModel(lazystring=_("lazystring"))
def test_lazy_strings_are_translated(self):
serializer = LazyStringSerializer(self.model)
self.assertEqual(type(serializer.data['lazystring']), type("lazystring"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment