aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests/serializer.py
diff options
context:
space:
mode:
authorMatteo Suppo2013-03-23 14:18:11 +0100
committerMatteo Suppo2013-03-23 14:18:11 +0100
commit0081d744b9f530b2418d1e82d7ad94a2ebc31c9c (patch)
tree8becd0fec6b13186d1c6a395052a157233a66e37 /rest_framework/tests/serializer.py
parent9fdb661c593a3c042d7aa2cd4608ae5b81f8109c (diff)
downloaddjango-rest-framework-0081d744b9f530b2418d1e82d7ad94a2ebc31c9c.tar.bz2
Added tests for issue 747 in serializer.py
Diffstat (limited to 'rest_framework/tests/serializer.py')
-rw-r--r--rest_framework/tests/serializer.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py
index 05217f35..0386ca76 100644
--- a/rest_framework/tests/serializer.py
+++ b/rest_framework/tests/serializer.py
@@ -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"))