graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.31k stars 769 forks source link

GraphQLTestCase does not send headers using Django 4.2 #1464

Closed ryanovas closed 1 year ago

ryanovas commented 1 year ago

Trying to send headers using GraphQLTestCase doesn't work. This is my test:

class TestCase(GraphQLTestCase):
    def test(self):
        response = self.query(
            '''
            query {
                puzzles {
                    id
                    title
                }
            }
            ''',
            headers={
                'Some-Header': 'test,
            },
        )

        self.assertResponseNoErrors(valid_response)

and if I try to log those headers in my code I get None. However if I follow the code to graphene_django/utils/testing.py and change line 58 from:

resp = client.post(
            graphql_url, json.dumps(body), content_type="application/json", **headers
        )

to

resp = client.post(
            graphql_url, json.dumps(body), content_type="application/json", headers=headers
        )

Then it works fine.

python = "^3.11" django = "^4.2.1" graphene-django = "^3.1.1"

kiendang commented 1 year ago

Yup looks like this was changed in Django 4.2 https://docs.djangoproject.com/en/4.2/topics/testing/tools/. Thanks for reporting.

kiendang commented 1 year ago

I opened #1465 to fix this. Feel free to add a test case with a PR. Would really appreciate it if you do.