Move to_const function from Graphene into Graphene-Django (#992) (#996)

Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
pull/1086/head
Jean-Louis Fuchs 2 years ago committed by GitHub
parent f8b88fdc9a
commit 08d0cce55a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      graphene_django/converter.py
  2. 6
      graphene_django/utils/str_converters.py
  3. 0
      graphene_django/utils/tests/__init__.py
  4. 9
      graphene_django/utils/tests/test_str_converters.py
  5. 1
      setup.py

@ -22,13 +22,14 @@ from graphene import (
Time,
)
from graphene.types.json import JSONString
from graphene.utils.str_converters import to_camel_case, to_const
from graphene.utils.str_converters import to_camel_case
from graphql import GraphQLError, assert_valid_name
from graphql.pyutils import register_description
from .compat import ArrayField, HStoreField, JSONField, RangeField
from .fields import DjangoConnectionField, DjangoListField
from .settings import graphene_settings
from .utils.str_converters import to_const
def convert_choice_name(name):

@ -0,0 +1,6 @@
import re
from unidecode import unidecode
def to_const(string):
return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()

@ -0,0 +1,9 @@
from ..str_converters import to_const
def test_to_const():
assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"
def test_to_const_unicode():
assert to_const(u"Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"

@ -58,6 +58,7 @@ setup(
"graphql-core>=3.1.0,<4",
"Django>=2.2",
"promise>=2.1",
"unidecode>=1.1.1,<2",
],
setup_requires=["pytest-runner"],
tests_require=tests_require,

Loading…
Cancel
Save