I am trying to write a unit test for a piece of code that checks if a header is missing. How can I omit the http_referer header (or any header for that matter) from Django's test client?
def testCase(self):
response = self.client.get('/some_url/')
self.assertNotEqual(500, response.status_code)
Instead of using the built-in test client, you could use Django's RequestFactory to build your request, then modify the request object before calling your function:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With