Author: aaugustin Date: 2012-02-27 14:54:35 -0800 (Mon, 27 Feb 2012) New Revision: 17598
Modified: django/trunk/django/contrib/auth/tests/context_processors.py Log: Fixed #16366 -- Prevented some failures of the django.contrib.auth tests when run within a project. Thanks to everyone who contributed to the patch. Modified: django/trunk/django/contrib/auth/tests/context_processors.py =================================================================== --- django/trunk/django/contrib/auth/tests/context_processors.py 2012-02-27 22:52:07 UTC (rev 17597) +++ django/trunk/django/contrib/auth/tests/context_processors.py 2012-02-27 22:54:35 UTC (rev 17598) @@ -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 @@ 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 @@ # 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) -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.