Skip to content

Commit bb03306

Browse files
syberenfiraskafri
andauthored
Move testing endpoint to settings (#1105)
* Import testing endpoint from graphene settings * Add documentation for TESTING_ENDPOINT setting * Remove empty lines * Run formatter Co-authored-by: Firas K <[email protected]>
1 parent c697e5c commit bb03306

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

Diff for: docs/settings.rst

+15-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Default: ``None``
189189
190190
191191
``GRAPHIQL_HEADER_EDITOR_ENABLED``
192-
---------------------
192+
----------------------------------
193193

194194
GraphiQL starting from version 1.0.0 allows setting custom headers in similar fashion to query variables.
195195

@@ -209,6 +209,20 @@ Default: ``True``
209209
}
210210
211211
212+
``TESTING_ENDPOINT``
213+
--------------------
214+
215+
Define the graphql endpoint url used for the `GraphQLTestCase` class.
216+
217+
Default: ``/graphql``
218+
219+
.. code:: python
220+
221+
GRAPHENE = {
222+
'TESTING_ENDPOINT': '/customEndpoint'
223+
}
224+
225+
212226
``GRAPHIQL_SHOULD_PERSIST_HEADERS``
213227
---------------------
214228

Diff for: docs/testing.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Using unittest
66

77
If you want to unittest your API calls derive your test case from the class `GraphQLTestCase`.
88

9-
Your endpoint is set through the `GRAPHQL_URL` attribute on `GraphQLTestCase`. The default endpoint is `GRAPHQL_URL = "/graphql/"`.
9+
The default endpoint for testing is `/graphql`. You can override this in the `settings <https://docs.graphene-python.org/projects/django/en/latest/settings/#testing-endpoint>`__.
10+
1011

1112
Usage:
1213

Diff for: graphene_django/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"GRAPHIQL_HEADER_EDITOR_ENABLED": True,
4444
"GRAPHIQL_SHOULD_PERSIST_HEADERS": False,
4545
"ATOMIC_MUTATIONS": False,
46+
"TESTING_ENDPOINT": "/graphql",
4647
}
4748

4849
if settings.DEBUG:

Diff for: graphene_django/utils/testing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from django.test import Client, TestCase, TransactionTestCase
55

6+
from graphene_django.settings import graphene_settings
7+
68
DEFAULT_GRAPHQL_URL = "/graphql"
79

810

@@ -40,7 +42,7 @@ def graphql_query(
4042
if client is None:
4143
client = Client()
4244
if not graphql_url:
43-
graphql_url = DEFAULT_GRAPHQL_URL
45+
graphql_url = graphene_settings.TESTING_ENDPOINT
4446

4547
body = {"query": query}
4648
if operation_name:
@@ -69,7 +71,7 @@ class GraphQLTestMixin(object):
6971
"""
7072

7173
# URL to graphql endpoint
72-
GRAPHQL_URL = DEFAULT_GRAPHQL_URL
74+
GRAPHQL_URL = graphene_settings.TESTING_ENDPOINT
7375

7476
def query(
7577
self, query, operation_name=None, input_data=None, variables=None, headers=None

Diff for: graphene_django/utils/tests/test_testing.py

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

78

@@ -43,3 +44,11 @@ def runTest(self):
4344

4445
with pytest.warns(PendingDeprecationWarning):
4546
tc._client = Client()
47+
48+
49+
def test_graphql_test_case_imports_endpoint():
50+
"""
51+
GraphQLTestCase class should import the default endpoint from settings file
52+
"""
53+
54+
assert GraphQLTestCase.GRAPHQL_URL == graphene_settings.TESTING_ENDPOINT

0 commit comments

Comments
 (0)