Skip to content

301 response GraphQLTestCase due to TESTING_ENDPOINT setting #1359

Closed
@FlavienRx

Description

@FlavienRx

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • What is the current behavior?

All my tests using GraphQLTestCase class crashed when I attenpt to load the response content of my requests.

Simple test case using Django User model

class AnonymousUserGraphQLTests(GraphQLTestCase):
    user_email = "[email protected]"
    user_password = User.objects.make_random_password()
    user_first_name = "User1 first name"
    user_last_name = "User1 last name"

    def test_create_user_without_last_name(self):
        response = self.query(
            """
            mutation createUser($input:  CreateUserInput!) {
                createUser(input: $input) {
                    user {
                        email
                        firstName
                        lastName
                    }
                    errors {
                        field
                        messages
                    }
                }
            }
            """,
            input_data={
                "email": self.user_email,
                "password": self.user_password,
                "firstName": self.user_first_name,
            },
        )

        # This validates the status code and if you get errors
        self.assertResponseNoErrors(response)

        content = json.loads(response.content) # <= crashed here
        user = content["data"]["createUser"]["user"]

        self.assertEqual(user["email"], self.user_email)
        self.assertEqual(user["firstName"], self.user_first_name)
        self.assertEqual(user["lastName"], "")

        user = User.objects.get(email=self.user_email)
        self.assertTrue(user.check_password(self.user_password))
  • What is the expected behavior?

A 200 response but I got a 301 response <HttpResponsePermanentRedirect status_code=301, "text/html; charset=utf-8", url="/graphql/"> with no request content.

  • Please tell us about your environment:

    • Version: 3.0.0
    • Platform:
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

I fixed my issue by set this setting in my test.py settings file

GRAPHENE["TESTING_ENDPOINT"] = "/graphql/"

Note the / at the end. The default TESTING_ENDPOINT value is /graphql in the graphene-django v3.0.0

https://github.com/graphql-python/graphene-django/blob/main/graphene_django/settings.py#L46

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions