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

Fix backward compability on GraphQLTestCase._client setter (v2) #1093

Merged
merged 1 commit into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions graphene_django/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def query(self, query, op_name=None, input_data=None, variables=None, headers=No
)

@property
def _client(self):
pass

@_client.getter
def _client(self):
warnings.warn(
"Using `_client` is deprecated in favour of `client`.",
Expand All @@ -107,6 +111,15 @@ def _client(self):
)
return self.client

@_client.setter
def _client(self, client):
warnings.warn(
"Using `_client` is deprecated in favour of `client`.",
PendingDeprecationWarning,
stacklevel=2,
)
self.client = 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`,
Expand Down
25 changes: 23 additions & 2 deletions graphene_django/utils/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from .. import GraphQLTestCase
from ...tests.test_types import with_local_registry
from django.test import Client


@with_local_registry
def test_graphql_test_case_deprecated_client():
def test_graphql_test_case_deprecated_client_getter():
"""
Test that `GraphQLTestCase._client`'s should raise pending deprecation warning.
`GraphQLTestCase._client`' getter should raise pending deprecation warning.
"""

class TestClass(GraphQLTestCase):
Expand All @@ -22,3 +23,23 @@ def runTest(self):

with pytest.warns(PendingDeprecationWarning):
tc._client


@with_local_registry
def test_graphql_test_case_deprecated_client_setter():
"""
`GraphQLTestCase._client`' setter should raise pending deprecation warning.
"""

class TestClass(GraphQLTestCase):
GRAPHQL_SCHEMA = True

def runTest(self):
pass

tc = TestClass()
tc._pre_setup()
tc.setUpClass()

with pytest.warns(PendingDeprecationWarning):
tc._client = Client()