mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Changed DepthTest to have depth=2
This commit is contained in:
parent
33a26a76f1
commit
3b0fa3ebaa
|
@ -3,7 +3,7 @@ from django.utils.datastructures import MultiValueDict
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
||||||
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
BlankFieldModel, BlogPost, BlogPostComment, Book, CallableDefaultValueModel, DefaultValueModel,
|
||||||
ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
|
ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
|
||||||
import datetime
|
import datetime
|
||||||
import pickle
|
import pickle
|
||||||
|
@ -767,8 +767,6 @@ class RelatedTraversalTest(TestCase):
|
||||||
post = BlogPost.objects.create(title="Test blog post", writer=user)
|
post = BlogPost.objects.create(title="Test blog post", writer=user)
|
||||||
post.blogpostcomment_set.create(text="I love this blog post")
|
post.blogpostcomment_set.create(text="I love this blog post")
|
||||||
|
|
||||||
from rest_framework.tests.models import BlogPostComment
|
|
||||||
|
|
||||||
class PersonSerializer(serializers.ModelSerializer):
|
class PersonSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Person
|
model = Person
|
||||||
|
@ -968,23 +966,26 @@ class SerializerPickleTests(TestCase):
|
||||||
|
|
||||||
class DepthTest(TestCase):
|
class DepthTest(TestCase):
|
||||||
def test_implicit_nesting(self):
|
def test_implicit_nesting(self):
|
||||||
|
|
||||||
writer = Person.objects.create(name="django", age=1)
|
writer = Person.objects.create(name="django", age=1)
|
||||||
post = BlogPost.objects.create(title="Test blog post", writer=writer)
|
post = BlogPost.objects.create(title="Test blog post", writer=writer)
|
||||||
|
comment = BlogPostComment.objects.create(text="Test blog post comment", blog_post=post)
|
||||||
|
|
||||||
class BlogPostSerializer(serializers.ModelSerializer):
|
class BlogPostCommentSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = BlogPost
|
model = BlogPostComment
|
||||||
depth = 1
|
depth = 2
|
||||||
|
|
||||||
serializer = BlogPostSerializer(instance=post)
|
serializer = BlogPostCommentSerializer(instance=comment)
|
||||||
expected = {'id': 1, 'title': 'Test blog post',
|
expected = {'id': 1, 'text': 'Test blog post comment', 'blog_post': {'id': 1, 'title': 'Test blog post',
|
||||||
'writer': {'id': 1, 'name': 'django', 'age': 1}}
|
'writer': {'id': 1, 'name': 'django', 'age': 1}}}
|
||||||
|
|
||||||
self.assertEqual(serializer.data, expected)
|
self.assertEqual(serializer.data, expected)
|
||||||
|
|
||||||
def test_explicit_nesting(self):
|
def test_explicit_nesting(self):
|
||||||
writer = Person.objects.create(name="django", age=1)
|
writer = Person.objects.create(name="django", age=1)
|
||||||
post = BlogPost.objects.create(title="Test blog post", writer=writer)
|
post = BlogPost.objects.create(title="Test blog post", writer=writer)
|
||||||
|
comment = BlogPostComment.objects.create(text="Test blog post comment", blog_post=post)
|
||||||
|
|
||||||
class PersonSerializer(serializers.ModelSerializer):
|
class PersonSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -996,9 +997,15 @@ class DepthTest(TestCase):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = BlogPost
|
model = BlogPost
|
||||||
|
|
||||||
serializer = BlogPostSerializer(instance=post)
|
class BlogPostCommentSerializer(serializers.ModelSerializer):
|
||||||
expected = {'id': 1, 'title': 'Test blog post',
|
blog_post = BlogPostSerializer()
|
||||||
'writer': {'id': 1, 'name': 'django', 'age': 1}}
|
|
||||||
|
class Meta:
|
||||||
|
model = BlogPostComment
|
||||||
|
|
||||||
|
serializer = BlogPostCommentSerializer(instance=comment)
|
||||||
|
expected = {'id': 1, 'text': 'Test blog post comment', 'blog_post': {'id': 1, 'title': 'Test blog post',
|
||||||
|
'writer': {'id': 1, 'name': 'django', 'age': 1}}}
|
||||||
|
|
||||||
self.assertEqual(serializer.data, expected)
|
self.assertEqual(serializer.data, expected)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user