From 0081d744b9f530b2418d1e82d7ad94a2ebc31c9c Mon Sep 17 00:00:00 2001
From: Matteo Suppo <matteo.suppo@gmail.com>
Date: Sat, 23 Mar 2013 14:18:11 +0100
Subject: [PATCH] Added tests for issue 747 in serializer.py

---
 rest_framework/tests/serializer.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py
index 05217f35a..0386ca76e 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"))