Added depth test

This commit is contained in:
George Kappel 2012-12-11 09:14:52 -06:00
parent 80adaecc43
commit 80f15c598a
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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)