diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-02-27 22:54:35 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-02-27 22:54:35 +0000 |
| commit | abf2d4295f0ec52fdafdda956ad3e5bc59e63d63 (patch) | |
| tree | f8b7af88744ada7cf5e47542cbf4e98c761fb122 | |
| parent | 2ddfcfbec67e1373dd61ed1640ff6ddcdef9e3aa (diff) | |
Fixed #16366 -- Prevented some failures of the django.contrib.auth tests when run within a project. Thanks to everyone who contributed to the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17598 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/auth/tests/context_processors.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/django/contrib/auth/tests/context_processors.py b/django/contrib/auth/tests/context_processors.py index 49172c60e0..8f77940a61 100644 --- a/django/contrib/auth/tests/context_processors.py +++ b/django/contrib/auth/tests/context_processors.py @@ -1,9 +1,11 @@ import os -from django.conf import settings +from django.conf import global_settings from django.contrib.auth import authenticate from django.db.models import Q +from django.template import context from django.test import TestCase +from django.test.utils import override_settings class AuthContextProcessorTests(TestCase): @@ -13,28 +15,31 @@ class AuthContextProcessorTests(TestCase): urls = 'django.contrib.auth.tests.urls' fixtures = ['context-processors-users.xml'] - def setUp(self): - self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS - settings.TEMPLATE_DIRS = ( - os.path.join(os.path.dirname(__file__), 'templates'), - ) - - def tearDown(self): - settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS - + @override_settings( + MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES, + TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS, + ) def test_session_not_accessed(self): """ Tests that the session is not accessed simply by including the auth context processor """ + context._standard_context_processors = None + response = self.client.get('/auth_processor_no_attr_access/') self.assertContains(response, "Session not accessed") + @override_settings( + MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES, + TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS, + ) def test_session_is_accessed(self): """ Tests that the session is accessed if the auth context processor is used and relevant attributes accessed. """ + context._standard_context_processors = None + response = self.client.get('/auth_processor_attr_access/') self.assertContains(response, "Session accessed") @@ -86,3 +91,9 @@ class AuthContextProcessorTests(TestCase): # See bug #12060 self.assertEqual(response.context['user'], user) self.assertEqual(user, response.context['user']) + +AuthContextProcessorTests = override_settings( + TEMPLATE_DIRS = ( + os.path.join(os.path.dirname(__file__), 'templates'), + ) +)(AuthContextProcessorTests) |
