티스토리 뷰

파이썬/장고

django testcase 작성시 headers 작성 방법

글을 쓰는 개발자 2021. 7. 10. 14:38
반응형
 def test_report_create(self):
        print("test_report_create")
        response = self.client.post(self.url, data={'title': 'hi', 'content': 'hello'},
                                    **{'HTTP_AUTHORIZATION': self.access_token_1})
        self.assertEqual(response.status_code, 200)

위와 같이 **을 붙여서 표현 하는데 이 때 'HTTP_'을 붙여서 표현하는 것이 중요하다. 

 

참고글: https://ssamko.tistory.com/53

 

[Django] Test 코드 작성시 header 추가하기

Django를 API서버로만 이용할 때, 외부 사용자들에게 header를 통해 인증정보를 받아야 할 경우가 있다. 이때, Test코드에서도 이를 처리해야 하는데, TestCase의 client에서 요청을 보낼때, from django.urls im

ssamko.tistory.com

 

반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함