mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
Run black
This commit is contained in:
parent
0afd512bb2
commit
e2ca1ed5e0
|
@ -52,7 +52,9 @@ def get_choices(choices):
|
||||||
yield name, value, description
|
yield name, value, description
|
||||||
|
|
||||||
|
|
||||||
def convert_django_field_with_choices(field, registry=None, convert_choices_to_enum=True):
|
def convert_django_field_with_choices(
|
||||||
|
field, registry=None, convert_choices_to_enum=True
|
||||||
|
):
|
||||||
if registry is not None:
|
if registry is not None:
|
||||||
converted = registry.get_converted_field(field)
|
converted = registry.get_converted_field(field)
|
||||||
if converted:
|
if converted:
|
||||||
|
|
|
@ -208,8 +208,7 @@ def test_field_with_choices_convert_enum_false():
|
||||||
app_label = "test"
|
app_label = "test"
|
||||||
|
|
||||||
graphene_type = convert_django_field_with_choices(
|
graphene_type = convert_django_field_with_choices(
|
||||||
field,
|
field, convert_choices_to_enum=False
|
||||||
convert_choices_to_enum=False
|
|
||||||
)
|
)
|
||||||
assert isinstance(graphene_type, graphene.String)
|
assert isinstance(graphene_type, graphene.String)
|
||||||
|
|
||||||
|
|
|
@ -230,13 +230,15 @@ def test_django_objecttype_exclude_fields():
|
||||||
assert "email" not in fields
|
assert "email" not in fields
|
||||||
|
|
||||||
|
|
||||||
class TestDjangoObjectType():
|
class TestDjangoObjectType:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def PetModel(self):
|
def PetModel(self):
|
||||||
class PetModel(models.Model):
|
class PetModel(models.Model):
|
||||||
kind = models.CharField(choices=(('cat', 'Cat'), ('dog', 'Dog')))
|
kind = models.CharField(choices=(("cat", "Cat"), ("dog", "Dog")))
|
||||||
cuteness = models.IntegerField(choices=(
|
cuteness = models.IntegerField(
|
||||||
(1, 'Kind of cute'), (2, 'Pretty cute'), (3, 'OMG SO CUTE!!!')))
|
choices=((1, "Kind of cute"), (2, "Pretty cute"), (3, "OMG SO CUTE!!!"))
|
||||||
|
)
|
||||||
|
|
||||||
return PetModel
|
return PetModel
|
||||||
|
|
||||||
def test_django_objecttype_convert_choices_enum_false(self, PetModel):
|
def test_django_objecttype_convert_choices_enum_false(self, PetModel):
|
||||||
|
@ -250,7 +252,8 @@ class TestDjangoObjectType():
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
assert str(schema) == dedent("""\
|
assert str(schema) == dedent(
|
||||||
|
"""\
|
||||||
schema {
|
schema {
|
||||||
query: Query
|
query: Query
|
||||||
}
|
}
|
||||||
|
@ -264,20 +267,22 @@ class TestDjangoObjectType():
|
||||||
type Query {
|
type Query {
|
||||||
pet: Pet
|
pet: Pet
|
||||||
}
|
}
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
def test_django_objecttype_convert_choices_enum_list(self, PetModel):
|
def test_django_objecttype_convert_choices_enum_list(self, PetModel):
|
||||||
class Pet(DjangoObjectType):
|
class Pet(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PetModel
|
model = PetModel
|
||||||
convert_choices_to_enum = ['kind']
|
convert_choices_to_enum = ["kind"]
|
||||||
|
|
||||||
class Query(ObjectType):
|
class Query(ObjectType):
|
||||||
pet = Field(Pet)
|
pet = Field(Pet)
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
assert str(schema) == dedent("""\
|
assert str(schema) == dedent(
|
||||||
|
"""\
|
||||||
schema {
|
schema {
|
||||||
query: Query
|
query: Query
|
||||||
}
|
}
|
||||||
|
@ -296,4 +301,5 @@ class TestDjangoObjectType():
|
||||||
type Query {
|
type Query {
|
||||||
pet: Pet
|
pet: Pet
|
||||||
}
|
}
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
|
@ -18,8 +18,9 @@ if six.PY3:
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
|
|
||||||
def construct_fields(model, registry, only_fields, exclude_fields,
|
def construct_fields(
|
||||||
convert_choices_to_enum):
|
model, registry, only_fields, exclude_fields, convert_choices_to_enum
|
||||||
|
):
|
||||||
_model_fields = get_model_fields(model)
|
_model_fields = get_model_fields(model)
|
||||||
|
|
||||||
fields = OrderedDict()
|
fields = OrderedDict()
|
||||||
|
@ -44,7 +45,8 @@ def construct_fields(model, registry, only_fields, exclude_fields,
|
||||||
_convert_choices_to_enum = False
|
_convert_choices_to_enum = False
|
||||||
|
|
||||||
converted = convert_django_field_with_choices(
|
converted = convert_django_field_with_choices(
|
||||||
field, registry, convert_choices_to_enum=_convert_choices_to_enum)
|
field, registry, convert_choices_to_enum=_convert_choices_to_enum
|
||||||
|
)
|
||||||
fields[name] = converted
|
fields[name] = converted
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
@ -103,13 +105,9 @@ class DjangoObjectType(ObjectType):
|
||||||
|
|
||||||
django_fields = yank_fields_from_attrs(
|
django_fields = yank_fields_from_attrs(
|
||||||
construct_fields(
|
construct_fields(
|
||||||
model,
|
model, registry, only_fields, exclude_fields, convert_choices_to_enum
|
||||||
registry,
|
|
||||||
only_fields,
|
|
||||||
exclude_fields,
|
|
||||||
convert_choices_to_enum
|
|
||||||
),
|
),
|
||||||
_as=Field
|
_as=Field,
|
||||||
)
|
)
|
||||||
|
|
||||||
if use_connection is None and interfaces:
|
if use_connection is None and interfaces:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user