Skip to content

Commit 32d2808

Browse files
committed
test and handle choices that start with an underscore, issue #141
1 parent ae03318 commit 32d2808

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

graphene_django/converter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
def convert_choice_name(name):
3232
name = force_text(name).encode('utf8').decode('ascii', 'ignore')
3333
name = to_const(name)
34+
if name.startswith('_'):
35+
name = "A%s" % name
3436
try:
3537
assert_valid_name(name)
3638
except AssertionError:

graphene_django/tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.db import models
55
from django.utils.translation import ugettext_lazy as _
66

7-
CHOICES = ((1, u"1: this漢"), (2, _(u"2: that漢")))
7+
CHOICES = ((1, u"1: this漢"), (2, _(u"2: that漢")), (3, "__amount__"))
88

99

1010
class Pet(models.Model):

graphene_django/tests/test_converter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ class Meta:
215215
convert_django_field_with_choices(field)
216216

217217

218+
def test_field_with_choices_underscore():
219+
field = models.CharField(
220+
choices=(
221+
("__amount__", "Amount"),
222+
("__percentage__", "Percentage"),
223+
),
224+
)
225+
226+
class UnderscoreChoicesModel(models.Model):
227+
ourfield = field
228+
229+
class Meta:
230+
app_label = "test"
231+
232+
graphene_type = convert_django_field_with_choices(field)
233+
assert len(graphene_type._meta.enum.__members__) == 2
234+
235+
218236
def test_should_float_convert_float():
219237
assert_conversion(models.FloatField, graphene.Float)
220238

graphene_django/tests/test_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def test_schema_representation():
174174
enum ReporterAChoice {
175175
A_1_THIS
176176
A_2_THAT
177+
A__AMOUNT__
177178
}
178179
179180
enum ReporterReporterType {

0 commit comments

Comments
 (0)