mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
add failing test case for schema generation
This commit is contained in:
parent
90eaf51839
commit
0b96bf9b33
|
@ -571,6 +571,22 @@ class TestOperationIntrospection(TestCase):
|
||||||
properties = response_schema['items']['properties']
|
properties = response_schema['items']['properties']
|
||||||
assert properties['hstore']['type'] == 'object'
|
assert properties['hstore']['type'] == 'object'
|
||||||
|
|
||||||
|
def test_serializer_choice_field(self):
|
||||||
|
path = '/'
|
||||||
|
method = 'GET'
|
||||||
|
view = create_view(
|
||||||
|
views.ExampleChoiceFieldAPIView,
|
||||||
|
method,
|
||||||
|
create_request(path),
|
||||||
|
)
|
||||||
|
inspector = AutoSchema()
|
||||||
|
inspector.view = view
|
||||||
|
|
||||||
|
responses = inspector._get_responses(path, method)
|
||||||
|
response_schema = responses['200']['content']['application/json']['schema']
|
||||||
|
properties = response_schema['items']['properties']
|
||||||
|
assert 'type' in properties['gender']
|
||||||
|
|
||||||
def test_serializer_validators(self):
|
def test_serializer_validators(self):
|
||||||
path = '/'
|
path = '/'
|
||||||
method = 'GET'
|
method = 'GET'
|
||||||
|
|
|
@ -136,3 +136,24 @@ class ExampleValidatedAPIView(generics.GenericAPIView):
|
||||||
url='http://localhost', uuid=uuid.uuid4(), ip4='127.0.0.1', ip6='::1',
|
url='http://localhost', uuid=uuid.uuid4(), ip4='127.0.0.1', ip6='::1',
|
||||||
ip='192.168.1.1')
|
ip='192.168.1.1')
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
|
MALE = 'male'
|
||||||
|
FEMALE = 'female'
|
||||||
|
|
||||||
|
EXAMPLE_GENDER_CHOICES = (
|
||||||
|
(MALE, 'male'),
|
||||||
|
(FEMALE, 'female')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ExampleChoiceFieldSerializer(serializers.Serializer):
|
||||||
|
gender = serializers.ChoiceField(choices=EXAMPLE_GENDER_CHOICES)
|
||||||
|
|
||||||
|
|
||||||
|
class ExampleChoiceFieldAPIView(generics.GenericAPIView):
|
||||||
|
serializer_class = ExampleChoiceFieldSerializer
|
||||||
|
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
serializer = self.get_serializer(gender='male')
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user