Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for non null in custom erros
fowczarekf1205911d5fe
diff --git a/tests/api/test_base_mutation.py b/tests/api/test_base_mutation.pyindex ffdc60c0bd..7e3454a0b3 100644--- a/tests/api/test_base_mutation.py+++ b/tests/api/test_base_mutation.py@@ -1,3 +1,4 @@+from enum import Enumfrom unittest.mock import Mockimport graphene@@ -5,6 +6,7 @@ import pytestfrom django.core.exceptions import ImproperlyConfiguredfrom saleor.graphql.core.mutations import BaseMutation+from saleor.graphql.core.types.common import Errorfrom 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!) {