-
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
Conversation
… its TestCase class. This allows GraphQL tests to make use of the stateful client methods like login()
@@ -51,7 +51,9 @@ def runTest(self): | |||
pass | |||
|
|||
tc = TestClass() | |||
tc._pre_setup() | |||
tc.setUpClass() |
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's TestCase
doesn't populate TestCase.client
.
graphql_url=self.GRAPHQL_URL, | ||
) | ||
|
||
@property | ||
def _client(self): |
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.
Assuming people calling (get attribute) the client with _client
in their tests, including myself, i didn't want to break all at once. But i'm not sure how to handle set attribute case, or does it even necessary.
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.
Sensible.
f0de876
to
6b8a550
Compare
@@ -0,0 +1,24 @@ | |||
import pytest |
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.
Not the best file name obviously 🙃 I'm open for recommendations.
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.
Best I came up with is test_harness, which I didn't think is any better.
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.
👍
@@ -0,0 +1,24 @@ | |||
import pytest |
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.
Best I came up with is test_harness, which I didn't think is any better.
graphql_url=self.GRAPHQL_URL, | ||
) | ||
|
||
@property | ||
def _client(self): |
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.
Sensible.
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()
Updated version of #886, our oldest open PR.