mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Removed legacy ways of calling cache_page.
This commit is contained in:
parent
9f9a4cdecd
commit
2ecf56ea3f
3 changed files with 13 additions and 91 deletions
38
tests/regressiontests/cache/tests.py
vendored
38
tests/regressiontests/cache/tests.py
vendored
|
@ -1478,19 +1478,12 @@ def hello_world_view(request, value):
|
|||
)
|
||||
class CacheMiddlewareTest(TestCase):
|
||||
|
||||
# The following tests will need to be modified in Django 1.6 to not use
|
||||
# deprecated ways of using the cache_page decorator that will be removed in
|
||||
# such version
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
self.default_cache = get_cache('default')
|
||||
self.other_cache = get_cache('other')
|
||||
self.save_warnings_state()
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning,
|
||||
module='django.views.decorators.cache')
|
||||
|
||||
def tearDown(self):
|
||||
self.restore_warnings_state()
|
||||
self.default_cache.clear()
|
||||
self.other_cache.clear()
|
||||
|
||||
|
@ -1603,21 +1596,20 @@ class CacheMiddlewareTest(TestCase):
|
|||
request.user = MockAuthenticatedUser()
|
||||
request.session = MockAccessedSession()
|
||||
|
||||
response = cache_page(hello_world_view)(request, '1')
|
||||
response = cache_page(60)(hello_world_view)(request, '1')
|
||||
|
||||
self.assertFalse("Cache-Control" in response)
|
||||
|
||||
def test_view_decorator(self):
|
||||
# decorate the same view with different cache decorators
|
||||
default_view = cache_page(hello_world_view)
|
||||
default_with_prefix_view = cache_page(key_prefix='prefix1')(hello_world_view)
|
||||
default_view = cache_page(3)(hello_world_view)
|
||||
default_with_prefix_view = cache_page(3, key_prefix='prefix1')(hello_world_view)
|
||||
|
||||
explicit_default_view = cache_page(cache='default')(hello_world_view)
|
||||
explicit_default_with_prefix_view = cache_page(cache='default', key_prefix='prefix1')(hello_world_view)
|
||||
explicit_default_view = cache_page(3, cache='default')(hello_world_view)
|
||||
explicit_default_with_prefix_view = cache_page(3, cache='default', key_prefix='prefix1')(hello_world_view)
|
||||
|
||||
other_view = cache_page(cache='other')(hello_world_view)
|
||||
other_with_prefix_view = cache_page(cache='other', key_prefix='prefix2')(hello_world_view)
|
||||
other_with_timeout_view = cache_page(3, cache='other', key_prefix='prefix3')(hello_world_view)
|
||||
other_view = cache_page(1, cache='other')(hello_world_view)
|
||||
other_with_prefix_view = cache_page(1, cache='other', key_prefix='prefix2')(hello_world_view)
|
||||
|
||||
request = self.factory.get('/view/')
|
||||
|
||||
|
@ -1657,10 +1649,6 @@ class CacheMiddlewareTest(TestCase):
|
|||
response = other_with_prefix_view(request, '9')
|
||||
self.assertEqual(response.content, b'Hello World 9')
|
||||
|
||||
# Request from the alternate cache with a new prefix and a custom timeout
|
||||
response = other_with_timeout_view(request, '10')
|
||||
self.assertEqual(response.content, b'Hello World 10')
|
||||
|
||||
# But if we wait a couple of seconds...
|
||||
time.sleep(2)
|
||||
|
||||
|
@ -1689,18 +1677,6 @@ class CacheMiddlewareTest(TestCase):
|
|||
response = other_with_prefix_view(request, '16')
|
||||
self.assertEqual(response.content, b'Hello World 16')
|
||||
|
||||
# ... but a view with a custom timeout will still hit
|
||||
response = other_with_timeout_view(request, '17')
|
||||
self.assertEqual(response.content, b'Hello World 10')
|
||||
|
||||
# And if we wait a few more seconds
|
||||
time.sleep(2)
|
||||
|
||||
# the custom timeout cache will miss
|
||||
response = other_with_timeout_view(request, '18')
|
||||
self.assertEqual(response.content, b'Hello World 18')
|
||||
|
||||
|
||||
@override_settings(
|
||||
CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
|
||||
CACHE_MIDDLEWARE_SECONDS=1,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import warnings
|
||||
from functools import wraps
|
||||
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
|
@ -116,22 +115,6 @@ class DecoratorsTest(TestCase):
|
|||
my_view_cached2 = cache_page(123, key_prefix="test")(my_view)
|
||||
self.assertEqual(my_view_cached2(HttpRequest()), "response")
|
||||
|
||||
def test_cache_page_old_style(self):
|
||||
"""
|
||||
Test that we can call cache_page the old way
|
||||
"""
|
||||
def my_view(request):
|
||||
return "response"
|
||||
with warnings.catch_warnings(record=True):
|
||||
my_view_cached = cache_page(my_view, 123)
|
||||
self.assertEqual(my_view_cached(HttpRequest()), "response")
|
||||
my_view_cached2 = cache_page(my_view, 123, key_prefix="test")
|
||||
self.assertEqual(my_view_cached2(HttpRequest()), "response")
|
||||
my_view_cached3 = cache_page(my_view)
|
||||
self.assertEqual(my_view_cached3(HttpRequest()), "response")
|
||||
my_view_cached4 = cache_page()(my_view)
|
||||
self.assertEqual(my_view_cached4(HttpRequest()), "response")
|
||||
|
||||
def test_require_safe_accepts_only_safe_methods(self):
|
||||
"""
|
||||
Test for the require_safe decorator.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue