graphql-python / graphql-python/graphene

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

Aperta
#1,379 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
🐛 bug
Lingua principale
Python
Stelle
8.2k
Fork
818
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.