-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the Django TestCase's Client #1084
Changes from 3 commits
0d28630
d545ad4
8cbadd0
6b8a550
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import json | ||
import warnings | ||
|
||
from django.test import TestCase, Client | ||
from django.test import Client, TestCase | ||
|
||
DEFAULT_GRAPHQL_URL = "/graphql/" | ||
|
||
|
@@ -68,12 +69,6 @@ class GraphQLTestCase(TestCase): | |
# URL to graphql endpoint | ||
GRAPHQL_URL = DEFAULT_GRAPHQL_URL | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(GraphQLTestCase, cls).setUpClass() | ||
|
||
cls._client = Client() | ||
|
||
def query(self, query, op_name=None, input_data=None, variables=None, headers=None): | ||
""" | ||
Args: | ||
|
@@ -99,10 +94,19 @@ def query(self, query, op_name=None, input_data=None, variables=None, headers=No | |
input_data=input_data, | ||
variables=variables, | ||
headers=headers, | ||
client=self._client, | ||
client=self.client, | ||
graphql_url=self.GRAPHQL_URL, | ||
) | ||
|
||
@property | ||
def _client(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming people calling (get attribute) the client with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sensible. |
||
warnings.warn( | ||
"Using `_client` is deprecated in favour of `client`.", | ||
PendingDeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return self.client | ||
|
||
def assertResponseNoErrors(self, resp, msg=None): | ||
""" | ||
Assert that the call went through correctly. 200 means the syntax is ok, if there are no `errors`, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why
.setUpClass
had to be called manually here but for same reason,._pre_setup()
should be called to. Otherwise, Django'sTestCase
doesn't populateTestCase.client
.