mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
install requires for backwards compatible enum
This commit is contained in:
parent
c827267cb9
commit
bc06637278
|
@ -114,8 +114,5 @@ class MyCustomChoices(DjangoChoicesEnum):
|
||||||
|
|
||||||
class FilmWithChoices(models.Model):
|
class FilmWithChoices(models.Model):
|
||||||
genre = models.CharField(
|
genre = models.CharField(
|
||||||
max_length=2,
|
max_length=2, help_text="Genre", choices=MyCustomChoices.choices(), default="DO"
|
||||||
help_text="Genre",
|
|
||||||
choices=MyCustomChoices.choices(),
|
|
||||||
default=MyCustomChoices.choices()[0][0],
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1072,7 +1072,7 @@ def test_using_django_choices_enum():
|
||||||
def resolve_films(self, info, **args):
|
def resolve_films(self, info, **args):
|
||||||
return Film.objects.all()
|
return Film.objects.all()
|
||||||
|
|
||||||
f = FilmWithChoices.objects.create()
|
f = FilmWithChoices.objects.create(genre="DO")
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
query NodeFilteringQuery {
|
query NodeFilteringQuery {
|
||||||
|
@ -1104,7 +1104,8 @@ def test_using_django_choices_enum():
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
enum_values = result.data["__type"]["enumValues"]
|
enum_values = result.data["__type"]["enumValues"]
|
||||||
assert enum_values == [
|
for result in [
|
||||||
{"name": "DO", "description": "Documentary"},
|
|
||||||
{"name": "OT", "description": "Other"},
|
{"name": "OT", "description": "Other"},
|
||||||
]
|
{"name": "DO", "description": "Documentary"},
|
||||||
|
]:
|
||||||
|
assert result in enum_values
|
||||||
|
|
|
@ -242,4 +242,6 @@ def test_custom_django_choices_enum():
|
||||||
assert graphene_enum._meta.description(graphene_enum.FOO) == "foo"
|
assert graphene_enum._meta.description(graphene_enum.FOO) == "foo"
|
||||||
|
|
||||||
# As a Django choices option
|
# 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
|
||||||
|
|
|
@ -180,7 +180,7 @@ class DjangoChoicesEnum(object):
|
||||||
class Model(models.model)
|
class Model(models.model)
|
||||||
some_field = CharField(choices=ChoicesType.choices())
|
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
|
@classmethod
|
||||||
def as_enum(cls):
|
def as_enum(cls):
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -60,6 +60,7 @@ setup(
|
||||||
"Django>=1.11",
|
"Django>=1.11",
|
||||||
"singledispatch>=3.4.0.3",
|
"singledispatch>=3.4.0.3",
|
||||||
"promise>=2.1",
|
"promise>=2.1",
|
||||||
|
"enum-compat",
|
||||||
],
|
],
|
||||||
setup_requires=["pytest-runner"],
|
setup_requires=["pytest-runner"],
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user