mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
Added depth test
This commit is contained in:
parent
80adaecc43
commit
80f15c598a
|
@ -5,6 +5,11 @@
|
|||
# http://code.djangoproject.com/svn/django/trunk/tests/runtests.py
|
||||
import os
|
||||
import sys
|
||||
"""
|
||||
Need to fix sys path so following works without specifically messing with PYTHONPATH
|
||||
python ./rest_framework/runtests/runtests.py
|
||||
"""
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'rest_framework.runtests.settings'
|
||||
|
||||
from django.conf import settings
|
||||
|
|
|
@ -726,3 +726,24 @@ class SerializerPickleTests(TestCase):
|
|||
model = Person
|
||||
fields = ('name', 'age')
|
||||
pickle.dumps(InnerPersonSerializer(Person(name="Noah", age=950)).data)
|
||||
|
||||
class DepthTest(TestCase):
|
||||
def test_depth(self):
|
||||
user = Person.objects.create(name="django",age=1)
|
||||
post = BlogPost.objects.create(title="Test blog post", writer=user)
|
||||
|
||||
class PersonSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Person
|
||||
fields = ("name", "age")
|
||||
|
||||
class BlogPostSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = BlogPost
|
||||
depth = 1
|
||||
|
||||
serializer = BlogPostSerializer(instance=post)
|
||||
expected = {'id': 1, 'title': u'Test blog post',
|
||||
'writer': {'id': 1, 'name': u'django', 'age':1}}
|
||||
|
||||
self.assertEqual(serializer.data, expected)
|
||||
|
|
Loading…
Reference in New Issue
Block a user