django test를 작성할때는 APITestCase의 client에서 요청을 보내는데, 이 방식이 평소에 사용하던 requests와는 조금 다르다.
def test_create_article(self):
article_uri = reverse("article:article_list")
article_data = {
"subject":"일반",
"title":"test_title",
"content":"test_content"
}
header = {"HTTP_AUTHORIZATION":'Bearer ' +self.access_token}
response = self.client.post(article_uri,article_data,**header)
self.assertEqual(response.status_code,201)
header 앞에 ** 을 붙여야하며, header의 key 값에는 HTTP_가 붙어야 한다.
즉, {"AUTHORIZATION":'token'} 라는 헤더를 보내고 싶다면 {"HTTP_AUTHORIZATION":'token'} 로 보내야한다는 것이다.