mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-26 12:03:47 +03:00
Merge branch 'permission-to-type#5' of github.com:revolico/graphene-django into permission-to-type#5
This commit is contained in:
commit
ece1677cb2
|
@ -103,7 +103,7 @@ class DjangoFormMutation(BaseDjangoFormMutation):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass_with_meta__(
|
def __init_subclass_with_meta__(
|
||||||
cls, form_class=None, only_fields=(), exclude_fields=(), **options
|
cls, form_class=None, mirror_input=False, only_fields=(), exclude_fields=(), **options
|
||||||
):
|
):
|
||||||
|
|
||||||
if not form_class:
|
if not form_class:
|
||||||
|
@ -111,7 +111,10 @@ class DjangoFormMutation(BaseDjangoFormMutation):
|
||||||
|
|
||||||
form = form_class()
|
form = form_class()
|
||||||
input_fields = fields_for_form(form, only_fields, exclude_fields)
|
input_fields = fields_for_form(form, only_fields, exclude_fields)
|
||||||
|
if mirror_input:
|
||||||
output_fields = fields_for_form(form, only_fields, exclude_fields)
|
output_fields = fields_for_form(form, only_fields, exclude_fields)
|
||||||
|
else:
|
||||||
|
output_fields = {}
|
||||||
|
|
||||||
_meta = DjangoFormMutationOptions(cls)
|
_meta = DjangoFormMutationOptions(cls)
|
||||||
_meta.form_class = form_class
|
_meta.form_class = form_class
|
||||||
|
|
|
@ -139,3 +139,36 @@ class ModelFormMutationTests(TestCase):
|
||||||
self.assertEqual(result.errors[0].messages, ["This field is required."])
|
self.assertEqual(result.errors[0].messages, ["This field is required."])
|
||||||
self.assertIn("age", fields_w_error)
|
self.assertIn("age", fields_w_error)
|
||||||
self.assertEqual(result.errors[1].messages, ["This field is required."])
|
self.assertEqual(result.errors[1].messages, ["This field is required."])
|
||||||
|
|
||||||
|
|
||||||
|
class FormMutationTests(TestCase):
|
||||||
|
def test_default_meta_fields(self):
|
||||||
|
class MyMutation(DjangoFormMutation):
|
||||||
|
class Meta:
|
||||||
|
form_class = MyForm
|
||||||
|
self.assertNotIn("text", MyMutation._meta.fields)
|
||||||
|
|
||||||
|
def test_mirror_meta_fields(self):
|
||||||
|
class MyMutation(DjangoFormMutation):
|
||||||
|
class Meta:
|
||||||
|
form_class = MyForm
|
||||||
|
mirror_input = True
|
||||||
|
|
||||||
|
self.assertIn("text", MyMutation._meta.fields)
|
||||||
|
|
||||||
|
def test_default_input_meta_fields(self):
|
||||||
|
class MyMutation(DjangoFormMutation):
|
||||||
|
class Meta:
|
||||||
|
form_class = MyForm
|
||||||
|
|
||||||
|
self.assertIn("client_mutation_id", MyMutation.Input._meta.fields)
|
||||||
|
self.assertIn("text", MyMutation.Input._meta.fields)
|
||||||
|
|
||||||
|
def test_exclude_fields_input_meta_fields(self):
|
||||||
|
class MyMutation(DjangoFormMutation):
|
||||||
|
class Meta:
|
||||||
|
form_class = MyForm
|
||||||
|
exclude_fields = ['text']
|
||||||
|
|
||||||
|
self.assertNotIn("text", MyMutation.Input._meta.fields)
|
||||||
|
self.assertIn("client_mutation_id", MyMutation.Input._meta.fields)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user