From 4caeaf73543c639f07bdcc371201b8a9e5e5b175 Mon Sep 17 00:00:00 2001 From: Max Peterson Date: Fri, 3 Jul 2015 14:07:02 +0100 Subject: [PATCH] Add regression test for grouped choices metadata Regression test for #3101 --- tests/test_metadata.py | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index f7aab89733..8cc5f344ed 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -241,6 +241,62 @@ def test_null_boolean_field_info_type(self): field_info = options.get_field_info(serializers.NullBooleanField()) assert field_info['type'] == 'boolean' + def test_bug_3101_grouped_choices(self): + choices = [ + ( + 'Colours', + ( + ('red', 'Red'), + ('green', 'Green'), + ('blue', 'Blue'), + ) + ) + ] + + class ExampleSerializer(serializers.Serializer): + choice_field = serializers.ChoiceField(choices) + + class ExampleView(views.APIView): + """Example view.""" + def post(self, request): + pass + + def get_serializer(self): + return ExampleSerializer() + + view = ExampleView.as_view() + response = view(request=request) + expected = { + 'name': 'Example', + 'description': 'Example view.', + 'renders': [ + 'application/json', + 'text/html' + ], + 'parses': [ + 'application/json', + 'application/x-www-form-urlencoded', + 'multipart/form-data' + ], + 'actions': { + 'POST': { + 'choice_field': { + 'type': 'choice', + 'required': True, + 'read_only': False, + 'label': 'Choice field', + 'choices': [ + {'display_name': 'Red', 'value': 'red'}, + {'display_name': 'Green', 'value': 'green'}, + {'display_name': 'Blue', 'value': 'blue'} + ] + } + } + } + } + assert response.status_code == status.HTTP_200_OK + assert response.data == expected + class TestModelSerializerMetadata(TestCase): def test_read_only_primary_key_related_field(self):