Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unable to add token headers to graphene-django test using pytest

オープン
#1,379 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
28/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
django, python

調査の方向性

Issue に示されている test_get_login_candidate テスト、create_candidate fixture、client_query fixture から始めてください。Authorization ヘッダーが GraphQL リクエストに到達する経路を追跡し、リクエストが AnonymousUser ではなくトークンのユーザーを解決することを確認してください。このクエリが報告されたエラーなしで認証済みの候補を返せば、issue は完了です。

索引モデルが issue の本文から書いたものです。

説明

🐛 bug

I am trying to add token to graphene-django headers using pytest. But It always return that user is anonymous as shown at the end but it should return user as token is added in fixture

@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 test**
@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)


This is the output

{'errors': [{'message': "'AnonymousUser' object is not iterable", 'locations': [{'line': 3, 'column': 11}], 'path': ['loginCandidate']}], 'data': {'loginCandidate': None}}
主要言語
Python
スター
8.2k
フォーク
818
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql-python/graphene のほかの issue

graphql-python/graphene の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。