From fcce1a30e5099e287f8984db7b3e1add206dc415 Mon Sep 17 00:00:00 2001 From: AjmalPonneth Date: Wed, 23 Aug 2023 00:09:46 +0530 Subject: [PATCH 1/2] add test case for context --- graphene/types/tests/test_context.py | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 graphene/types/tests/test_context.py diff --git a/graphene/types/tests/test_context.py b/graphene/types/tests/test_context.py new file mode 100644 index 00000000..97d6965a --- /dev/null +++ b/graphene/types/tests/test_context.py @@ -0,0 +1,42 @@ +from ..context import Context +from ..objecttype import ObjectType +from ..scalars import String +from ..schema import Schema + + +class Query(ObjectType): + hello = String() + + def resolve_hello(self, info): + assert isinstance(info.context, Context) + assert hasattr(info.context, "loaders") + assert hasattr(info.context, "request") + return "World" + + +test_schema = Schema(query=Query) + + +def test_context_with_kwargs(): + + class Request: + pass + + class Loader: + pass + + context = Context(loaders=Loader, request=Request) + test_schema.execute("{hello}", context) + + +def text_context_with_dict(): + + class Request: + pass + + class Loader: + pass + + context_dict = {"loader": Loader, "request": Request} + context = Context(**context_dict) + test_schema.execute("{hello}", context) From 892ed4934aca98abeffe13a16c393c29ef6733fb Mon Sep 17 00:00:00 2001 From: AjmalPonneth Date: Wed, 23 Aug 2023 00:15:27 +0530 Subject: [PATCH 2/2] run black --- graphene/types/tests/test_context.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/graphene/types/tests/test_context.py b/graphene/types/tests/test_context.py index 97d6965a..87be2539 100644 --- a/graphene/types/tests/test_context.py +++ b/graphene/types/tests/test_context.py @@ -18,7 +18,6 @@ def resolve_hello(self, info): def test_context_with_kwargs(): - class Request: pass @@ -30,7 +29,6 @@ class Loader: def text_context_with_dict(): - class Request: pass