# tests.py
def test_review_get_handler_method_success(self):
client = Client()
access_token = jwt.encode({'id':12345},SECRET_KEY, ALGORITHM)
headers = {"Authorization" : access_token}
response = client.get('/reviews/1',**headers)
self.assertEqual(response.json(),
{
"results": {
"top_review": {
"review_id": 1,
"user_id": 1,
"nickname": "jayce",
"rating": 2.5,
"content": "리뷰내용1",
"created_at": "2022-03-20",
"updated_at": "2022-03-20"
},
"list_review": [
{
"review_id": 2,
"user_id": 2,
"nickname": "jayce2",
"rating": 3,
"content": "리뷰내용2",
"created_at": "2022-03-20",
"updated_at": "2022-03-20"
},
{
"review_id": 3,
"user_id": 3,
"nickname": "jayce3",
"rating": 3,
"content": "리뷰내용3",
"created_at": "2022-03-20",
"updated_at": "2022-03-20"
}
]
}
}
)
self.assertEqual(response.status_code, 200)
# login_decorator.py
try:
access_token = request.headers.get('Authorization', None)
payload = jwt.decode(access_token, SECRET_KEY, ALGORITHM)
user = User.objects.get(kakao_id = payload["id"])
request.user = user
참으로 기이했다
request.header에 분명 인증 정보가 담겨져서 와야 하는데 아무 것도 담겨 오지 않았다
request.header 를 프린트 해보면
{'Cookie': ''}
....이런 쿠키에 빈 문자열이 value로 있는 딕셔너리만 프린트 되었다..
2시간 반동안 머리를 쥐어뜯고 구글신께 빌어봐도 해결이 되지 않았고
시간은 저녁이라 멘토님들도 모두 퇴근한 상황...
금요일 저녁에 업무를 더해드리고 싶지 않았다
결국 백짱 갓솔님의 도움으로 tests.py를 다음과 같이 수정해서 해결했다
def test_review_get_handler_method_success(self):
client = Client()
access_token = jwt.encode({'id':12345},SECRET_KEY, ALGORITHM)
headers = {"HTTP_Authorization" : access_token} # 이 부분
response = client.get('/reviews/1',**headers)
self.assertEqual(response.json(),...
Authorization의 앞에 HTTP_를 붙이는 것으로 해결
{'Authorization': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MX0.JJhxhioTrfGekH2jE-cPZxHtnVCCn1BHRDzxmDbUBq8'}
{'Cookie': ''}
근데 저 쿠키는 뭘까... 찾아서 블로깅 해볼 예정
ㅎ...왜 그런지도 나중에 찾아서 블로깅 해볼 예정
'dev > error' 카테고리의 다른 글
ImproperlyConfigured (0) | 2022.03.20 |
---|---|
django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row (0) | 2022.03.20 |
[git]fatal: The current branch feature/models has no upstream branch. (0) | 2022.03.07 |
Authentication plugin 'caching_sha2_password' cannot be loaded (0) | 2022.02.20 |
[python]SyntaxError: (unicode error) (0) | 2022.01.05 |