mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
expand test case to cover underscores that are sunder, dunder, and general underscore
This commit is contained in:
parent
59184a117d
commit
de7edaae76
|
@ -36,10 +36,18 @@ def _is_dunder(name):
|
||||||
name[-3:-2] != '_')
|
name[-3:-2] != '_')
|
||||||
|
|
||||||
|
|
||||||
|
def _is_sunder(name):
|
||||||
|
"""Returns True if a _sunder_ name, False otherwise."""
|
||||||
|
return (len(name) > 2 and
|
||||||
|
name[0] == name[-1] == '_' and
|
||||||
|
name[1:2] != '_' and
|
||||||
|
name[-2:-1] != '_')
|
||||||
|
|
||||||
|
|
||||||
def convert_choice_name(name):
|
def convert_choice_name(name):
|
||||||
name = force_text(name).encode('utf8').decode('ascii', 'ignore')
|
name = force_text(name).encode('utf8').decode('ascii', 'ignore')
|
||||||
name = to_const(name)
|
name = to_const(name)
|
||||||
if _is_dunder(name):
|
if _is_sunder(name) or _is_dunder(name):
|
||||||
name = "A%s" % name
|
name = "A%s" % name
|
||||||
try:
|
try:
|
||||||
assert_valid_name(name)
|
assert_valid_name(name)
|
||||||
|
|
|
@ -199,8 +199,10 @@ def test_field_with_choices_collision():
|
||||||
def test_field_with_choices_underscore():
|
def test_field_with_choices_underscore():
|
||||||
field = models.CharField(
|
field = models.CharField(
|
||||||
choices=(
|
choices=(
|
||||||
("_amount__", "Amount"),
|
("_amount_", "Amount"),
|
||||||
("__percentage__", "Percentage"),
|
("__percentage__", "Percentage"),
|
||||||
|
("_not_sunder__", "Not Single Underscore"),
|
||||||
|
("__not_dunder", "Not Double Underscore"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -211,12 +213,11 @@ def test_field_with_choices_underscore():
|
||||||
app_label = "test"
|
app_label = "test"
|
||||||
|
|
||||||
graphene_type = convert_django_field_with_choices(field)
|
graphene_type = convert_django_field_with_choices(field)
|
||||||
assert len(graphene_type._meta.enum.__members__) == 2
|
assert len(graphene_type._meta.enum.__members__) == 4
|
||||||
assert graphene_type._meta.enum.__members__["_AMOUNT__"].value == "_amount__"
|
assert "A_AMOUNT_" in graphene_type._meta.enum.__members__
|
||||||
assert graphene_type._meta.enum.__members__["_AMOUNT__"].description == "Amount"
|
assert "A__PERCENTAGE__" in graphene_type._meta.enum.__members__
|
||||||
assert graphene_type._meta.enum.__members__["A__PERCENTAGE__"].value == "__percentage__"
|
assert "_NOT_SUNDER__" in graphene_type._meta.enum.__members__
|
||||||
assert graphene_type._meta.enum.__members__["A__PERCENTAGE__"].description == "Percentage"
|
assert "__NOT_DUNDER" in graphene_type._meta.enum.__members__
|
||||||
|
|
||||||
|
|
||||||
def test_should_float_convert_float():
|
def test_should_float_convert_float():
|
||||||
assert_conversion(models.FloatField, graphene.Float)
|
assert_conversion(models.FloatField, graphene.Float)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user