mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-25 23:50:01 +03:00
Test case
This commit is contained in:
parent
e25cea43a9
commit
b04fd3d050
|
@ -613,7 +613,6 @@ class CallableDefaultValueTests(TestCase):
|
|||
self.assertEquals(instance.pk, 1)
|
||||
self.assertEquals(instance.text, 'overridden')
|
||||
|
||||
|
||||
class ManyRelatedTests(TestCase):
|
||||
def test_reverse_relations(self):
|
||||
post = BlogPost.objects.create(title="Test blog post")
|
||||
|
@ -638,6 +637,30 @@ class ManyRelatedTests(TestCase):
|
|||
|
||||
self.assertEqual(serializer.data, expected)
|
||||
|
||||
def test_include_reverse_relations(self):
|
||||
post = BlogPost.objects.create(title="Test blog post")
|
||||
post.blogpostcomment_set.create(text="I hate this blog post")
|
||||
post.blogpostcomment_set.create(text="I love this blog post")
|
||||
|
||||
class BlogPostCommentSerializer(serializers.Serializer):
|
||||
text = serializers.CharField()
|
||||
|
||||
class BlogPostSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = BlogPost
|
||||
include_reverse_relations = True
|
||||
depth = 1
|
||||
|
||||
serializer = BlogPostSerializer(instance=post)
|
||||
expected = {
|
||||
'id': 1, 'title': u'Test blog post', 'writer': None,
|
||||
'blogpostcomment_set': [
|
||||
{'id': 1, 'text': u'I hate this blog post', 'blog_post': 1},
|
||||
{'id': 2, 'text': u'I love this blog post', 'blog_post': 1}
|
||||
]
|
||||
}
|
||||
self.assertEqual(serializer.data, expected)
|
||||
|
||||
def test_callable_source(self):
|
||||
post = BlogPost.objects.create(title="Test blog post")
|
||||
post.blogpostcomment_set.create(text="I love this blog post")
|
||||
|
@ -901,3 +924,4 @@ class NestedSerializerContextTests(TestCase):
|
|||
|
||||
# This will raise RuntimeError if context doesn't get passed correctly to the nested Serializers
|
||||
AlbumCollectionSerializer(album_collection, context={'context_item': 'album context'}).data
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user