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
This commit is contained in:
Aymeric Augustin 2012-02-27 22:54:35 +00:00
parent 2ddfcfbec6
commit abf2d4295f
1 changed files with 21 additions and 10 deletions

View File

@ -1,9 +1,11 @@
import os import os
from django.conf import settings from django.conf import global_settings
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from django.db.models import Q from django.db.models import Q
from django.template import context
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings
class AuthContextProcessorTests(TestCase): class AuthContextProcessorTests(TestCase):
@ -13,28 +15,31 @@ class AuthContextProcessorTests(TestCase):
urls = 'django.contrib.auth.tests.urls' urls = 'django.contrib.auth.tests.urls'
fixtures = ['context-processors-users.xml'] fixtures = ['context-processors-users.xml']
def setUp(self): @override_settings(
self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES,
settings.TEMPLATE_DIRS = ( TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS,
os.path.join(os.path.dirname(__file__), 'templates'), )
)
def tearDown(self):
settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
def test_session_not_accessed(self): def test_session_not_accessed(self):
""" """
Tests that the session is not accessed simply by including Tests that the session is not accessed simply by including
the auth context processor the auth context processor
""" """
context._standard_context_processors = None
response = self.client.get('/auth_processor_no_attr_access/') response = self.client.get('/auth_processor_no_attr_access/')
self.assertContains(response, "Session not accessed") 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): def test_session_is_accessed(self):
""" """
Tests that the session is accessed if the auth context processor Tests that the session is accessed if the auth context processor
is used and relevant attributes accessed. is used and relevant attributes accessed.
""" """
context._standard_context_processors = None
response = self.client.get('/auth_processor_attr_access/') response = self.client.get('/auth_processor_attr_access/')
self.assertContains(response, "Session accessed") self.assertContains(response, "Session accessed")
@ -86,3 +91,9 @@ class AuthContextProcessorTests(TestCase):
# See bug #12060 # See bug #12060
self.assertEqual(response.context['user'], user) self.assertEqual(response.context['user'], user)
self.assertEqual(user, response.context['user']) self.assertEqual(user, response.context['user'])
AuthContextProcessorTests = override_settings(
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
)(AuthContextProcessorTests)