Skip to content

Commit e24675e

Browse files
authored
Fix backward compability on GraphQLTestCase._client setter (#1093)
1 parent aff56b8 commit e24675e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

graphene_django/utils/testing.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ def query(self, query, op_name=None, input_data=None, variables=None, headers=No
9999
)
100100

101101
@property
102+
def _client(self):
103+
pass
104+
105+
@_client.getter
102106
def _client(self):
103107
warnings.warn(
104108
"Using `_client` is deprecated in favour of `client`.",
@@ -107,6 +111,15 @@ def _client(self):
107111
)
108112
return self.client
109113

114+
@_client.setter
115+
def _client(self, client):
116+
warnings.warn(
117+
"Using `_client` is deprecated in favour of `client`.",
118+
PendingDeprecationWarning,
119+
stacklevel=2,
120+
)
121+
self.client = client
122+
110123
def assertResponseNoErrors(self, resp, msg=None):
111124
"""
112125
Assert that the call went through correctly. 200 means the syntax is ok, if there are no `errors`,

graphene_django/utils/tests/test_testing.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
from .. import GraphQLTestCase
44
from ...tests.test_types import with_local_registry
5+
from django.test import Client
56

67

78
@with_local_registry
8-
def test_graphql_test_case_deprecated_client():
9+
def test_graphql_test_case_deprecated_client_getter():
910
"""
10-
Test that `GraphQLTestCase._client`'s should raise pending deprecation warning.
11+
`GraphQLTestCase._client`' getter should raise pending deprecation warning.
1112
"""
1213

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

2324
with pytest.warns(PendingDeprecationWarning):
2425
tc._client
26+
27+
28+
@with_local_registry
29+
def test_graphql_test_case_deprecated_client_setter():
30+
"""
31+
`GraphQLTestCase._client`' setter should raise pending deprecation warning.
32+
"""
33+
34+
class TestClass(GraphQLTestCase):
35+
GRAPHQL_SCHEMA = True
36+
37+
def runTest(self):
38+
pass
39+
40+
tc = TestClass()
41+
tc._pre_setup()
42+
tc.setUpClass()
43+
44+
with pytest.warns(PendingDeprecationWarning):
45+
tc._client = Client()

0 commit comments

Comments
 (0)