Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Aymeric Augustin authored February 27, 2012
31  django/contrib/auth/tests/context_processors.py
... ...
@@ -1,9 +1,11 @@
1 1
 import os
2 2
 
3  
-from django.conf import settings
  3
+from django.conf import global_settings
4 4
 from django.contrib.auth import authenticate
5 5
 from django.db.models import Q
  6
+from django.template import context
6 7
 from django.test import TestCase
  8
+from django.test.utils import override_settings
7 9
 
8 10
 
9 11
 class AuthContextProcessorTests(TestCase):
@@ -13,28 +15,31 @@ class AuthContextProcessorTests(TestCase):
13 15
     urls = 'django.contrib.auth.tests.urls'
14 16
     fixtures = ['context-processors-users.xml']
15 17
 
16  
-    def setUp(self):
17  
-        self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
18  
-        settings.TEMPLATE_DIRS = (
19  
-            os.path.join(os.path.dirname(__file__), 'templates'),
20  
-        )
21  
-
22  
-    def tearDown(self):
23  
-        settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
24  
-
  18
+    @override_settings(
  19
+        MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES,
  20
+        TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS,
  21
+    )
25 22
     def test_session_not_accessed(self):
26 23
         """
27 24
         Tests that the session is not accessed simply by including
28 25
         the auth context processor
29 26
         """
  27
+        context._standard_context_processors = None
  28
+
30 29
         response = self.client.get('/auth_processor_no_attr_access/')
31 30
         self.assertContains(response, "Session not accessed")
32 31
 
  32
+    @override_settings(
  33
+        MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES,
  34
+        TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS,
  35
+    )
33 36
     def test_session_is_accessed(self):
34 37
         """
35 38
         Tests that the session is accessed if the auth context processor
36 39
         is used and relevant attributes accessed.
37 40
         """
  41
+        context._standard_context_processors = None
  42
+
38 43
         response = self.client.get('/auth_processor_attr_access/')
39 44
         self.assertContains(response, "Session accessed")
40 45
 
@@ -86,3 +91,9 @@ def test_user_attrs(self):
86 91
         # See bug #12060
87 92
         self.assertEqual(response.context['user'], user)
88 93
         self.assertEqual(user, response.context['user'])
  94
+
  95
+AuthContextProcessorTests = override_settings(
  96
+    TEMPLATE_DIRS = (
  97
+            os.path.join(os.path.dirname(__file__), 'templates'),
  98
+        )
  99
+)(AuthContextProcessorTests)

0 notes on commit abf2d42

Please sign in to comment.
Something went wrong with that request. Please try again.