From fce79ef269777b8204a851703496e7982fc49ee2 Mon Sep 17 00:00:00 2001 From: "M.R. Sopacua" <144725145+msopacua@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:31:40 +0100 Subject: [PATCH] test(3276): Add test for views - Add a basic test to see if graphql template is rendering - Add test for the failed rendering of the setting when overriding the template --- tests/django/templates/graphql/graphiql.html | 1 + tests/django/test_views.py | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/django/templates/graphql/graphiql.html create mode 100644 tests/django/test_views.py diff --git a/tests/django/templates/graphql/graphiql.html b/tests/django/templates/graphql/graphiql.html new file mode 100644 index 0000000000..29d67b5636 --- /dev/null +++ b/tests/django/templates/graphql/graphiql.html @@ -0,0 +1 @@ + diff --git a/tests/django/test_views.py b/tests/django/test_views.py new file mode 100644 index 0000000000..585062f887 --- /dev/null +++ b/tests/django/test_views.py @@ -0,0 +1,32 @@ +from pathlib import Path + +from django.http import HttpResponse +from django.test import Client, override_settings + +BASE_DIR = Path(__file__).parent +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [BASE_DIR / "templates"], + "APP_DIRS": True, + } +] + + +def test_render_graphiql_template(): + headers = { + "Accept": "text/html", + } + client = Client(headers=headers) + response: HttpResponse = client.get("/graphql/") + assert 'JSON.parse("false")' in response.content.decode() + + +@override_settings(TEMPLATES=TEMPLATES) +def test_subscription_enabled_not_empty(): + headers = { + "Accept": "text/html", + } + client = Client(headers=headers) + response: HttpResponse = client.get("/graphql/") + assert 'JSON.parse("false")' in response.content.decode()