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

Move testing endpoint to settings #1105

Merged
merged 7 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -207,3 +207,17 @@ Default: ``True``
GRAPHENE = {
'GRAPHIQL_HEADER_EDITOR_ENABLED': True,
}


``TESTING_ENDPOINT``
--------------------

Define the graphql endpoint url used for the `GraphQLTestCase` class.

Default: ``/graphql``

.. code:: python

GRAPHENE = {
'TESTING_ENDPOINT': '/customEndpoint'
}
3 changes: 2 additions & 1 deletion docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.graphene-python.org/projects/django/en/latest/settings/#testing-endpoint>`__.


Usage:

Expand Down
1 change: 1 addition & 0 deletions graphene_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# https://github.com/graphql/graphiql/tree/main/packages/graphiql#options
"GRAPHIQL_HEADER_EDITOR_ENABLED": True,
"ATOMIC_MUTATIONS": False,
"TESTING_ENDPOINT": "/graphql",
}

if settings.DEBUG:
Expand Down
6 changes: 3 additions & 3 deletions graphene_django/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.test import Client, TestCase

DEFAULT_GRAPHQL_URL = "/graphql/"
from graphene_django.settings import graphene_settings


def graphql_query(
Expand Down Expand Up @@ -38,7 +38,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:
Expand Down Expand Up @@ -67,7 +67,7 @@ class GraphQLTestCase(TestCase):
"""

# 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
Expand Down
9 changes: 9 additions & 0 deletions graphene_django/utils/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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