From a9886d4bb52d4fc96807a7bd0b2dff7eeb3537d7 Mon Sep 17 00:00:00 2001 From: Noelle Leigh Date: Fri, 17 Apr 2020 15:50:35 -0400 Subject: [PATCH] Add op_name test --- graphene_django/tests/test_utils.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/graphene_django/tests/test_utils.py b/graphene_django/tests/test_utils.py index 55cfd4f..e4ff066 100644 --- a/graphene_django/tests/test_utils.py +++ b/graphene_django/tests/test_utils.py @@ -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,23 @@ 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` key. + """ + + class TestClass(GraphQLTestCase): + GRAPHQL_SCHEMA = True + + tc = TestClass() + tc.setUpClass() + tc.query("query { }", op_name="QueryName") + body = json.loads(post_mock.call_args.args[1]) + assert ( + "operationName", + "QueryName", + ) in body.items(), "Key 'operationName' is not present in the final request."