mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Test for issue #178.
This failing test shows that the serializer implementation breaks when a related serializer is passed in via include rather than via fields.
This commit is contained in:
parent
7183815235
commit
98c16e6da8
|
@ -104,6 +104,27 @@ class TestFieldNesting(TestCase):
|
|||
self.assertEqual(SerializerM2().serialize(self.m2), {'field': {'field1': u'foo'}})
|
||||
self.assertEqual(SerializerM3().serialize(self.m3), {'field': {'field2': u'bar'}})
|
||||
|
||||
def test_serializer_no_fields(self):
|
||||
"""
|
||||
Test related serializer works when the fields attr isn't present. Fix for
|
||||
#178.
|
||||
"""
|
||||
class NestedM2(Serializer):
|
||||
fields = ('field1', )
|
||||
|
||||
class NestedM3(Serializer):
|
||||
fields = ('field2', )
|
||||
|
||||
class SerializerM2(Serializer):
|
||||
include = [('field', NestedM2)]
|
||||
exclude = ('id', )
|
||||
|
||||
class SerializerM3(Serializer):
|
||||
fields = [('field', NestedM3)]
|
||||
|
||||
self.assertEqual(SerializerM2().serialize(self.m2), {'field': {'field1': u'foo'}})
|
||||
self.assertEqual(SerializerM3().serialize(self.m3), {'field': {'field2': u'bar'}})
|
||||
|
||||
def test_serializer_classname_nesting(self):
|
||||
"""
|
||||
Test related model serialization
|
||||
|
|
Loading…
Reference in New Issue
Block a user