Skip to content

Commit e8f36b0

Browse files
authored
Fix test Client headers for Django 4.2 (#1465)
* Fix test Client headers for Django 4.2 * Lazy import pkg_resources since it could be quite heavy * Remove use of pkg_resources altogether
1 parent 83d3d27 commit e8f36b0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

graphene_django/utils/testing.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.test import Client, TestCase, TransactionTestCase
55

66
from graphene_django.settings import graphene_settings
7+
from graphene_django.utils.utils import _DJANGO_VERSION_AT_LEAST_4_2
78

89
DEFAULT_GRAPHQL_URL = "/graphql"
910

@@ -55,8 +56,14 @@ def graphql_query(
5556
else:
5657
body["variables"] = {"input": input_data}
5758
if headers:
59+
header_params = (
60+
{"headers": headers} if _DJANGO_VERSION_AT_LEAST_4_2 else headers
61+
)
5862
resp = client.post(
59-
graphql_url, json.dumps(body), content_type="application/json", **headers
63+
graphql_url,
64+
json.dumps(body),
65+
content_type="application/json",
66+
**header_params
6067
)
6168
else:
6269
resp = client.post(

graphene_django/utils/utils.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22

3+
import django
34
from django.db import connection, models, transaction
45
from django.db.models.manager import Manager
56
from django.utils.encoding import force_str
@@ -145,3 +146,8 @@ def bypass_get_queryset(resolver):
145146
"""
146147
resolver._bypass_get_queryset = True
147148
return resolver
149+
150+
151+
_DJANGO_VERSION_AT_LEAST_4_2 = django.VERSION[0] > 4 or (
152+
django.VERSION[0] >= 4 and django.VERSION[1] >= 2
153+
)

0 commit comments

Comments
 (0)