mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +03:00
Added test for nested serializer
This commit is contained in:
parent
b077c988c5
commit
d3a9259d4d
|
@ -51,6 +51,10 @@ class TestFieldMapping(TestCase):
|
|||
uuid1 = uuid.uuid4()
|
||||
uuid2 = uuid.uuid4()
|
||||
inspector = AutoSchema()
|
||||
|
||||
class NestedSerializer(serializers.Serializer):
|
||||
data = serializers.ListSerializer(child=serializers.FloatField())
|
||||
|
||||
cases = [
|
||||
(serializers.ListField(), {'items': {}, 'type': 'array'}),
|
||||
(serializers.ListField(child=serializers.BooleanField()), {'items': {'type': 'boolean'}, 'type': 'array'}),
|
||||
|
@ -73,13 +77,18 @@ class TestFieldMapping(TestCase):
|
|||
(serializers.ListField(child=serializers.ChoiceField(choices=[
|
||||
(1, 'One'), ('a', 'Choice A'), (1.1, 'First'), (1.1, 'First'), (1, 'One'), ('a', 'Choice A'), (1, 'One')
|
||||
])),
|
||||
{'items': {'enum': [1, 'a', 1.1]}, 'type': 'array'}),
|
||||
{'items': {'enum': [1, 'a', 1.1]}, 'type': 'array'}),
|
||||
(serializers.ListField(child=serializers.ChoiceField(choices=[
|
||||
(1, 'One'), (2, 'Two'), (3, 'Three'), (2, 'Two'), (3, 'Three'), (1, 'One'),
|
||||
])),
|
||||
{'items': {'enum': [1, 2, 3], 'type': 'integer'}, 'type': 'array'}),
|
||||
{'items': {'enum': [1, 2, 3], 'type': 'integer'}, 'type': 'array'}),
|
||||
(serializers.IntegerField(min_value=2147483648),
|
||||
{'type': 'integer', 'minimum': 2147483648, 'format': 'int64'}),
|
||||
(NestedSerializer(),
|
||||
{'properties': {'data': {'items': {'type': 'number'}, 'type': 'array'}},
|
||||
'required': ['data'],
|
||||
'type': 'object'}
|
||||
)
|
||||
]
|
||||
for field, mapping in cases:
|
||||
with self.subTest(field=field):
|
||||
|
@ -536,8 +545,8 @@ class TestOperationIntrospection(TestCase):
|
|||
'o2': reused_object,
|
||||
}
|
||||
assert (
|
||||
renderer.render(data) == b'o1:\n test: test\no2:\n test: test\n' or
|
||||
renderer.render(data) == b'o2:\n test: test\no1:\n test: test\n' # py <= 3.5
|
||||
renderer.render(data) == b'o1:\n test: test\no2:\n test: test\n' or
|
||||
renderer.render(data) == b'o2:\n test: test\no1:\n test: test\n' # py <= 3.5
|
||||
)
|
||||
|
||||
def test_serializer_filefield(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user