diff --git a/docs/settings.rst b/docs/settings.rst index 1984a154c..5bffd08f9 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -189,7 +189,7 @@ Default: ``None`` ``GRAPHIQL_HEADER_EDITOR_ENABLED`` ---------------------- +---------------------------------- GraphiQL starting from version 1.0.0 allows setting custom headers in similar fashion to query variables. @@ -209,6 +209,20 @@ Default: ``True`` } +``TESTING_ENDPOINT`` +-------------------- + +Define the graphql endpoint url used for the `GraphQLTestCase` class. + +Default: ``/graphql`` + +.. code:: python + + GRAPHENE = { + 'TESTING_ENDPOINT': '/customEndpoint' + } + + ``GRAPHIQL_SHOULD_PERSIST_HEADERS`` --------------------- diff --git a/docs/testing.rst b/docs/testing.rst index fb0a85dc4..1b3235218 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -6,7 +6,8 @@ Using unittest If you want to unittest your API calls derive your test case from the class `GraphQLTestCase`. -Your endpoint is set through the `GRAPHQL_URL` attribute on `GraphQLTestCase`. The default endpoint is `GRAPHQL_URL = "/graphql/"`. +The default endpoint for testing is `/graphql`. You can override this in the `settings `__. + Usage: diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 0fd70a721..6f6232687 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -43,6 +43,7 @@ "GRAPHIQL_HEADER_EDITOR_ENABLED": True, "GRAPHIQL_SHOULD_PERSIST_HEADERS": False, "ATOMIC_MUTATIONS": False, + "TESTING_ENDPOINT": "/graphql", } if settings.DEBUG: diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index f94c38574..ca0d18506 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -3,6 +3,8 @@ from django.test import Client, TestCase, TransactionTestCase +from graphene_django.settings import graphene_settings + DEFAULT_GRAPHQL_URL = "/graphql" @@ -40,7 +42,7 @@ def graphql_query( if client is None: client = Client() if not graphql_url: - graphql_url = DEFAULT_GRAPHQL_URL + graphql_url = graphene_settings.TESTING_ENDPOINT body = {"query": query} if operation_name: @@ -69,7 +71,7 @@ class GraphQLTestMixin(object): """ # URL to graphql endpoint - GRAPHQL_URL = DEFAULT_GRAPHQL_URL + GRAPHQL_URL = graphene_settings.TESTING_ENDPOINT def query( self, query, operation_name=None, input_data=None, variables=None, headers=None diff --git a/graphene_django/utils/tests/test_testing.py b/graphene_django/utils/tests/test_testing.py index 2ef78f99b..de5615859 100644 --- a/graphene_django/utils/tests/test_testing.py +++ b/graphene_django/utils/tests/test_testing.py @@ -2,6 +2,7 @@ from .. import GraphQLTestCase from ...tests.test_types import with_local_registry +from ...settings import graphene_settings from django.test import Client @@ -43,3 +44,11 @@ def runTest(self): with pytest.warns(PendingDeprecationWarning): tc._client = Client() + + +def test_graphql_test_case_imports_endpoint(): + """ + GraphQLTestCase class should import the default endpoint from settings file + """ + + assert GraphQLTestCase.GRAPHQL_URL == graphene_settings.TESTING_ENDPOINT