Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add test for non null in custom erros

fowczarekf1205911d5fe
diff --git a/tests/api/test_base_mutation.py b/tests/api/test_base_mutation.py
index ffdc60c0bd..7e3454a0b3 100644
--- a/tests/api/test_base_mutation.py
+++ b/tests/api/test_base_mutation.py
@@ -1,3 +1,4 @@
+from enum import Enum
from unittest.mock import Mock
import graphene
@@ -5,6 +6,7 @@ import pytest
from django.core.exceptions import ImproperlyConfigured
from saleor.graphql.core.mutations import BaseMutation
+from saleor.graphql.core.types.common import Error
from saleor.graphql.product import types as product_types
@@ -25,8 +27,27 @@ class Mutation(BaseMutation):
return Mutation(name=product.name)
+class TestErrorCode(Enum):
+ INVALID = "invalid"
+
+
+TestErrorCode = graphene.Enum.from_enum(TestErrorCode)
+
+
+class TestError(Error):
+ code = TestErrorCode()
+
+
+class MutationWithCustomErrors(Mutation):
+ class Meta:
+ description = "Base mutation with custom errors"
+ error_type_class = Error
+ error_type_field = "custom_errors"
+
+
class Mutations(graphene.ObjectType):
test = Mutation.Field()
+ test_with_custom_errors = MutationWithCustomErrors.Field()
schema = graphene.Schema(
@@ -84,6 +105,29 @@ def test_user_error_nonexistent_id(schema_context):
assert user_errors[0]["message"] == "Couldn't resolve to a node: not-really"
+def test_mutation_custom_errors_default_value(product, schema_context):
+ product_id = graphene.Node.to_global_id("Product", product.pk)
+ query = """
+ mutation testMutation($productId: ID!) {
+ testWithCustomErrors(productId: $productId) {
+ name
+ errors {
+ field
+ message
+ }
+ customErrors {
+ field
+ message
+ }
+ }
+ }
+ """
+ variables = {"productId": product_id}
+ result = schema.execute(query, variables=variables, context_value=schema_context)
+ assert result.data["testWithCustomErrors"]["errors"] == []
+ assert result.data["testWithCustomErrors"]["customErrors"] == []
+
+
def test_user_error_id_of_different_type(product, schema_context):
query = """
mutation testMutation($productId: ID!) {