mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
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 <3097061+firaskafri@users.noreply.github.com>
This commit is contained in:
parent
c697e5c8c1
commit
bb03306075
|
@ -189,7 +189,7 @@ Default: ``None``
|
||||||
|
|
||||||
|
|
||||||
``GRAPHIQL_HEADER_EDITOR_ENABLED``
|
``GRAPHIQL_HEADER_EDITOR_ENABLED``
|
||||||
---------------------
|
----------------------------------
|
||||||
|
|
||||||
GraphiQL starting from version 1.0.0 allows setting custom headers in similar fashion to query variables.
|
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``
|
``GRAPHIQL_SHOULD_PERSIST_HEADERS``
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ Using unittest
|
||||||
|
|
||||||
If you want to unittest your API calls derive your test case from the class `GraphQLTestCase`.
|
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:
|
Usage:
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ DEFAULTS = {
|
||||||
"GRAPHIQL_HEADER_EDITOR_ENABLED": True,
|
"GRAPHIQL_HEADER_EDITOR_ENABLED": True,
|
||||||
"GRAPHIQL_SHOULD_PERSIST_HEADERS": False,
|
"GRAPHIQL_SHOULD_PERSIST_HEADERS": False,
|
||||||
"ATOMIC_MUTATIONS": False,
|
"ATOMIC_MUTATIONS": False,
|
||||||
|
"TESTING_ENDPOINT": "/graphql",
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|
|
@ -3,6 +3,8 @@ import warnings
|
||||||
|
|
||||||
from django.test import Client, TestCase, TransactionTestCase
|
from django.test import Client, TestCase, TransactionTestCase
|
||||||
|
|
||||||
|
from graphene_django.settings import graphene_settings
|
||||||
|
|
||||||
DEFAULT_GRAPHQL_URL = "/graphql"
|
DEFAULT_GRAPHQL_URL = "/graphql"
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +42,7 @@ def graphql_query(
|
||||||
if client is None:
|
if client is None:
|
||||||
client = Client()
|
client = Client()
|
||||||
if not graphql_url:
|
if not graphql_url:
|
||||||
graphql_url = DEFAULT_GRAPHQL_URL
|
graphql_url = graphene_settings.TESTING_ENDPOINT
|
||||||
|
|
||||||
body = {"query": query}
|
body = {"query": query}
|
||||||
if operation_name:
|
if operation_name:
|
||||||
|
@ -69,7 +71,7 @@ class GraphQLTestMixin(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# URL to graphql endpoint
|
# URL to graphql endpoint
|
||||||
GRAPHQL_URL = DEFAULT_GRAPHQL_URL
|
GRAPHQL_URL = graphene_settings.TESTING_ENDPOINT
|
||||||
|
|
||||||
def query(
|
def query(
|
||||||
self, query, operation_name=None, input_data=None, variables=None, headers=None
|
self, query, operation_name=None, input_data=None, variables=None, headers=None
|
||||||
|
|
|
@ -2,6 +2,7 @@ import pytest
|
||||||
|
|
||||||
from .. import GraphQLTestCase
|
from .. import GraphQLTestCase
|
||||||
from ...tests.test_types import with_local_registry
|
from ...tests.test_types import with_local_registry
|
||||||
|
from ...settings import graphene_settings
|
||||||
from django.test import Client
|
from django.test import Client
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,3 +44,11 @@ def test_graphql_test_case_deprecated_client_setter():
|
||||||
|
|
||||||
with pytest.warns(PendingDeprecationWarning):
|
with pytest.warns(PendingDeprecationWarning):
|
||||||
tc._client = Client()
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user