Невозможно добавить заголовки токенов в graphene-django с помощью pytest

Я пытаюсь добавить токен к заголовкам graphene-django, используя pytest. Но он всегда возвращает, что пользователь анонимный, как показано в конце, но он должен возвращать пользователя, так как токен добавлен в fixture.

@pytest.fixture
def client_query(client):
    def func(*args, **kwargs):
        return graphql_query(*args, **kwargs, client=client)

    return func


@pytest.fixture
def create_candidate(candidate_factory):
    candidate = []
    for _ in range(5):
        can = candidate_factory.create()
        token, __ = Token.objects.get_or_create(user=can.user)
        candidate.append(can)

    return candidate

# This is the testing
@pytest.mark.django_db
def test_get_login_candidate(client_query, create_candidate):
    headers = {"Authorization": f"Token {create_candidate[0].user.auth_token}"}
    response = client_query(
        """
        query {
          loginCandidate{
              id,
          }
        }
        """,
        headers=headers,
    )

    result = json.loads(response.content)
    print(result)

output

{'errors': [{'message': "'AnonymousUser' object is not iterable", 'locations': [{'line': 3, 'column': 11}], 'path': ['loginCandidate']}], 'data': {'loginCandidate': None}}
Вернуться на верх