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:
Tom Nightingale 2020-02-26 17:04:58 -08:00
parent aeb04d5b5c
commit 7ac0e82176

View File

@ -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