From d3a9259d4d7a6d94adddd0822db185b91162f115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torstein=20A=2E=20B=C3=B8?= Date: Thu, 14 May 2020 08:04:28 +0200 Subject: [PATCH] Added test for nested serializer --- tests/schemas/test_openapi.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index 0e86a7f50..f39f98843 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -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):