mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-12 09:12:18 +03:00
Lint
This commit is contained in:
parent
4246dab3d6
commit
b61ecd88ec
|
@ -104,8 +104,13 @@ class DjangoFormMutation(BaseDjangoFormMutation):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass_with_meta__(
|
def __init_subclass_with_meta__(
|
||||||
cls, form_class=None, only_fields=(), exclude_fields=(),
|
cls,
|
||||||
fields=None, exclude=(), input_fields=None,
|
form_class=None,
|
||||||
|
only_fields=(),
|
||||||
|
exclude_fields=(),
|
||||||
|
fields=None,
|
||||||
|
exclude=(),
|
||||||
|
input_fields=None,
|
||||||
**options
|
**options
|
||||||
):
|
):
|
||||||
|
|
||||||
|
@ -113,28 +118,33 @@ class DjangoFormMutation(BaseDjangoFormMutation):
|
||||||
raise Exception("form_class is required for DjangoFormMutation")
|
raise Exception("form_class is required for DjangoFormMutation")
|
||||||
|
|
||||||
form = form_class()
|
form = form_class()
|
||||||
if (any([fields, exclude, input_fields])
|
if any([fields, exclude, input_fields]) and (only_fields or exclude_fields):
|
||||||
and (only_fields or exclude_fields)):
|
raise Exception(
|
||||||
raise Exception("Cannot specify legacy `only_fields` or `exclude_fields` params with"
|
"Cannot specify legacy `only_fields` or `exclude_fields` params with"
|
||||||
" `only`, `exclude`, or `input_fields` params")
|
" `only`, `exclude`, or `input_fields` params"
|
||||||
|
)
|
||||||
if only_fields or exclude_fields:
|
if only_fields or exclude_fields:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"only_fields/exclude_fields have been deprecated, use "
|
"only_fields/exclude_fields have been deprecated, use "
|
||||||
"input_fields or only/exclude (for output fields)"
|
"input_fields or only/exclude (for output fields)"
|
||||||
"instead",
|
"instead",
|
||||||
DeprecationWarning
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
if not fields or exclude:
|
if not fields or exclude:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"a future version of graphene-django will require fields or exclude."
|
"a future version of graphene-django will require fields or exclude."
|
||||||
" Set fields='__all__' to allow all fields through.",
|
" Set fields='__all__' to allow all fields through.",
|
||||||
DeprecationWarning
|
DeprecationWarning,
|
||||||
)
|
)
|
||||||
if not input_fields and input_fields is not None:
|
if not input_fields and input_fields is not None:
|
||||||
input_fields = {}
|
input_fields = {}
|
||||||
else:
|
else:
|
||||||
input_fields = fields_for_form(form, only_fields or input_fields, exclude_fields)
|
input_fields = fields_for_form(
|
||||||
output_fields = fields_for_form(form, only_fields or fields, exclude_fields or exclude)
|
form, only_fields or input_fields, exclude_fields
|
||||||
|
)
|
||||||
|
output_fields = fields_for_form(
|
||||||
|
form, only_fields or fields, exclude_fields or exclude
|
||||||
|
)
|
||||||
|
|
||||||
_meta = DjangoFormMutationOptions(cls)
|
_meta = DjangoFormMutationOptions(cls)
|
||||||
_meta.form_class = form_class
|
_meta.form_class = form_class
|
||||||
|
|
|
@ -81,6 +81,7 @@ def test_no_input_fields():
|
||||||
class Meta:
|
class Meta:
|
||||||
form_class = MyForm
|
form_class = MyForm
|
||||||
input_fields = []
|
input_fields = []
|
||||||
|
|
||||||
assert set(MyMutation.Input._meta.fields.keys()) == set(["client_mutation_id"])
|
assert set(MyMutation.Input._meta.fields.keys()) == set(["client_mutation_id"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ def test_filtering_input_fields():
|
||||||
form_class = MyForm
|
form_class = MyForm
|
||||||
input_fields = ["text"]
|
input_fields = ["text"]
|
||||||
|
|
||||||
assert "text" in MyMutation.Input._meta.fields
|
assert "text" in MyMutation.Input._meta.fields
|
||||||
assert "another" not in MyMutation.Input._meta.fields
|
assert "another" not in MyMutation.Input._meta.fields
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,6 +100,7 @@ def test_select_output_fields():
|
||||||
class Meta:
|
class Meta:
|
||||||
form_class = MyForm
|
form_class = MyForm
|
||||||
fields = ["text"]
|
fields = ["text"]
|
||||||
|
|
||||||
assert "text" in MyMutation._meta.fields
|
assert "text" in MyMutation._meta.fields
|
||||||
assert "another" not in MyMutation._meta.fields
|
assert "another" not in MyMutation._meta.fields
|
||||||
|
|
||||||
|
@ -106,8 +108,10 @@ def test_select_output_fields():
|
||||||
def test_filtering_output_fields_exclude():
|
def test_filtering_output_fields_exclude():
|
||||||
class FormWithWeirdOutput(MyForm):
|
class FormWithWeirdOutput(MyForm):
|
||||||
"""Weird form that has extra cleaned_data we want to expose"""
|
"""Weird form that has extra cleaned_data we want to expose"""
|
||||||
|
|
||||||
text = forms.CharField()
|
text = forms.CharField()
|
||||||
another = forms.CharField(required=False)
|
another = forms.CharField(required=False)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super(FormWithWeirdOutput, self).clean()
|
super(FormWithWeirdOutput, self).clean()
|
||||||
self.cleaned_data["some_integer"] = 5
|
self.cleaned_data["some_integer"] = 5
|
||||||
|
|
Loading…
Reference in New Issue
Block a user