1+ import uuid
2+
13import pytest
24from django .conf .urls import url
35from django .test import RequestFactory , TestCase , override_settings
@@ -44,6 +46,8 @@ def test_pagination(self):
4446
4547class TestFieldMapping (TestCase ):
4648 def test_list_field_mapping (self ):
49+ uuid1 = uuid .uuid4 ()
50+ uuid2 = uuid .uuid4 ()
4751 inspector = AutoSchema ()
4852 cases = [
4953 (serializers .ListField (), {'items' : {}, 'type' : 'array' }),
@@ -53,7 +57,25 @@ def test_list_field_mapping(self):
5357 (serializers .ListField (child = serializers .IntegerField (max_value = 4294967295 )),
5458 {'items' : {'type' : 'integer' , 'maximum' : 4294967295 , 'format' : 'int64' }, 'type' : 'array' }),
5559 (serializers .ListField (child = serializers .ChoiceField (choices = [('a' , 'Choice A' ), ('b' , 'Choice B' )])),
56- {'items' : {'enum' : ['a' , 'b' ]}, 'type' : 'array' }),
60+ {'items' : {'enum' : ['a' , 'b' ], 'type' : 'string' }, 'type' : 'array' }),
61+ (serializers .ListField (child = serializers .ChoiceField (choices = [(1 , 'One' ), (2 , 'Two' )])),
62+ {'items' : {'enum' : [1 , 2 ], 'type' : 'integer' }, 'type' : 'array' }),
63+ (serializers .ListField (child = serializers .ChoiceField (choices = [(1.1 , 'First' ), (2.2 , 'Second' )])),
64+ {'items' : {'enum' : [1.1 , 2.2 ], 'type' : 'number' }, 'type' : 'array' }),
65+ (serializers .ListField (child = serializers .ChoiceField (choices = [(True , 'true' ), (False , 'false' )])),
66+ {'items' : {'enum' : [True , False ], 'type' : 'boolean' }, 'type' : 'array' }),
67+ (serializers .ListField (child = serializers .ChoiceField (choices = [(uuid1 , 'uuid1' ), (uuid2 , 'uuid2' )])),
68+ {'items' : {'enum' : [uuid1 , uuid2 ]}, 'type' : 'array' }),
69+ (serializers .ListField (child = serializers .ChoiceField (choices = [(1 , 'One' ), ('a' , 'Choice A' )])),
70+ {'items' : {'enum' : [1 , 'a' ]}, 'type' : 'array' }),
71+ (serializers .ListField (child = serializers .ChoiceField (choices = [
72+ (1 , 'One' ), ('a' , 'Choice A' ), (1.1 , 'First' ), (1.1 , 'First' ), (1 , 'One' ), ('a' , 'Choice A' ), (1 , 'One' )
73+ ])),
74+ {'items' : {'enum' : [1 , 'a' , 1.1 ]}, 'type' : 'array' }),
75+ (serializers .ListField (child = serializers .ChoiceField (choices = [
76+ (1 , 'One' ), (2 , 'Two' ), (3 , 'Three' ), (2 , 'Two' ), (3 , 'Three' ), (1 , 'One' ),
77+ ])),
78+ {'items' : {'enum' : [1 , 2 , 3 ], 'type' : 'integer' }, 'type' : 'array' }),
5779 (serializers .IntegerField (min_value = 2147483648 ),
5880 {'type' : 'integer' , 'minimum' : 2147483648 , 'format' : 'int64' }),
5981 ]
0 commit comments