From bc20a389362af5b6fa7d2d5df403835df3af47b3 Mon Sep 17 00:00:00 2001 From: "st. chibie" Date: Sat, 14 Dec 2019 18:04:44 +0100 Subject: [PATCH 1/3] Add headers arg to GraphQLTestCase.query --- graphene_django/utils/testing.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 5b694b2a7..89b293ca6 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -24,7 +24,7 @@ def setUpClass(cls): cls._client = Client() - def query(self, query, op_name=None, input_data=None, variables=None): + def query(self, query, op_name=None, input_data=None, variables=None, headers=None): """ Args: query (string) - GraphQL query to run @@ -36,7 +36,9 @@ def query(self, query, op_name=None, input_data=None, variables=None): are provided, the ``input`` field in the ``variables`` dict will be overwritten with this value. variables (dict) - If provided, the "variables" field in GraphQL will be - set to this value. + set to this value. + headers (dict) - If provided, the headers in POST request to GRAPHQL_URL + will be set to this value. Returns: Response object from client @@ -53,7 +55,7 @@ def query(self, query, op_name=None, input_data=None, variables=None): body["variables"] = {"input": input_data} resp = self._client.post( - self.GRAPHQL_URL, json.dumps(body), content_type="application/json" + self.GRAPHQL_URL, json.dumps(body), content_type="application/json", **headers ) return resp From 1b02624cc6d062d69dfea280380ca68e0d512797 Mon Sep 17 00:00:00 2001 From: "st. chibie" Date: Sat, 14 Dec 2019 22:43:04 +0100 Subject: [PATCH 2/3] fix headers NoneType case in GraphQLTestCase.query --- graphene_django/utils/testing.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 89b293ca6..5a020259c 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -53,10 +53,14 @@ def query(self, query, op_name=None, input_data=None, variables=None, headers=No body["variables"]["input"] = input_data else: body["variables"] = {"input": input_data} - - resp = self._client.post( - self.GRAPHQL_URL, json.dumps(body), content_type="application/json", **headers - ) + if headers: + resp = self._client.post( + self.GRAPHQL_URL, json.dumps(body), content_type="application/json", **headers + ) + else: + resp = self._client.post( + self.GRAPHQL_URL, json.dumps(body), content_type="application/json" + ) return resp def assertResponseNoErrors(self, resp): From eabf7595efdcf095023dc439ca21d38950675199 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Thu, 26 Dec 2019 11:37:56 +0000 Subject: [PATCH 3/3] Run format --- graphene_django/utils/testing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 5a020259c..8a9b99483 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -55,7 +55,10 @@ def query(self, query, op_name=None, input_data=None, variables=None, headers=No body["variables"] = {"input": input_data} if headers: resp = self._client.post( - self.GRAPHQL_URL, json.dumps(body), content_type="application/json", **headers + self.GRAPHQL_URL, + json.dumps(body), + content_type="application/json", + **headers ) else: resp = self._client.post(