mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-12 09:30:35 +03:00
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>
This commit is contained in:
parent
968002f155
commit
b66a3f3479
|
@ -24,7 +24,7 @@ class GraphQLTestCase(TestCase):
|
||||||
|
|
||||||
cls._client = Client()
|
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:
|
Args:
|
||||||
query (string) - GraphQL query to run
|
query (string) - GraphQL query to run
|
||||||
|
@ -37,6 +37,8 @@ class GraphQLTestCase(TestCase):
|
||||||
dict will be overwritten with this value.
|
dict will be overwritten with this value.
|
||||||
variables (dict) - If provided, the "variables" field in GraphQL will be
|
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:
|
Returns:
|
||||||
Response object from client
|
Response object from client
|
||||||
|
@ -51,7 +53,14 @@ class GraphQLTestCase(TestCase):
|
||||||
body["variables"]["input"] = input_data
|
body["variables"]["input"] = input_data
|
||||||
else:
|
else:
|
||||||
body["variables"] = {"input": input_data}
|
body["variables"] = {"input": input_data}
|
||||||
|
if headers:
|
||||||
|
resp = self._client.post(
|
||||||
|
self.GRAPHQL_URL,
|
||||||
|
json.dumps(body),
|
||||||
|
content_type="application/json",
|
||||||
|
**headers
|
||||||
|
)
|
||||||
|
else:
|
||||||
resp = self._client.post(
|
resp = self._client.post(
|
||||||
self.GRAPHQL_URL, json.dumps(body), content_type="application/json"
|
self.GRAPHQL_URL, json.dumps(body), content_type="application/json"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user