1+ import enum
2+
13from py .test import raises
24from sqlalchemy import Column , Table , case , types , select , func
35from sqlalchemy .dialects import postgresql
@@ -24,7 +26,8 @@ def assert_column_conversion(sqlalchemy_type, graphene_field, **kwargs):
2426 column = Column (sqlalchemy_type , doc = 'Custom Help Text' , ** kwargs )
2527 graphene_type = convert_sqlalchemy_column (column )
2628 assert isinstance (graphene_type , graphene_field )
27- field = graphene_type .Field ()
29+ field = graphene_type if isinstance (
30+ graphene_type , graphene .Field ) else graphene_type .Field ()
2831 assert field .description == 'Custom Help Text'
2932 return field
3033
@@ -76,8 +79,18 @@ def test_should_unicodetext_convert_string():
7679 assert_column_conversion (types .UnicodeText (), graphene .String )
7780
7881
79- def test_should_enum_convert_string ():
80- assert_column_conversion (types .Enum (), graphene .String )
82+ def test_should_enum_convert_enum ():
83+ field = assert_column_conversion (
84+ types .Enum (enum .Enum ('one' , 'two' )), graphene .Field )
85+ field_type = field .type ()
86+ assert isinstance (field_type , graphene .Enum )
87+ assert hasattr (field_type , 'two' )
88+ field = assert_column_conversion (
89+ types .Enum ('one' , 'two' , name = 'two_numbers' ), graphene .Field )
90+ field_type = field .type ()
91+ assert field_type .__class__ .__name__ == 'two_numbers'
92+ assert isinstance (field_type , graphene .Enum )
93+ assert hasattr (field_type , 'two' )
8194
8295
8396def test_should_small_integer_convert_int ():
@@ -119,6 +132,7 @@ def test_should_label_convert_int():
119132 graphene_type = convert_sqlalchemy_column (label )
120133 assert isinstance (graphene_type , graphene .Int )
121134
135+
122136def test_should_choice_convert_enum ():
123137 TYPES = [
124138 (u'es' , u'Spanish' ),
@@ -247,7 +261,12 @@ def test_should_postgresql_uuid_convert():
247261
248262
249263def test_should_postgresql_enum_convert ():
250- assert_column_conversion (postgresql .ENUM (), graphene .String )
264+ field = assert_column_conversion (postgresql .ENUM (
265+ enum .Enum ('one' , 'two' ), name = 'two_numbers' ), graphene .Field )
266+ field_type = field .type ()
267+ assert field_type .__class__ .__name__ == 'two_numbers'
268+ assert isinstance (field_type , graphene .Enum )
269+ assert hasattr (field_type , 'two' )
251270
252271
253272def test_should_postgresql_array_convert ():
0 commit comments