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

Conversation

ulgens
Copy link
Collaborator

@ulgens ulgens commented Dec 30, 2020

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.

… its TestCase class. This allows GraphQL tests to make use of the stateful client methods like login()
@ulgens ulgens self-assigned this Dec 30, 2020
@ulgens ulgens changed the title Use the Django Client test utility instance that Django provides with… Use the Django TestCase's Client Dec 30, 2020
@@ -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.

@ulgens ulgens requested a review from zbyte64 December 30, 2020 03:09
graphql_url=self.GRAPHQL_URL,
)

@property
def _client(self):
Copy link
Collaborator Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sensible.

@ulgens ulgens force-pushed the use-djangos-testcase-client branch from f0de876 to 6b8a550 Compare December 30, 2020 03:31
@@ -0,0 +1,24 @@
import pytest
Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@zbyte64 zbyte64 left a 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
Copy link
Collaborator

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants