Switch operation_name to operationName in GraphQLTestCase (#936)

* Add op_name test

* Replace "operation_name" with "operationName"

* Improve test comments

* Add method for Python 2.7
This commit is contained in:
Noelle Leigh 2020-04-19 16:11:33 -04:00 committed by GitHub
parent 23b6419b42
commit dc5c971498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 5 deletions

View File

@ -1,6 +1,10 @@
from django.utils.translation import gettext_lazy
import json
from ..utils import camelize, get_model_fields
import pytest
from django.utils.translation import gettext_lazy
from mock import patch
from ..utils import camelize, get_model_fields, GraphQLTestCase
from .models import Film, Reporter
@ -30,3 +34,27 @@ def test_camelize():
"valueA": "value_b"
}
assert camelize({0: {"field_a": ["errors"]}}) == {0: {"fieldA": ["errors"]}}
@pytest.mark.django_db
@patch("graphene_django.utils.testing.Client.post")
def test_graphql_test_case_op_name(post_mock):
"""
Test that `GraphQLTestCase.query()`'s `op_name` argument produces an `operationName` field.
"""
class TestClass(GraphQLTestCase):
GRAPHQL_SCHEMA = True
def runTest(self):
pass
tc = TestClass()
tc.setUpClass()
tc.query("query { }", op_name="QueryName")
body = json.loads(post_mock.call_args.args[1])
# `operationName` field from https://graphql.org/learn/serving-over-http/#post-request
assert (
"operationName",
"QueryName",
) in body.items(), "Field 'operationName' is not present in the final request."

View File

@ -45,7 +45,7 @@ class GraphQLTestCase(TestCase):
"""
body = {"query": query}
if op_name:
body["operation_name"] = op_name
body["operationName"] = op_name
if variables:
body["variables"] = variables
if input_data: