mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
Simplify choices in test
This commit is contained in:
parent
0b96bf9b33
commit
458ea844a4
|
@ -585,7 +585,7 @@ class TestOperationIntrospection(TestCase):
|
||||||
responses = inspector._get_responses(path, method)
|
responses = inspector._get_responses(path, method)
|
||||||
response_schema = responses['200']['content']['application/json']['schema']
|
response_schema = responses['200']['content']['application/json']['schema']
|
||||||
properties = response_schema['items']['properties']
|
properties = response_schema['items']['properties']
|
||||||
assert 'type' in properties['gender']
|
assert 'type' in properties['choice_field']
|
||||||
|
|
||||||
def test_serializer_validators(self):
|
def test_serializer_validators(self):
|
||||||
path = '/'
|
path = '/'
|
||||||
|
|
|
@ -138,22 +138,13 @@ class ExampleValidatedAPIView(generics.GenericAPIView):
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
MALE = 'male'
|
|
||||||
FEMALE = 'female'
|
|
||||||
|
|
||||||
EXAMPLE_GENDER_CHOICES = (
|
|
||||||
(MALE, 'male'),
|
|
||||||
(FEMALE, 'female')
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleChoiceFieldSerializer(serializers.Serializer):
|
class ExampleChoiceFieldSerializer(serializers.Serializer):
|
||||||
gender = serializers.ChoiceField(choices=EXAMPLE_GENDER_CHOICES)
|
choice_field = serializers.ChoiceField(choices=[('a', 'Choice A', 'b', 'Choice B')])
|
||||||
|
|
||||||
|
|
||||||
class ExampleChoiceFieldAPIView(generics.GenericAPIView):
|
class ExampleChoiceFieldAPIView(generics.GenericAPIView):
|
||||||
serializer_class = ExampleChoiceFieldSerializer
|
serializer_class = ExampleChoiceFieldSerializer
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
serializer = self.get_serializer(gender='male')
|
serializer = self.get_serializer(choice_field='a')
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user