Skip to content
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

Merged
merged 4 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions graphene_django/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def runTest(self):
pass

tc = TestClass()
tc._pre_setup()
tc.setUpClass()
Copy link
Collaborator Author

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's TestCase doesn't populate TestCase.client.


tc.query("query { }", op_name="QueryName")
body = json.loads(post_mock.call_args.args[1])
# `operationName` field from https://graphql.org/learn/serving-over-http/#post-request
Expand Down
8 changes: 1 addition & 7 deletions graphene_django/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,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:
Expand All @@ -99,7 +93,7 @@ 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,
)

Expand Down