graphql-python / graphql-python/graphene
Unable to add token headers to graphene-django test using pytest
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
**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}}
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- django, python
- Área
- api, authentication, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 28/100