mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
test and handle choices that start with an underscore, issue #141
This commit is contained in:
parent
ae0331873e
commit
32d2808187
|
@ -31,6 +31,8 @@ singledispatch = import_single_dispatch()
|
|||
def convert_choice_name(name):
|
||||
name = force_text(name).encode('utf8').decode('ascii', 'ignore')
|
||||
name = to_const(name)
|
||||
if name.startswith('_'):
|
||||
name = "A%s" % name
|
||||
try:
|
||||
assert_valid_name(name)
|
||||
except AssertionError:
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import absolute_import
|
|||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
CHOICES = ((1, u"1: this漢"), (2, _(u"2: that漢")))
|
||||
CHOICES = ((1, u"1: this漢"), (2, _(u"2: that漢")), (3, "__amount__"))
|
||||
|
||||
|
||||
class Pet(models.Model):
|
||||
|
|
|
@ -215,6 +215,24 @@ def test_field_with_choices_collision():
|
|||
convert_django_field_with_choices(field)
|
||||
|
||||
|
||||
def test_field_with_choices_underscore():
|
||||
field = models.CharField(
|
||||
choices=(
|
||||
("__amount__", "Amount"),
|
||||
("__percentage__", "Percentage"),
|
||||
),
|
||||
)
|
||||
|
||||
class UnderscoreChoicesModel(models.Model):
|
||||
ourfield = field
|
||||
|
||||
class Meta:
|
||||
app_label = "test"
|
||||
|
||||
graphene_type = convert_django_field_with_choices(field)
|
||||
assert len(graphene_type._meta.enum.__members__) == 2
|
||||
|
||||
|
||||
def test_should_float_convert_float():
|
||||
assert_conversion(models.FloatField, graphene.Float)
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ type Reporter {
|
|||
enum ReporterAChoice {
|
||||
A_1_THIS
|
||||
A_2_THAT
|
||||
A__AMOUNT__
|
||||
}
|
||||
|
||||
enum ReporterReporterType {
|
||||
|
|
Loading…
Reference in New Issue
Block a user