def test_mutation_error_camelcased(graphene_settings): class ExtraPetForm(PetForm): test_field = forms.CharField(required=True) class PetType(DjangoObjectType): class Meta: model = Pet fields = "__all__" class PetMutation(DjangoModelFormMutation): pet = Field(PetType) class Meta: form_class = ExtraPetForm result = PetMutation.mutate_and_get_payload(None, None) assert {f.field for f in result.errors} == {"name", "age", "test_field"} graphene_settings.CAMELCASE_ERRORS = True result = PetMutation.mutate_and_get_payload(None, None) assert {f.field for f in result.errors} == {"name", "age", "testField"}
def test_model_form_mutation_mutate_invalid_form(): result = PetMutation.mutate_and_get_payload(None, None) # A pet was not created Pet.objects.count() == 0 fields_w_error = [e.field for e in result.errors] assert len(result.errors) == 2 assert result.errors[0].messages == ["This field is required."] assert result.errors[1].messages == ["This field is required."] assert "age" in fields_w_error assert "name" in fields_w_error
class Mutation(ObjectType): pet_mutation = PetMutation.Field()