mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
Added test writable star source
Uses nested serializer with parent object
This commit is contained in:
parent
abe14c06f7
commit
19c03f4a60
|
@ -508,6 +508,32 @@ class ValidationTests(TestCase):
|
|||
)
|
||||
self.assertEqual(serializer.is_valid(), True)
|
||||
|
||||
def test_writable_star_source_on_nested_serializer_with_parent_object(self):
|
||||
class Serializer(serializers.Serializer):
|
||||
title = serializers.WritableField(source='title')
|
||||
|
||||
class AlbumSerializer(serializers.ModelSerializer):
|
||||
nested = Serializer(source='*')
|
||||
|
||||
class Meta:
|
||||
model = Album
|
||||
fields = ('nested',)
|
||||
|
||||
class PhotoSerializer(serializers.ModelSerializer):
|
||||
album = AlbumSerializer(source='album')
|
||||
|
||||
class Meta:
|
||||
model = Photo
|
||||
fields = ('album', )
|
||||
|
||||
photo = Photo(album=Album())
|
||||
|
||||
data = {'album': {'nested': {'title': 'test'}}}
|
||||
|
||||
serializer = PhotoSerializer(photo, data=data)
|
||||
self.assertEqual(serializer.is_valid(), True)
|
||||
self.assertEqual(serializer.data, data)
|
||||
|
||||
def test_writable_star_source_with_inner_source_fields(self):
|
||||
"""
|
||||
Tests that a serializer with source="*" correctly expands the
|
||||
|
|
Loading…
Reference in New Issue
Block a user