mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-25 19:43:51 +03:00
Merge pull request #16 from revolico/form-error-field-in-camel-case#15
Form error field in camel case#15
This commit is contained in:
commit
dd3cc6889d
|
@ -11,6 +11,7 @@ from graphene.types.mutation import MutationOptions
|
||||||
# InputObjectType,
|
# InputObjectType,
|
||||||
# )
|
# )
|
||||||
from graphene.types.utils import yank_fields_from_attrs
|
from graphene.types.utils import yank_fields_from_attrs
|
||||||
|
from graphene.utils.str_converters import to_camel_case
|
||||||
from graphene_django.registry import get_global_registry
|
from graphene_django.registry import get_global_registry
|
||||||
|
|
||||||
from .converter import convert_form_field_with_choices
|
from .converter import convert_form_field_with_choices
|
||||||
|
@ -46,7 +47,7 @@ class BaseDjangoFormMutation(ClientIDMutation):
|
||||||
return cls.perform_mutate(form, info)
|
return cls.perform_mutate(form, info)
|
||||||
else:
|
else:
|
||||||
errors = [
|
errors = [
|
||||||
ErrorType(field=key, messages=value)
|
ErrorType(field=to_camel_case(key), messages=value)
|
||||||
for key, value in form.errors.items()
|
for key, value in form.errors.items()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ class PetForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Pet
|
model = Pet
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
test_camel = forms.IntegerField(required=False)
|
||||||
|
|
||||||
|
|
||||||
def test_needs_form_class():
|
def test_needs_form_class():
|
||||||
|
@ -127,18 +128,20 @@ class ModelFormMutationTests(TestCase):
|
||||||
class Meta:
|
class Meta:
|
||||||
form_class = PetForm
|
form_class = PetForm
|
||||||
|
|
||||||
result = PetMutation.mutate_and_get_payload(None, None)
|
result = PetMutation.mutate_and_get_payload(None, None, test_camel='text')
|
||||||
|
|
||||||
# A pet was not created
|
# A pet was not created
|
||||||
self.assertEqual(Pet.objects.count(), 0)
|
self.assertEqual(Pet.objects.count(), 0)
|
||||||
|
|
||||||
|
|
||||||
fields_w_error = [e.field for e in result.errors]
|
fields_w_error = [e.field for e in result.errors]
|
||||||
self.assertEqual(len(result.errors), 2)
|
self.assertEqual(len(result.errors), 3)
|
||||||
|
self.assertIn("testCamel", fields_w_error)
|
||||||
|
self.assertEqual(result.errors[0].messages, ["Enter a whole number."])
|
||||||
self.assertIn("name", fields_w_error)
|
self.assertIn("name", fields_w_error)
|
||||||
self.assertEqual(result.errors[0].messages, ["This field is required."])
|
|
||||||
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."])
|
||||||
|
self.assertIn("age", fields_w_error)
|
||||||
|
self.assertEqual(result.errors[2].messages, ["This field is required."])
|
||||||
|
|
||||||
|
|
||||||
class FormMutationTests(TestCase):
|
class FormMutationTests(TestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user