mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #15260 -- Ensured that CACHE_MIDDLEWARE_ANONYMOUS_ONLY is effective with the cache_page decorator, not only the middleware. Thanks to brodie for report and draft patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15559 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ed7a30782b
commit
969217d455
4 changed files with 33 additions and 11 deletions
22
tests/regressiontests/cache/tests.py
vendored
22
tests/regressiontests/cache/tests.py
vendored
|
@ -1256,6 +1256,28 @@ class CacheMiddlewareTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual(request.session.accessed, False)
|
||||
|
||||
def test_cache_middleware_anonymous_only_with_cache_page(self):
|
||||
"""CACHE_MIDDLEWARE_ANONYMOUS_ONLY should still be effective when used
|
||||
with the cache_page decorator: the response to a request from an
|
||||
authenticated user should not be cached."""
|
||||
settings.CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
|
||||
|
||||
request = self.factory.get('/view_anon/')
|
||||
|
||||
class MockAuthenticatedUser(object):
|
||||
def is_authenticated(self):
|
||||
return True
|
||||
|
||||
class MockAccessedSession(object):
|
||||
accessed = True
|
||||
|
||||
request.user = MockAuthenticatedUser()
|
||||
request.session = MockAccessedSession()
|
||||
|
||||
response = cache_page(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)
|
||||
|
|
5
tests/regressiontests/cache/urls.py
vendored
5
tests/regressiontests/cache/urls.py
vendored
|
@ -1,5 +0,0 @@
|
|||
from django.conf.urls.defaults import patterns
|
||||
|
||||
urlpatterns = patterns('regressiontests.cache.views',
|
||||
(r'^$', 'home'),
|
||||
)
|
4
tests/regressiontests/cache/views.py
vendored
4
tests/regressiontests/cache/views.py
vendored
|
@ -1,4 +0,0 @@
|
|||
from django.http import HttpResponse
|
||||
|
||||
def home(request):
|
||||
return HttpResponse('Hello World!')
|
Loading…
Add table
Add a link
Reference in a new issue