Skip to content

Commit

Permalink
test(3276): Add test for views
Browse files Browse the repository at this point in the history
- Add a basic test to see if graphql template is rendering
- Add test for the failed rendering of the setting when overriding the
  template
  • Loading branch information
msopacua committed Dec 6, 2023
1 parent c0d00aa commit fce79ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/django/templates/graphql/graphiql.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script>JSON.parse("{{ SUBSCRIPTION_ENABLED }}")</script>
32 changes: 32 additions & 0 deletions tests/django/test_views.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit fce79ef

Please sign in to comment.