django-rest-framework/tests/test_serializer_nested.py
2014-11-28 13:04:42 +00:00

41 lines
1.1 KiB
Python

from rest_framework import serializers
class TestNestedSerializer:
def setup(self):
class NestedSerializer(serializers.Serializer):
one = serializers.IntegerField(max_value=10)
two = serializers.IntegerField(max_value=10)
class TestSerializer(serializers.Serializer):
nested = NestedSerializer()
self.Serializer = TestSerializer
def test_nested_validate(self):
input_data = {
'nested': {
'one': '1',
'two': '2',
}
}
expected_data = {
'nested': {
'one': 1,
'two': 2,
}
}
serializer = self.Serializer(data=input_data)
assert serializer.is_valid()
assert serializer.validated_data == expected_data
def test_nested_serialize_empty(self):
expected_data = {
'nested': {
'one': None,
'two': None
}
}
serializer = self.Serializer()
assert serializer.data == expected_data