Skip to content

Commit 56021f9

Browse files
committed
Add tests for list field to schema
1 parent 32a0b62 commit 56021f9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_schemas.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class ExampleSerializer(serializers.Serializer):
3939
hidden = serializers.HiddenField(default='hello')
4040

4141

42+
class AnotherSerializerWithListFields(serializers.Serializer):
43+
a = serializers.ListField(child=serializers.IntegerField())
44+
b = serializers.ListSerializer(child=serializers.CharField())
45+
46+
4247
class AnotherSerializer(serializers.Serializer):
4348
c = serializers.CharField(required=True)
4449
d = serializers.CharField(required=False)
@@ -57,6 +62,13 @@ def custom_action(self, request, pk):
5762
"""
5863
return super(ExampleSerializer, self).retrieve(self, request)
5964

65+
@detail_route(methods=['post'], serializer_class=AnotherSerializerWithListFields)
66+
def custom_action_with_list_fields(self, request, pk):
67+
"""
68+
A custom action using both list field and list serializer in the serializer.
69+
"""
70+
return super(ExampleSerializer, self).retrieve(self, request)
71+
6072
@list_route()
6173
def custom_list_action(self, request):
6274
return super(ExampleViewSet, self).list(self, request)
@@ -174,6 +186,17 @@ def test_authenticated_request(self):
174186
coreapi.Field('d', required=False, location='form', schema=coreschema.String(title='D')),
175187
]
176188
),
189+
'custom_action_with_list_fields': coreapi.Link(
190+
url='/example/{id}/custom_action_with_list_fields/',
191+
action='post',
192+
encoding='application/json',
193+
description='A custom action using both list field and list serializer in the serializer.',
194+
fields=[
195+
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
196+
coreapi.Field('a', required=True, location='form', schema=coreschema.Array(title='A', items=coreschema.Integer())),
197+
coreapi.Field('b', required=True, location='form', schema=coreschema.Array(title='B', items=coreschema.String())),
198+
]
199+
),
177200
'custom_list_action': coreapi.Link(
178201
url='/example/custom_list_action/',
179202
action='get'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy