Skip to content

Commit

Permalink
Add failing test for issue encode#4073
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcreid committed Apr 27, 2016
1 parent 4f16c54 commit 91e215a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_serializer_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,30 @@ def test_empty_not_allowed_if_allow_empty_is_set_to_false(self):

expected_errors = {'not_allow_empty': {'non_field_errors': [serializers.ListSerializer.default_error_messages['empty']]}}
assert serializer.errors == expected_errors


class TestNestedSerializerWithParentValidation:
def setup(self):
class NestedSerializer(serializers.Serializer):
one = serializers.IntegerField()

class TestSerializer(serializers.Serializer):
nested = NestedSerializer()

def validate_nested(self, value):
raise serializers.ValidationError(
u'Error from parent serializer.')

self.Serializer = TestSerializer

def test_using_serializer_as_form_with_parent_validation(self):
input_data = {'nested': {'one': 1}}

serializer = self.Serializer(data=input_data)

assert not serializer.is_valid()
assert 'nested' in serializer.errors

nested_bound_field = serializer['nested']
# This should not raise an exception:
one_bound_field = nested_bound_field['one']

0 comments on commit 91e215a

Please sign in to comment.