1
+ import uuid
2
+
1
3
import pytest
2
4
from django .conf .urls import url
3
5
from django .test import RequestFactory , TestCase , override_settings
@@ -44,6 +46,8 @@ def test_pagination(self):
44
46
45
47
class TestFieldMapping (TestCase ):
46
48
def test_list_field_mapping (self ):
49
+ uuid1 = uuid .uuid4 ()
50
+ uuid2 = uuid .uuid4 ()
47
51
inspector = AutoSchema ()
48
52
cases = [
49
53
(serializers .ListField (), {'items' : {}, 'type' : 'array' }),
@@ -53,7 +57,25 @@ def test_list_field_mapping(self):
53
57
(serializers .ListField (child = serializers .IntegerField (max_value = 4294967295 )),
54
58
{'items' : {'type' : 'integer' , 'maximum' : 4294967295 , 'format' : 'int64' }, 'type' : 'array' }),
55
59
(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' }),
57
79
(serializers .IntegerField (min_value = 2147483648 ),
58
80
{'type' : 'integer' , 'minimum' : 2147483648 , 'format' : 'int64' }),
59
81
]
0 commit comments