graphql-python / graphql-python/graphene

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

オープン
#1,379 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
🐛 bug
主要言語
Python
スター
8.2k
フォーク
818
PR マージ指標
30日以内にマージされた PR はありません

説明

**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}}
```

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

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

調査の方向性

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

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

評価

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

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

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