9
9
from sqlalchemy .ext .hybrid import hybrid_property
10
10
from sqlalchemy .inspection import inspect
11
11
from sqlalchemy .orm import column_property , composite
12
- from sqlalchemy_utils import ChoiceType , JSONType , ScalarListType , UUIDType
12
+ import sqlalchemy_utils as sqa_utils
13
13
14
- import graphene
15
- from graphene import Boolean , Float , Int , Scalar , String
16
14
from graphene .relay import Node
17
- from graphene . types . datetime import Date , DateTime , Time
18
- from graphene .types .json import JSONString
19
- from graphene . types . structures import List , Structure
15
+ import graphene
16
+ from graphene .types .structures import Structure
17
+
20
18
21
19
from ..converter import (convert_sqlalchemy_column ,
22
20
convert_sqlalchemy_composite ,
@@ -187,7 +185,7 @@ def test_should_numeric_convert_float():
187
185
188
186
189
187
def test_should_choice_convert_enum ():
190
- field = get_field (ChoiceType ([(u"es" , u"Spanish" ), (u"en" , u"English" )]))
188
+ field = get_field (sqa_utils . ChoiceType ([(u"es" , u"Spanish" ), (u"en" , u"English" )]))
191
189
graphene_type = field .type
192
190
assert issubclass (graphene_type , graphene .Enum )
193
191
assert graphene_type ._meta .name == "MODEL_COLUMN"
@@ -200,7 +198,7 @@ class TestEnum(enum.Enum):
200
198
es = u"Spanish"
201
199
en = u"English"
202
200
203
- field = get_field (ChoiceType (TestEnum , impl = types .String ()))
201
+ field = get_field (sqa_utils . ChoiceType (TestEnum , impl = types .String ()))
204
202
graphene_type = field .type
205
203
assert issubclass (graphene_type , graphene .Enum )
206
204
assert graphene_type ._meta .name == "MODEL_COLUMN"
@@ -218,7 +216,7 @@ class TestEnum(enum.Enum):
218
216
es = u"Spanish"
219
217
en = u"English"
220
218
221
- testChoice = Column ("% descuento1" , ChoiceType (TestEnum , impl = types .String ()), key = "descuento1" )
219
+ testChoice = Column ("% descuento1" , sqa_utils . ChoiceType (TestEnum , impl = types .String ()), key = "descuento1" )
222
220
field = get_field_from_column (testChoice )
223
221
224
222
graphene_type = field .type
@@ -233,7 +231,7 @@ class TestEnum(enum.IntEnum):
233
231
one = 1
234
232
two = 2
235
233
236
- field = get_field (ChoiceType (TestEnum , impl = types .String ()))
234
+ field = get_field (sqa_utils . ChoiceType (TestEnum , impl = types .String ()))
237
235
graphene_type = field .type
238
236
assert issubclass (graphene_type , graphene .Enum )
239
237
assert graphene_type ._meta .name == "MODEL_COLUMN"
@@ -250,14 +248,14 @@ def test_should_columproperty_convert():
250
248
251
249
252
250
def test_should_scalar_list_convert_list ():
253
- field = get_field (ScalarListType ())
251
+ field = get_field (sqa_utils . ScalarListType ())
254
252
assert isinstance (field .type , graphene .List )
255
253
assert field .type .of_type == graphene .String
256
254
257
255
258
256
def test_should_jsontype_convert_jsonstring ():
259
- assert get_field (JSONType ()).type == JSONString
260
- assert get_field (types .JSON ).type == JSONString
257
+ assert get_field (sqa_utils . JSONType ()).type == graphene . JSONString
258
+ assert get_field (types .JSON ).type == graphene . JSONString
261
259
262
260
263
261
def test_should_variant_int_convert_int ():
@@ -369,7 +367,7 @@ def test_should_postgresql_uuid_convert():
369
367
370
368
371
369
def test_should_sqlalchemy_utils_uuid_convert ():
372
- assert get_field (UUIDType ()).type == graphene .UUID
370
+ assert get_field (sqa_utils . UUIDType ()).type == graphene .UUID
373
371
374
372
375
373
def test_should_postgresql_enum_convert ():
@@ -483,8 +481,8 @@ class Meta:
483
481
# Check ShoppingCartItem's Properties and Return Types
484
482
#######################################################
485
483
486
- shopping_cart_item_expected_types : Dict [str , Union [Scalar , Structure ]] = {
487
- 'hybrid_prop_shopping_cart' : List (ShoppingCartType )
484
+ shopping_cart_item_expected_types : Dict [str , Union [graphene . Scalar , Structure ]] = {
485
+ 'hybrid_prop_shopping_cart' : graphene . List (ShoppingCartType )
488
486
}
489
487
490
488
assert sorted (list (ShoppingCartItemType ._meta .fields .keys ())) == sorted ([
@@ -509,27 +507,27 @@ class Meta:
509
507
# Check ShoppingCart's Properties and Return Types
510
508
###################################################
511
509
512
- shopping_cart_expected_types : Dict [str , Union [Scalar , Structure ]] = {
510
+ shopping_cart_expected_types : Dict [str , Union [graphene . Scalar , Structure ]] = {
513
511
# Basic types
514
- "hybrid_prop_str" : String ,
515
- "hybrid_prop_int" : Int ,
516
- "hybrid_prop_float" : Float ,
517
- "hybrid_prop_bool" : Boolean ,
518
- "hybrid_prop_decimal" : String , # Decimals should be serialized Strings
519
- "hybrid_prop_date" : Date ,
520
- "hybrid_prop_time" : Time ,
521
- "hybrid_prop_datetime" : DateTime ,
512
+ "hybrid_prop_str" : graphene . String ,
513
+ "hybrid_prop_int" : graphene . Int ,
514
+ "hybrid_prop_float" : graphene . Float ,
515
+ "hybrid_prop_bool" : graphene . Boolean ,
516
+ "hybrid_prop_decimal" : graphene . String , # Decimals should be serialized Strings
517
+ "hybrid_prop_date" : graphene . Date ,
518
+ "hybrid_prop_time" : graphene . Time ,
519
+ "hybrid_prop_datetime" : graphene . DateTime ,
522
520
# Lists and Nested Lists
523
- "hybrid_prop_list_int" : List (Int ),
524
- "hybrid_prop_list_date" : List (Date ),
525
- "hybrid_prop_nested_list_int" : List (List (Int )),
526
- "hybrid_prop_deeply_nested_list_int" : List (List (List (Int ))),
521
+ "hybrid_prop_list_int" : graphene . List (graphene . Int ),
522
+ "hybrid_prop_list_date" : graphene . List (graphene . Date ),
523
+ "hybrid_prop_nested_list_int" : graphene . List (graphene . List (graphene . Int )),
524
+ "hybrid_prop_deeply_nested_list_int" : graphene . List (graphene . List (graphene . List (graphene . Int ))),
527
525
"hybrid_prop_first_shopping_cart_item" : ShoppingCartItemType ,
528
- "hybrid_prop_shopping_cart_item_list" : List (ShoppingCartItemType ),
529
- "hybrid_prop_unsupported_type_tuple" : String ,
526
+ "hybrid_prop_shopping_cart_item_list" : graphene . List (ShoppingCartItemType ),
527
+ "hybrid_prop_unsupported_type_tuple" : graphene . String ,
530
528
# Self Referential List
531
529
"hybrid_prop_self_referential" : ShoppingCartType ,
532
- "hybrid_prop_self_referential_list" : List (ShoppingCartType ),
530
+ "hybrid_prop_self_referential_list" : graphene . List (ShoppingCartType ),
533
531
# Optionals
534
532
"hybrid_prop_optional_self_referential" : ShoppingCartType ,
535
533
}
0 commit comments