# HG changeset patch
# User Brodie Rao <brodie@bitheap.org>
# Date 1297306155 28800
# Branch releases/1.2.X
# Node ID f9460598a915c96ec3d4d883c965eaa06b880713
# Parent 61c0665bc6c15ed9db42a7ca5da2678efa551934
Added tests for logged in users and CACHE_MIDDLEWARE_ANONYMOUS_ONLY
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
a
|
b
|
import unittest
|
10 | 10 | import warnings |
11 | 11 | |
12 | 12 | from django.conf import settings |
| 13 | from django.contrib.auth.models import User |
13 | 14 | from django.core import management |
14 | 15 | from django.core.cache import get_cache |
15 | 16 | from django.core.cache.backends.base import CacheKeyWarning |
… |
… |
class CacheMiddlewareAnonymousOnlyTests(
|
670 | 671 | response = self.client.get('/') |
671 | 672 | self.failIf('Cookie' in response.get('Vary', '')) |
672 | 673 | |
| 674 | def test_cache_middleware_anonymous_only_while_logged_in(self): |
| 675 | settings.CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True |
| 676 | |
| 677 | response = self.client.get('/') |
| 678 | self.assertEqual(response['Cache-Control'], 'max-age=600') |
| 679 | |
| 680 | User.objects.create_user(username='user', email='foo@bar.com', |
| 681 | password='password') |
| 682 | login = self.client.login(username='user', password='password') |
| 683 | self.assertTrue(login) |
| 684 | |
| 685 | response = self.client.get('/user') |
| 686 | self.failIf('Cache-Control' in response) |
| 687 | response = self.client.get('/user-cache-page') |
| 688 | self.failIf('Cache-Control' in response) |
| 689 | response = self.client.get('/user-vary-on-cookie-cache-page') |
| 690 | self.failIf('Cache-Control' in response) |
| 691 | response = self.client.get('/user-cache-page-vary-on-cookie') |
| 692 | self.failIf('Cache-Control' in response) |
673 | 693 | |
674 | 694 | if __name__ == '__main__': |
675 | 695 | unittest.main() |
diff --git a/tests/regressiontests/cache/urls.py b/tests/regressiontests/cache/urls.py
a
|
b
|
from django.conf.urls.defaults import pa
|
2 | 2 | |
3 | 3 | urlpatterns = patterns('regressiontests.cache.views', |
4 | 4 | (r'^$', 'home'), |
| 5 | (r'^user$', 'user'), |
| 6 | (r'^user-cache-page$', 'user_cache_page'), |
| 7 | (r'^user-vary-on-cookie-cache-page$', 'user_vary_on_cookie_cache_page'), |
| 8 | (r'^user-cache-page-vary-on-cookie$', 'user_cache_page_vary_on_cookie'), |
5 | 9 | ) |
diff --git a/tests/regressiontests/cache/views.py b/tests/regressiontests/cache/views.py
a
|
b
|
|
1 | 1 | from django.http import HttpResponse |
| 2 | from django.views.decorators.cache import cache_page |
| 3 | from django.views.decorators.vary import vary_on_cookie |
2 | 4 | |
3 | 5 | def home(request): |
4 | 6 | return HttpResponse('Hello World!') |
| 7 | |
| 8 | def user(request): |
| 9 | return HttpResponse(request.user.username) |
| 10 | |
| 11 | user_cache_page = cache_page(60 * 15)(user) |
| 12 | user_vary_on_cookie_cache_page = vary_on_cookie(user_cache_page) |
| 13 | user_cache_page_vary_on_cookie = cache_page(60 * 15)(vary_on_cookie(user)) |