From bc0663727820d2b6cceced1abd72e5b52344e293 Mon Sep 17 00:00:00 2001 From: Paul Hallett Date: Wed, 8 May 2019 21:39:57 +0100 Subject: [PATCH] install requires for backwards compatible enum --- graphene_django/tests/models.py | 5 +---- graphene_django/tests/test_query.py | 9 +++++---- graphene_django/tests/test_types.py | 4 +++- graphene_django/types.py | 2 +- setup.py | 1 + 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/graphene_django/tests/models.py b/graphene_django/tests/models.py index 03cc40e..e216d8a 100644 --- a/graphene_django/tests/models.py +++ b/graphene_django/tests/models.py @@ -114,8 +114,5 @@ class MyCustomChoices(DjangoChoicesEnum): class FilmWithChoices(models.Model): genre = models.CharField( - max_length=2, - help_text="Genre", - choices=MyCustomChoices.choices(), - default=MyCustomChoices.choices()[0][0], + max_length=2, help_text="Genre", choices=MyCustomChoices.choices(), default="DO" ) diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 9ee39ea..0ade7a1 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1072,7 +1072,7 @@ def test_using_django_choices_enum(): def resolve_films(self, info, **args): return Film.objects.all() - f = FilmWithChoices.objects.create() + f = FilmWithChoices.objects.create(genre="DO") query = """ query NodeFilteringQuery { @@ -1104,7 +1104,8 @@ def test_using_django_choices_enum(): result = schema.execute(query) assert not result.errors enum_values = result.data["__type"]["enumValues"] - assert enum_values == [ - {"name": "DO", "description": "Documentary"}, + for result in [ {"name": "OT", "description": "Other"}, - ] + {"name": "DO", "description": "Documentary"}, + ]: + assert result in enum_values diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index c09876d..b4bfd1b 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -242,4 +242,6 @@ def test_custom_django_choices_enum(): assert graphene_enum._meta.description(graphene_enum.FOO) == "foo" # As a Django choices option - assert MyChoicesEnum.choices() == [("FOO", "foo"), ("BAR", "bar")] + resulting_choices = MyChoicesEnum.choices() + for result in (("FOO", "foo"), ("BAR", "bar")): + assert result in resulting_choices diff --git a/graphene_django/types.py b/graphene_django/types.py index 5641421..eaa432b 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -180,7 +180,7 @@ class DjangoChoicesEnum(object): class Model(models.model) some_field = CharField(choices=ChoicesType.choices()) """ - return [(k, v) for k, v in cls.__dict__.items() if not k.startswith("__")] + return tuple((k, v) for k, v in cls.__dict__.items() if not k.startswith("__")) @classmethod def as_enum(cls): diff --git a/setup.py b/setup.py index e622a71..07831c2 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ setup( "Django>=1.11", "singledispatch>=3.4.0.3", "promise>=2.1", + "enum-compat", ], setup_requires=["pytest-runner"], tests_require=tests_require,