@@ -85,19 +85,37 @@ def test_should_unicodetext_convert_string():
85
85
86
86
87
87
def test_should_enum_convert_enum ():
88
- field = assert_column_conversion (
89
- types .Enum (enum .Enum ("one" , "two" )), graphene .Field
90
- )
88
+ field = assert_column_conversion (types .Enum ("one" , "two" ), graphene .Field )
91
89
field_type = field .type ()
90
+ assert field_type .__class__ .__name__ .startswith ("Enum" )
92
91
assert isinstance (field_type , graphene .Enum )
93
- assert hasattr (field_type , "two" )
92
+ assert hasattr (field_type , "ONE" )
93
+ assert not hasattr (field_type , "one" )
94
+ assert hasattr (field_type , "TWO" )
95
+
94
96
field = assert_column_conversion (
95
97
types .Enum ("one" , "two" , name = "two_numbers" ), graphene .Field
96
98
)
97
99
field_type = field .type ()
98
- assert field_type .__class__ .__name__ == "two_numbers"
100
+ assert field_type .__class__ .__name__ == "TwoNumbers"
101
+ assert isinstance (field_type , graphene .Enum )
102
+ assert hasattr (field_type , "ONE" )
103
+ assert not hasattr (field_type , "one" )
104
+ assert hasattr (field_type , "TWO" )
105
+
106
+
107
+ def test_conflicting_enum_should_raise_error ():
108
+ some_type = types .Enum (enum .Enum ("ConflictingEnum" , "cat cow" ))
109
+ field = assert_column_conversion (some_type , graphene .Field )
110
+ field_type = field .type ()
99
111
assert isinstance (field_type , graphene .Enum )
100
- assert hasattr (field_type , "two" )
112
+ assert hasattr (field_type , "COW" )
113
+ same_type = types .Enum (enum .Enum ("ConflictingEnum" , "cat cow" ))
114
+ field = assert_column_conversion (same_type , graphene .Field )
115
+ assert field_type == field .type ()
116
+ conflicting_type = types .Enum (enum .Enum ("ConflictingEnum" , "cat horse" ))
117
+ with raises (TypeError ):
118
+ assert_column_conversion (conflicting_type , graphene .Field )
101
119
102
120
103
121
def test_should_small_integer_convert_int ():
@@ -272,19 +290,20 @@ def test_should_postgresql_enum_convert():
272
290
postgresql .ENUM ("one" , "two" , name = "two_numbers" ), graphene .Field
273
291
)
274
292
field_type = field .type ()
275
- assert field_type .__class__ .__name__ == "two_numbers "
293
+ assert field_type .__class__ .__name__ == "TwoNumbers "
276
294
assert isinstance (field_type , graphene .Enum )
277
- assert hasattr (field_type , "two " )
295
+ assert hasattr (field_type , "TWO " )
278
296
279
297
280
298
def test_should_postgresql_py_enum_convert ():
281
299
field = assert_column_conversion (
282
- postgresql .ENUM (enum .Enum ("TwoNumbers" , "one two" ), name = "two_numbers" ), graphene .Field
300
+ postgresql .ENUM (enum .Enum ("TwoNumbersEnum" , "one two" ), name = "two_numbers" ),
301
+ graphene .Field ,
283
302
)
284
303
field_type = field .type ()
285
- assert field_type .__class__ .__name__ == "TwoNumbers "
304
+ assert field_type .__class__ .__name__ == "TwoNumbersEnum "
286
305
assert isinstance (field_type , graphene .Enum )
287
- assert hasattr (field_type , "two " )
306
+ assert hasattr (field_type , "TWO " )
288
307
289
308
290
309
def test_should_postgresql_array_convert ():
0 commit comments