1
+ import pytest
1
2
from django .db import models
2
3
from py .test import raises
3
4
4
5
import graphene
5
- from graphene .contrib .django .converter import (
6
- convert_django_field , convert_django_field_with_choices )
7
- from graphene .contrib .django .fields import (ConnectionOrListField ,
8
- DjangoModelField )
6
+ from graphene .core .types .custom_scalars import DateTime , JSONString
9
7
8
+ from ..compat import (ArrayField , HStoreField , JSONField , MissingType ,
9
+ RangeField )
10
+ from ..converter import convert_django_field , convert_django_field_with_choices
11
+ from ..fields import ConnectionOrListField , DjangoModelField
10
12
from .models import Article , Reporter
11
13
12
14
@@ -26,7 +28,7 @@ def test_should_unknown_django_field_raise_exception():
26
28
27
29
28
30
def test_should_date_convert_string ():
29
- assert_conversion (models .DateField , graphene . String )
31
+ assert_conversion (models .DateField , DateTime )
30
32
31
33
32
34
def test_should_char_convert_string ():
@@ -53,6 +55,14 @@ def test_should_ipaddress_convert_string():
53
55
assert_conversion (models .GenericIPAddressField , graphene .String )
54
56
55
57
58
+ def test_should_file_convert_string ():
59
+ assert_conversion (models .FileField , graphene .String )
60
+
61
+
62
+ def test_should_image_convert_string ():
63
+ assert_conversion (models .ImageField , graphene .String )
64
+
65
+
56
66
def test_should_auto_convert_id ():
57
67
assert_conversion (models .AutoField , graphene .ID , primary_key = True )
58
68
@@ -136,3 +146,40 @@ def test_should_onetoone_convert_model():
136
146
def test_should_foreignkey_convert_model ():
137
147
field = assert_conversion (models .ForeignKey , DjangoModelField , Article )
138
148
assert field .type .model == Article
149
+
150
+
151
+ @pytest .mark .skipif (ArrayField is MissingType ,
152
+ reason = "ArrayField should exist" )
153
+ def test_should_postgres_array_convert_list ():
154
+ field = assert_conversion (ArrayField , graphene .List , models .CharField (max_length = 100 ))
155
+ assert isinstance (field .type , graphene .List )
156
+ assert isinstance (field .type .of_type , graphene .String )
157
+
158
+
159
+ @pytest .mark .skipif (ArrayField is MissingType ,
160
+ reason = "ArrayField should exist" )
161
+ def test_should_postgres_array_multiple_convert_list ():
162
+ field = assert_conversion (ArrayField , graphene .List , ArrayField (models .CharField (max_length = 100 )))
163
+ assert isinstance (field .type , graphene .List )
164
+ assert isinstance (field .type .of_type , graphene .List )
165
+ assert isinstance (field .type .of_type .of_type , graphene .String )
166
+
167
+
168
+ @pytest .mark .skipif (HStoreField is MissingType ,
169
+ reason = "HStoreField should exist" )
170
+ def test_should_postgres_hstore_convert_string ():
171
+ assert_conversion (HStoreField , JSONString )
172
+
173
+
174
+ @pytest .mark .skipif (JSONField is MissingType ,
175
+ reason = "JSONField should exist" )
176
+ def test_should_postgres_json_convert_string ():
177
+ assert_conversion (JSONField , JSONString )
178
+
179
+
180
+ @pytest .mark .skipif (RangeField is MissingType ,
181
+ reason = "RangeField should exist" )
182
+ def test_should_postgres_range_convert_list ():
183
+ from django .contrib .postgres .fields import IntegerRangeField
184
+ field = assert_conversion (IntegerRangeField , graphene .List )
185
+ assert isinstance (field .type .of_type , graphene .Int )
0 commit comments