Skip to content

Commit

Permalink
test if field with callable choices converts into enum
Browse files Browse the repository at this point in the history
  • Loading branch information
nossila committed Feb 7, 2024
1 parent a48abd1 commit f18ab43
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions graphene_django/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ class Meta:
assert graphene_type._meta.enum.__members__["EN"].description == "English"


def test_field_with_callable_choices_convert_enum():
def get_choices():
return ("es", "Spanish"), ("en", "English")

field = models.CharField(help_text="Language", choices=get_choices)

class TranslatedModel(models.Model):
language = field

class Meta:
app_label = "test"

graphene_type = convert_django_field_with_choices(field).type.of_type
assert graphene_type._meta.name == "TestTranslatedModelLanguageChoices"
assert graphene_type._meta.enum.__members__["ES"].value == "es"
assert graphene_type._meta.enum.__members__["ES"].description == "Spanish"
assert graphene_type._meta.enum.__members__["EN"].value == "en"
assert graphene_type._meta.enum.__members__["EN"].description == "English"


def test_field_with_grouped_choices():
field = models.CharField(
help_text="Language",
Expand Down

0 comments on commit f18ab43

Please sign in to comment.