Skip to content

Commit b66a3f3

Browse files
chibiejkimbo
andcommitted
Add headers arg to GraphQLTestCase.query (#827)
* Add headers arg to GraphQLTestCase.query * fix headers NoneType case in GraphQLTestCase.query * Run format Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
1 parent 968002f commit b66a3f3

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

graphene_django/utils/testing.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setUpClass(cls):
2424

2525
cls._client = Client()
2626

27-
def query(self, query, op_name=None, input_data=None, variables=None):
27+
def query(self, query, op_name=None, input_data=None, variables=None, headers=None):
2828
"""
2929
Args:
3030
query (string) - GraphQL query to run
@@ -36,7 +36,9 @@ def query(self, query, op_name=None, input_data=None, variables=None):
3636
are provided, the ``input`` field in the ``variables``
3737
dict will be overwritten with this value.
3838
variables (dict) - If provided, the "variables" field in GraphQL will be
39-
set to this value.
39+
set to this value.
40+
headers (dict) - If provided, the headers in POST request to GRAPHQL_URL
41+
will be set to this value.
4042
4143
Returns:
4244
Response object from client
@@ -51,10 +53,17 @@ def query(self, query, op_name=None, input_data=None, variables=None):
5153
body["variables"]["input"] = input_data
5254
else:
5355
body["variables"] = {"input": input_data}
54-
55-
resp = self._client.post(
56-
self.GRAPHQL_URL, json.dumps(body), content_type="application/json"
57-
)
56+
if headers:
57+
resp = self._client.post(
58+
self.GRAPHQL_URL,
59+
json.dumps(body),
60+
content_type="application/json",
61+
**headers
62+
)
63+
else:
64+
resp = self._client.post(
65+
self.GRAPHQL_URL, json.dumps(body), content_type="application/json"
66+
)
5867
return resp
5968

6069
def assertResponseNoErrors(self, resp):

0 commit comments

Comments
 (0)