From 2bb198db5cde0c856d9469e7bbbaafd227c396be Mon Sep 17 00:00:00 2001 From: Syberen Date: Sun, 24 Jan 2021 08:24:50 +0100 Subject: [PATCH 1/5] Import testing endpoint from graphene settings --- graphene_django/settings.py | 1 + graphene_django/utils/testing.py | 6 +++--- graphene_django/utils/tests/test_testing.py | 14 +++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/graphene_django/settings.py b/graphene_django/settings.py index c48712362..fbdc61f19 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -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: diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 584a08bca..84a8c1ad9 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -3,7 +3,7 @@ from django.test import Client, TestCase -DEFAULT_GRAPHQL_URL = "/graphql/" +from graphene_django.settings import graphene_settings def graphql_query( @@ -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: @@ -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 diff --git a/graphene_django/utils/tests/test_testing.py b/graphene_django/utils/tests/test_testing.py index 2ef78f99b..a03c8a773 100644 --- a/graphene_django/utils/tests/test_testing.py +++ b/graphene_django/utils/tests/test_testing.py @@ -2,9 +2,9 @@ from .. import GraphQLTestCase from ...tests.test_types import with_local_registry +from ...settings import graphene_settings from django.test import Client - @with_local_registry def test_graphql_test_case_deprecated_client_getter(): """ @@ -43,3 +43,15 @@ 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 + + + + From ec0acb5a845a8646e6b9ce95e1dea6fc7238cd97 Mon Sep 17 00:00:00 2001 From: Syberen Date: Sun, 24 Jan 2021 08:38:30 +0100 Subject: [PATCH 2/5] Add documentation for TESTING_ENDPOINT setting --- docs/settings.rst | 16 +++++++++++++++- docs/testing.rst | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index ff1c05e3b..fa02347a8 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. @@ -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' + } \ No newline at end of file diff --git a/docs/testing.rst b/docs/testing.rst index c24f7c448..df73e05dd 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: From 2b870a89e5548fd56263f324dd4029ce7c085cff Mon Sep 17 00:00:00 2001 From: Syberen Date: Sun, 24 Jan 2021 08:42:29 +0100 Subject: [PATCH 3/5] Remove empty lines --- graphene_django/utils/tests/test_testing.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/graphene_django/utils/tests/test_testing.py b/graphene_django/utils/tests/test_testing.py index a03c8a773..97d088c60 100644 --- a/graphene_django/utils/tests/test_testing.py +++ b/graphene_django/utils/tests/test_testing.py @@ -51,7 +51,3 @@ def test_graphql_test_case_imports_endpoint(): """ assert GraphQLTestCase.GRAPHQL_URL == graphene_settings.TESTING_ENDPOINT - - - - From c273f6c5e41de6c3c65d96442d066fe2dcb6ae01 Mon Sep 17 00:00:00 2001 From: Syberen Date: Sun, 31 Jan 2021 10:24:52 +0100 Subject: [PATCH 4/5] Run formatter --- graphene_django/settings.py | 2 +- graphene_django/utils/tests/test_testing.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/graphene_django/settings.py b/graphene_django/settings.py index fbdc61f19..a0a7b3d6b 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -45,7 +45,7 @@ # https://github.com/graphql/graphiql/tree/main/packages/graphiql#options "GRAPHIQL_HEADER_EDITOR_ENABLED": True, "ATOMIC_MUTATIONS": False, - "TESTING_ENDPOINT": "/graphql" + "TESTING_ENDPOINT": "/graphql", } if settings.DEBUG: diff --git a/graphene_django/utils/tests/test_testing.py b/graphene_django/utils/tests/test_testing.py index 97d088c60..de5615859 100644 --- a/graphene_django/utils/tests/test_testing.py +++ b/graphene_django/utils/tests/test_testing.py @@ -5,6 +5,7 @@ from ...settings import graphene_settings from django.test import Client + @with_local_registry def test_graphql_test_case_deprecated_client_getter(): """ From cc7508cf197d3b73832113dccb3752e2fc4f52bb Mon Sep 17 00:00:00 2001 From: Firas Kafri Date: Mon, 26 Sep 2022 01:53:45 +0300 Subject: [PATCH 5/5] reformat --- graphene_django/utils/testing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 63d41fa0b..ca0d18506 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -4,8 +4,10 @@ from django.test import Client, TestCase, TransactionTestCase from graphene_django.settings import graphene_settings + DEFAULT_GRAPHQL_URL = "/graphql" + def graphql_query( query, operation_name=None,