파이썬/장고
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
반응형