mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Added test that makes sure that fields with
dictionaries as data are returned as expected and not turned into string representations
This commit is contained in:
parent
19a218f859
commit
1b49615c00
|
@ -122,6 +122,13 @@ class Person(RESTFrameworkModel):
|
|||
name = models.CharField(max_length=10)
|
||||
age = models.IntegerField(null=True, blank=True)
|
||||
|
||||
@property
|
||||
def info(self):
|
||||
return {
|
||||
'name': self.name,
|
||||
'age': self.age,
|
||||
}
|
||||
|
||||
|
||||
# Model for issue #324
|
||||
class BlankFieldModel(RESTFrameworkModel):
|
||||
|
|
|
@ -46,8 +46,11 @@ class ActionItemSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class PersonSerializer(serializers.ModelSerializer):
|
||||
info = serializers.Field(source='info')
|
||||
|
||||
class Meta:
|
||||
model = Person
|
||||
fields = ('name', 'age', 'info')
|
||||
|
||||
|
||||
class BasicTests(TestCase):
|
||||
|
@ -69,6 +72,9 @@ class BasicTests(TestCase):
|
|||
'created': datetime.datetime(2012, 1, 1),
|
||||
'sub_comment': 'And Merry Christmas!'
|
||||
}
|
||||
self.person_data = {'name': 'dwight', 'age': 35}
|
||||
self.person = Person(**self.person_data)
|
||||
self.person.save()
|
||||
|
||||
def test_empty(self):
|
||||
serializer = CommentSerializer()
|
||||
|
@ -100,6 +106,13 @@ class BasicTests(TestCase):
|
|||
self.assertTrue(serializer.object is expected)
|
||||
self.assertEquals(serializer.data['sub_comment'], 'And Merry Christmas!')
|
||||
|
||||
def test_field_with_dictionary(self):
|
||||
""" Make sure that dictionaries from fields are left intact
|
||||
"""
|
||||
serializer = PersonSerializer(instance=self.person)
|
||||
expected = self.person_data
|
||||
self.assertEquals(serializer.data['info'], expected)
|
||||
|
||||
|
||||
class ValidationTests(TestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user