From 50c1ab62ba9a8dc38fdbbefedbfff103d0124a0e Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sat, 4 Jun 2016 15:42:17 -0700 Subject: [PATCH] Fixed Enum value getter --- graphene/types/enum.py | 10 ++++------ graphene/types/tests/test_enum.py | 9 +++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/graphene/types/enum.py b/graphene/types/enum.py index 5d8956dd..75111b47 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -55,11 +55,12 @@ class EnumTypeMeta(ClassTypeMeta): def construct(cls, bases, attrs): if not cls._meta.enum: cls._meta.enum = type(cls.__name__, (PyEnum,), attrs) - return super(EnumTypeMeta, cls).construct(bases, {}) + + return super(EnumTypeMeta, cls).construct(bases, cls._meta.enum.__members__) def __call__(cls, *args, **kwargs): - if cls is Enum: - return Enum.create(PyEnum(*args, **kwargs)) + if cls._meta.abstract: + return cls.create(PyEnum(*args, **kwargs)) return super(EnumTypeMeta, cls).__call__(*args, **kwargs) def create(cls, python_enum): @@ -71,6 +72,3 @@ class EnumTypeMeta(ClassTypeMeta): class Enum(six.with_metaclass(EnumTypeMeta, TypeProxy)): class Meta: abstract = True - - def __getattr__(self, name): - return getattr(self._meta.enum, name) diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index e032ccb8..51b3b76c 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -50,3 +50,12 @@ def test_enum_from_builtin_enum(): ] assert isinstance(RGB(name='field_name').as_field(), Field) assert isinstance(RGB(name='field_name').as_argument(), Argument) + + +def test_enum_value_from_class(): + class RGB(Enum): + RED = 1 + GREEN = 2 + BLUE = 3 + + assert RGB.RED.value == 1