mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-11 16:52:25 +03:00
Use the Django Client test utility instance that Django provides with its TestCase class. This allows GraphQL tests to make use of the stateful client methods like login()
This commit is contained in:
parent
aeb04d5b5c
commit
7ac0e82176
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.test import TestCase, Client
|
from django.test import Client, TestCase
|
||||||
|
|
||||||
|
|
||||||
class GraphQLTestCase(TestCase):
|
class GraphQLTestCase(TestCase):
|
||||||
|
@ -22,8 +22,6 @@ class GraphQLTestCase(TestCase):
|
||||||
"Variable GRAPHQL_SCHEMA not defined in GraphQLTestCase."
|
"Variable GRAPHQL_SCHEMA not defined in GraphQLTestCase."
|
||||||
)
|
)
|
||||||
|
|
||||||
cls._client = Client()
|
|
||||||
|
|
||||||
def query(self, query, op_name=None, input_data=None, variables=None, headers=None):
|
def query(self, query, op_name=None, input_data=None, variables=None, headers=None):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
|
@ -54,14 +52,14 @@ class GraphQLTestCase(TestCase):
|
||||||
else:
|
else:
|
||||||
body["variables"] = {"input": input_data}
|
body["variables"] = {"input": input_data}
|
||||||
if headers:
|
if headers:
|
||||||
resp = self._client.post(
|
resp = self.client.post(
|
||||||
self.GRAPHQL_URL,
|
self.GRAPHQL_URL,
|
||||||
json.dumps(body),
|
json.dumps(body),
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
**headers
|
**headers
|
||||||
)
|
)
|
||||||
else:
|
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"
|
||||||
)
|
)
|
||||||
return resp
|
return resp
|
||||||
|
|
Loading…
Reference in New Issue
Block a user