我想爲一段代碼編寫一個單元測試,用於檢查標頭是否丟失。我怎樣才能從Django的測試客戶端中省略http_referer頭文件(或任何頭文件)?Django測試客戶端:如何刪除http標頭
from django.test.client import RequestFactory
from django.test import TestCase
from yourapp.view import yourfunction
class YourTest(TestCase)
def setUp(self):
self.factory = RequestFactory()
def testCase(self):
request = self.factory.get('/yoururl/')
del request.META['HTTP_REFERER']
yourfunction(request)