graphql-python / graphql-python/graphene

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

Đang mở
#1,379 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
🐛 bug
Ngôn ngữ chính
Python
Star
8.2k
Fork
818
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với test test_get_login_candidate, fixture create_candidate và fixture client_query được nêu trong issue. Theo dõi cách các header Authorization đến được yêu cầu GraphQL và xác minh rằng yêu cầu phân giải người dùng của token thay vì AnonymousUser; issue được hoàn tất khi truy vấn này trả về ứng viên đã xác thực mà không có lỗi được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
django, python
Lĩnh vực
api, authentication, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.