From 18cd3451f9715f3db900a64fd288b00b6706c003 Mon Sep 17 00:00:00 2001 From: Aryan Iyappan <69184573+codebyaryan@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:59:38 +0530 Subject: [PATCH] Update test_schema.py --- graphene/types/tests/test_schema.py | 119 +--------------------------- 1 file changed, 1 insertion(+), 118 deletions(-) diff --git a/graphene/types/tests/test_schema.py b/graphene/types/tests/test_schema.py index f84d2e20..9cdbde3b 100644 --- a/graphene/types/tests/test_schema.py +++ b/graphene/types/tests/test_schema.py @@ -7,7 +7,7 @@ from graphene.tests.utils import dedent from ..field import Field from ..objecttype import ObjectType from ..scalars import String -from ..schema import Schema, UnforgivingExecutionContext +from ..schema import Schema class MyOtherType(ObjectType): @@ -69,120 +69,3 @@ def test_schema_requires_query_type(): assert len(result.errors) == 1 error = result.errors[0] assert error.message == "Query root type must be provided." - - -class TestUnforgivingExecutionContext: - @fixture - def schema(self): - class ErrorFieldsMixin: - sanity_field = String() - expected_error_field = String() - unexpected_value_error_field = String() - unexpected_type_error_field = String() - unexpected_attribute_error_field = String() - unexpected_key_error_field = String() - - @staticmethod - def resolve_sanity_field(obj, info): - return "not an error" - - @staticmethod - def resolve_expected_error_field(obj, info): - raise GraphQLError("expected error") - - @staticmethod - def resolve_unexpected_value_error_field(obj, info): - raise ValueError("unexpected error") - - @staticmethod - def resolve_unexpected_type_error_field(obj, info): - raise TypeError("unexpected error") - - @staticmethod - def resolve_unexpected_attribute_error_field(obj, info): - raise AttributeError("unexpected error") - - @staticmethod - def resolve_unexpected_key_error_field(obj, info): - return {}["fails"] - - class NestedObject(ErrorFieldsMixin, ObjectType): - pass - - class MyQuery(ErrorFieldsMixin, ObjectType): - nested_object = Field(NestedObject) - nested_object_error = Field(NestedObject) - - @staticmethod - def resolve_nested_object(obj, info): - return object() - - @staticmethod - def resolve_nested_object_error(obj, info): - raise TypeError() - - schema = Schema(query=MyQuery) - return schema - - def test_sanity_check(self, schema): - # this should pass with no errors (sanity check) - result = schema.execute( - "query { sanityField }", - execution_context_class=UnforgivingExecutionContext, - ) - assert not result.errors - assert result.data == {"sanityField": "not an error"} - - def test_nested_sanity_check(self, schema): - # this should pass with no errors (sanity check) - result = schema.execute( - r"query { nestedObject { sanityField } }", - execution_context_class=UnforgivingExecutionContext, - ) - assert not result.errors - assert result.data == {"nestedObject": {"sanityField": "not an error"}} - - def test_graphql_error(self, schema): - result = schema.execute( - "query { expectedErrorField }", - execution_context_class=UnforgivingExecutionContext, - ) - assert len(result.errors) == 1 - assert result.errors[0].message == "expected error" - assert result.data == {"expectedErrorField": None} - - def test_nested_graphql_error(self, schema): - result = schema.execute( - r"query { nestedObject { expectedErrorField } }", - execution_context_class=UnforgivingExecutionContext, - ) - assert len(result.errors) == 1 - assert result.errors[0].message == "expected error" - assert result.data == {"nestedObject": {"expectedErrorField": None}} - - @mark.parametrize( - "field,exception", - [ - ("unexpectedValueErrorField", ValueError), - ("unexpectedTypeErrorField", TypeError), - ("unexpectedAttributeErrorField", AttributeError), - ("unexpectedKeyErrorField", KeyError), - ("nestedObject { unexpectedValueErrorField }", ValueError), - ("nestedObject { unexpectedTypeErrorField }", TypeError), - ("nestedObject { unexpectedAttributeErrorField }", AttributeError), - ("nestedObject { unexpectedKeyErrorField }", KeyError), - ("nestedObjectError { __typename }", TypeError), - ], - ) - def test_unexpected_error(self, field, exception, schema): - # FIXME: tests are failing currently because no exception - # is being raised below. Instead, the errors are being propagated - # to the `errors` array of the response. If this is intended - # behaviour, we need to check if the error exists in the `errors` - # array rather than checking if an exception is raised. - with raises(exception): - # no result, but the exception should be propagated - schema.execute( - f"query {{ {field} }}", - execution_context_class=UnforgivingExecutionContext, - )