From 208bd991dacb6c2edc9fc820717354c579c2e6d6 Mon Sep 17 00:00:00 2001 From: Craig de Stigter Date: Sat, 18 May 2013 15:23:43 +0200 Subject: when source='*' on a nested serializer, expand fields into outer serializer when writing. fixes #765 --- rest_framework/tests/serializer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'rest_framework/tests/serializer.py') diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py index 34acbaab..116459e0 100644 --- a/rest_framework/tests/serializer.py +++ b/rest_framework/tests/serializer.py @@ -78,6 +78,17 @@ class PersonSerializer(serializers.ModelSerializer): read_only_fields = ('age',) +class NestedSerializer(serializers.Serializer): + info = serializers.Field() + + +class ModelSerializerWithNestedSerializer(serializers.ModelSerializer): + nested = NestedSerializer(source='*') + + class Meta: + model = Person + + class PersonSerializerInvalidReadOnly(serializers.ModelSerializer): """ Testing for #652. @@ -369,6 +380,17 @@ class ValidationTests(TestCase): except: self.fail('Wrong exception type thrown.') + def test_writable_star_source_on_nested_serializer(self): + """ + Assert that a nested serializer instantiated with source='*' correctly + expands the data into the outer serializer. + """ + serializer = ModelSerializerWithNestedSerializer(data={ + 'name': 'marko', + 'nested': {'info': 'hi'}}, + ) + self.assertEqual(serializer.is_valid(), True) + class CustomValidationTests(TestCase): class CommentSerializerWithFieldValidator(CommentSerializer): -- cgit v1.2.3