|
1 | 1 | import copy |
2 | | -from rest_framework import serializers |
3 | | -from py.test import raises |
4 | 2 |
|
5 | 3 | import graphene |
| 4 | +from django.db import models |
| 5 | +from graphene import InputObjectType |
| 6 | +from py.test import raises |
| 7 | +from rest_framework import serializers |
6 | 8 |
|
7 | 9 | from ..serializer_converter import convert_serializer_field |
8 | 10 | from ..types import DictType |
@@ -74,7 +76,6 @@ def test_should_uuid_convert_string(): |
74 | 76 |
|
75 | 77 |
|
76 | 78 | def test_should_model_convert_field(): |
77 | | - |
78 | 79 | class MyModelSerializer(serializers.ModelSerializer): |
79 | 80 | class Meta: |
80 | 81 | model = None |
@@ -128,6 +129,30 @@ class StringListField(serializers.ListField): |
128 | 129 | assert field_b.of_type == graphene.String |
129 | 130 |
|
130 | 131 |
|
| 132 | +def test_should_list_serializer_convert_to_list(): |
| 133 | + class FooModel(models.Model): |
| 134 | + pass |
| 135 | + |
| 136 | + class ChildSerializer(serializers.ModelSerializer): |
| 137 | + class Meta: |
| 138 | + model = FooModel |
| 139 | + fields = '__all__' |
| 140 | + |
| 141 | + class ParentSerializer(serializers.ModelSerializer): |
| 142 | + child = ChildSerializer(many=True) |
| 143 | + |
| 144 | + class Meta: |
| 145 | + model = FooModel |
| 146 | + fields = '__all__' |
| 147 | + |
| 148 | + converted_type = convert_serializer_field(ParentSerializer().get_fields()['child'], is_input=True) |
| 149 | + assert isinstance(converted_type, graphene.List) |
| 150 | + |
| 151 | + converted_type = convert_serializer_field(ParentSerializer().get_fields()['child'], is_input=False) |
| 152 | + assert isinstance(converted_type, graphene.List) |
| 153 | + assert converted_type.of_type is None |
| 154 | + |
| 155 | + |
131 | 156 | def test_should_dict_convert_dict(): |
132 | 157 | assert_conversion(serializers.DictField, DictType) |
133 | 158 |
|
@@ -157,6 +182,6 @@ def test_should_json_convert_jsonstring(): |
157 | 182 |
|
158 | 183 |
|
159 | 184 | def test_should_multiplechoicefield_convert_to_list_of_string(): |
160 | | - field = assert_conversion(serializers.MultipleChoiceField, graphene.List, choices=[1,2,3]) |
| 185 | + field = assert_conversion(serializers.MultipleChoiceField, graphene.List, choices=[1, 2, 3]) |
161 | 186 |
|
162 | 187 | assert field.of_type == graphene.String |
0 commit comments