Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16366 -- Prevented some failures of the django.contrib.auth te…

…sts 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
  • Loading branch information...
commit abf2d4295f0ec52fdafdda956ad3e5bc59e63d63 1 parent 2ddfcfb
@aaugustin aaugustin authored
Showing with 21 additions and 10 deletions.
  1. +21 −10 django/contrib/auth/tests/context_processors.py
View
31 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 @@ def test_user_attrs(self):
# 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)
Please sign in to comment.
Something went wrong with that request. Please try again.