def test_vary(self): request = test.RequestFactory().get('/') response = http.HttpResponse() r = middleware.XMobileMiddleware().process_response(request, response) assert r is response self.assertEqual(response['Vary'], 'X-Mobile') response['Vary'] = 'User-Agent' middleware.XMobileMiddleware().process_response(request, response) self.assertEqual(response['Vary'], 'User-Agent, X-Mobile')
def test_vary_xmobile(self): request = test.RequestFactory().get('/') request.NO_MOBILE = True response = http.HttpResponse() r = middleware.XMobileMiddleware().process_response(request, response) self.assertEqual(response.get('Vary', None), None)
def check(self, xmobile, mobile): request = test.RequestFactory().get('/') if xmobile: request.META['HTTP_X_MOBILE'] = xmobile middleware.XMobileMiddleware().process_request(request) self.assertEqual(request.MOBILE, mobile)