Is there a way to add a user agent string to the RequestFactory request object? I have the following test:
def test_homepage(self): request = self.factory.get(reverse('home')) response = views.home_page(request) self.assertEqual(response.status_code, 200)
The problem is that the home_page view calls a function requiring request.META ["HTTP_USER_AGENT"]. As a result, the above test raises KeyError because it does not know what HTTP_USER_AGENT is. Is there any way to add it to the RF request object? I know that I can add it if I use the Django Client object, but I would prefer not to go along this route, since I want to exclude all the participation of middleware in my test.
Thanks.
source share