@@ -85,19 +85,37 @@ def test_should_unicodetext_convert_string():
8585
8686
8787def 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 )
9189 field_type = field .type ()
90+ assert field_type .__class__ .__name__ .startswith ("Enum" )
9291 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+
9496 field = assert_column_conversion (
9597 types .Enum ("one" , "two" , name = "two_numbers" ), graphene .Field
9698 )
9799 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 ()
99111 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 )
101119
102120
103121def test_should_small_integer_convert_int ():
@@ -272,19 +290,20 @@ def test_should_postgresql_enum_convert():
272290 postgresql .ENUM ("one" , "two" , name = "two_numbers" ), graphene .Field
273291 )
274292 field_type = field .type ()
275- assert field_type .__class__ .__name__ == "two_numbers "
293+ assert field_type .__class__ .__name__ == "TwoNumbers "
276294 assert isinstance (field_type , graphene .Enum )
277- assert hasattr (field_type , "two " )
295+ assert hasattr (field_type , "TWO " )
278296
279297
280298def test_should_postgresql_py_enum_convert ():
281299 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 ,
283302 )
284303 field_type = field .type ()
285- assert field_type .__class__ .__name__ == "TwoNumbers "
304+ assert field_type .__class__ .__name__ == "TwoNumbersEnum "
286305 assert isinstance (field_type , graphene .Enum )
287- assert hasattr (field_type , "two " )
306+ assert hasattr (field_type , "TWO " )
288307
289308
290309def test_should_postgresql_array_convert ():
0 commit comments