Пример #1
0
 def test_cache_control_already_set_to_0_should_not_set_s_maxage(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     response = HttpResponse()
     response['Cache-Control'] = 'max-age=0'
     response = CacheControlMiddleware(lambda x: response)(request)
     assert response['Cache-Control'] == 'max-age=0'
Пример #2
0
 def test_cookies_in_response_should_not_cache(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     response = HttpResponse()
     response.set_cookie('foo', 'bar')
     response = CacheControlMiddleware(lambda x: response)(request)
     assert response['Cache-Control'] == 's-maxage=0'
Пример #3
0
 def test_disable_caching_arg_should_not_cache(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     request.GET = {'disable_caching': '1'}
     response = HttpResponse()
     response = CacheControlMiddleware(lambda x: response)(request)
     assert response['Cache-Control'] == 's-maxage=0'
Пример #4
0
 def test_authenticated_should_not_cache(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     request.META = {'HTTP_AUTHORIZATION': 'foo'}
     response = HttpResponse()
     response = CacheControlMiddleware(lambda x: response)(request)
     assert response['Cache-Control'] == 's-maxage=0'
Пример #5
0
 def test_everything_ok_should_cache_for_3_minutes(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     response = HttpResponse()
     for status_code in (200, 201, 202, 204, 301, 302, 303, 304):
         response.status_code = status_code
         response = CacheControlMiddleware(lambda x: response)(request)
         assert response['Cache-Control'] == 'max-age=180'
Пример #6
0
 def test_non_success_status_code_should_not_cache(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     response = HttpResponse()
     for status_code in (400, 401, 403, 404, 429, 500, 502, 503, 504):
         response.status_code = status_code
         response = CacheControlMiddleware(lambda x: response)(request)
         assert response['Cache-Control'] == 's-maxage=0'
Пример #7
0
 def test_non_read_only_http_method_should_not_cache(self):
     request = self.request_factory.get('/api/v5/foo')
     request.is_api = True
     for method in ('POST', 'DELETE', 'PUT', 'PATCH'):
         request.method = method
         response = HttpResponse()
         response = CacheControlMiddleware(lambda x: response)(request)
         assert response['Cache-Control'] == 's-maxage=0'
Пример #8
0
 def test_not_api_should_not_cache(self):
     request = self.request_factory.get('/bar')
     request.is_api = False
     response = HttpResponse()
     response = CacheControlMiddleware(lambda x: response)(request)
     assert response['Cache-Control'] == 's-maxage=0'