Skip to content

Commit de8b39d

Browse files
committed
✅ Fix usage of mock.call_args.args
Not present before python 3.8
1 parent 9a96ed1 commit de8b39d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

graphene_django/tests/test_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import sys
23

34
import pytest
45
from django.utils.translation import gettext_lazy
@@ -9,6 +10,12 @@
910
from ..utils.testing import graphql_query
1011

1112

13+
def call_args_compat(mock):
14+
if sys.version_info < (3, 8):
15+
setattr(mock.call_args, "args", mock.call_args[0])
16+
return mock.call_args
17+
18+
1219
def test_get_model_fields_no_duplication():
1320
reporter_fields = get_model_fields(Reporter)
1421
reporter_name_set = set([field[0] for field in reporter_fields])
@@ -54,7 +61,7 @@ def runTest(self):
5461
tc._pre_setup()
5562
tc.setUpClass()
5663
tc.query("query { }", operation_name="QueryName")
57-
body = json.loads(post_mock.call_args.args[1])
64+
body = json.loads(call_args_compat(post_mock).args[1])
5865
# `operationName` field from https://graphql.org/learn/serving-over-http/#post-request
5966
assert (
6067
"operationName",
@@ -66,7 +73,7 @@ def runTest(self):
6673
@patch("graphene_django.utils.testing.Client.post")
6774
def test_graphql_query_case_operation_name(post_mock):
6875
graphql_query("query { }", operation_name="QueryName")
69-
body = json.loads(post_mock.call_args.args[1])
76+
body = json.loads(call_args_compat(post_mock).args[1])
7077
# `operationName` field from https://graphql.org/learn/serving-over-http/#post-request
7178
assert (
7279
"operationName",

0 commit comments

Comments
 (0)