graphql-python / graphql-python/graphene

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

Ouverte
#1,379 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
🐛 bug
Langage dominant
Python
Étoiles
8.2k
Forks
818
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start with the test_get_login_candidate test, the create_candidate fixture, and the client_query fixture shown in the issue. Trace how the Authorization headers reach the GraphQL request and verify the request resolves the token's user instead of AnonymousUser; the issue is done when this query returns the authenticated candidate without the reported error.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
django, python
Domaine
api, authentication, backend
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
28/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.