From beb2e4aae324cd89038aabf9718c01a3607bc1a1 Mon Sep 17 00:00:00 2001 From: Jiahao Li Date: Mon, 22 Feb 2021 23:13:49 -0500 Subject: [PATCH] Doc clarification for headers arg in testing utils (#1117) I think it might be helpful to add an explicit hint that HTTP headers should be prepended with `HTTP_` as required by `django.test.Client` (at least it was not super obvious to me when I tried to use it). --- graphene_django/utils/testing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 584a08b..6187566 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -28,7 +28,9 @@ def graphql_query( variables (dict) - If provided, the "variables" field in GraphQL will be set to this value. headers (dict) - If provided, the headers in POST request to GRAPHQL_URL - will be set to this value. + will be set to this value. Keys should be prepended with + "HTTP_" (e.g. to specify the "Authorization" HTTP header, + use "HTTP_AUTHORIZATION" as the key). client (django.test.Client) - Test client. Defaults to django.test.Client. graphql_url (string) - URL to graphql endpoint. Defaults to "/graphql". @@ -85,7 +87,9 @@ class GraphQLTestCase(TestCase): variables (dict) - If provided, the "variables" field in GraphQL will be set to this value. headers (dict) - If provided, the headers in POST request to GRAPHQL_URL - will be set to this value. + will be set to this value. Keys should be prepended with + "HTTP_" (e.g. to specify the "Authorization" HTTP header, + use "HTTP_AUTHORIZATION" as the key). Returns: Response object from client