Skip to content

Fix test Client headers for Django 4.2 #1465

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

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion graphene_django/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.test import Client, TestCase, TransactionTestCase

from graphene_django.settings import graphene_settings
from graphene_django.utils.utils import _DJANGO_VERSION_AT_LEAST_4_2

DEFAULT_GRAPHQL_URL = "/graphql"

Expand Down Expand Up @@ -55,8 +56,14 @@ def graphql_query(
else:
body["variables"] = {"input": input_data}
if headers:
header_params = (
{"headers": headers} if _DJANGO_VERSION_AT_LEAST_4_2 else headers
)
resp = client.post(
graphql_url, json.dumps(body), content_type="application/json", **headers
graphql_url,
json.dumps(body),
content_type="application/json",
**header_params
)
else:
resp = client.post(
Expand Down
6 changes: 6 additions & 0 deletions graphene_django/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect

import django
from django.db import connection, models, transaction
from django.db.models.manager import Manager
from django.utils.encoding import force_str
Expand Down Expand Up @@ -145,3 +146,8 @@ def bypass_get_queryset(resolver):
"""
resolver._bypass_get_queryset = True
return resolver


_DJANGO_VERSION_AT_LEAST_4_2 = django.VERSION[0] > 4 or (
django.VERSION[0] >= 4 and django.VERSION[1] >= 2
)