aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests
diff options
context:
space:
mode:
authorTom Christie2013-05-18 09:05:42 -0700
committerTom Christie2013-05-18 09:05:42 -0700
commit1888f4a1f01c03384fd401ee90002d1cda955425 (patch)
tree544f96cbee9d1e31fe70e02e42fadbc5e8055056 /rest_framework/tests
parent6d5cf527c32402436b8300324715779c41f50fd7 (diff)
parent579f77ceaa03a216a7a635c3d3a4d83b0e5868f8 (diff)
downloaddjango-rest-framework-1888f4a1f01c03384fd401ee90002d1cda955425.tar.bz2
Merge pull request #865 from ryankask/issue-747-lazy-strings-serialized
Issue 747 lazy strings serialized
Diffstat (limited to 'rest_framework/tests')
-rw-r--r--rest_framework/tests/serializer.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py
index 220a581a..fd6cf6da 100644
--- a/rest_framework/tests/serializer.py
+++ b/rest_framework/tests/serializer.py
@@ -1,8 +1,9 @@
from __future__ import unicode_literals
from django.db import models
from django.db.models.fields import BLANK_CHOICE_DASH
-from django.utils.datastructures import MultiValueDict
from django.test import TestCase
+from django.utils.datastructures import MultiValueDict
+from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
BlankFieldModel, BlogPost, BlogPostComment, Book, CallableDefaultValueModel, DefaultValueModel,
@@ -1323,6 +1324,34 @@ class DeserializeListTestCase(TestCase):
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 LazyStringModel(**attrs)
+
+
+class LazyStringsTestCase(TestCase):
+ def setUp(self):
+ self.model = LazyStringModel(lazystring=_('lazystring'))
+
+ def test_lazy_strings_are_translated(self):
+ serializer = LazyStringSerializer(self.model)
+ self.assertEqual(type(serializer.data['lazystring']),
+ type('lazystring'))
+
+
class AttributeMappingOnAutogeneratedFieldsTests(TestCase):
def setUp(self):