diff --git a/django/contrib/auth/tests/context_processors.py b/django/contrib/auth/tests/context_processors.py
index 8f77940..8718ccc 100644
a
|
b
|
class AuthContextProcessorTests(TestCase):
|
24 | 24 | Tests that the session is not accessed simply by including |
25 | 25 | the auth context processor |
26 | 26 | """ |
27 | | context._standard_context_processors = None |
28 | | |
29 | 27 | response = self.client.get('/auth_processor_no_attr_access/') |
30 | 28 | self.assertContains(response, "Session not accessed") |
31 | 29 | |
… |
… |
class AuthContextProcessorTests(TestCase):
|
38 | 36 | Tests that the session is accessed if the auth context processor |
39 | 37 | is used and relevant attributes accessed. |
40 | 38 | """ |
41 | | context._standard_context_processors = None |
42 | | |
43 | 39 | response = self.client.get('/auth_processor_attr_access/') |
44 | 40 | self.assertContains(response, "Session accessed") |
45 | 41 | |
diff --git a/django/test/signals.py b/django/test/signals.py
index 01d5581..290fdd1 100644
a
|
b
|
def update_connections_time_zone(**kwargs):
|
20 | 20 | if tz_sql: |
21 | 21 | conn.cursor().execute(tz_sql, [tz]) |
22 | 22 | |
| 23 | def clear_context_processors_cache(**kwargs): |
| 24 | if kwargs['setting'] == 'TEMPLATE_CONTEXT_PROCESSORS': |
| 25 | from django.template import context |
| 26 | context._standard_context_processors = None |
| 27 | |
23 | 28 | setting_changed.connect(update_connections_time_zone) |
| 29 | setting_changed.connect(clear_context_processors_cache) |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 12f1c67..9f71d04 100644
a
|
b
|
import re
|
6 | 6 | import datetime |
7 | 7 | import urlparse |
8 | 8 | |
9 | | from django.conf import settings |
| 9 | from django.conf import settings, global_settings |
10 | 10 | from django.core import mail |
11 | 11 | from django.core.exceptions import SuspiciousOperation |
12 | 12 | from django.core.files import temp as tempfile |
… |
… |
from django.contrib.auth import REDIRECT_FIELD_NAME
|
23 | 23 | from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD |
24 | 24 | from django.contrib.contenttypes.models import ContentType |
25 | 25 | from django.forms.util import ErrorList |
26 | | from django.template import context as context_module |
27 | 26 | from django.template.response import TemplateResponse |
28 | 27 | from django.test import TestCase |
29 | 28 | from django.utils import formats, translation, unittest |
… |
… |
class ValidXHTMLTests(TestCase):
|
3365 | 3364 | urlbit = 'admin' |
3366 | 3365 | |
3367 | 3366 | def setUp(self): |
3368 | | self._context_processors = None |
3369 | | self._use_i18n, settings.USE_I18N = settings.USE_I18N, False |
3370 | | if 'django.core.context_processors.i18n' in settings.TEMPLATE_CONTEXT_PROCESSORS: |
3371 | | self._context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS |
3372 | | cp = list(settings.TEMPLATE_CONTEXT_PROCESSORS) |
3373 | | cp.remove('django.core.context_processors.i18n') |
3374 | | settings.TEMPLATE_CONTEXT_PROCESSORS = tuple(cp) |
3375 | | # Force re-evaluation of the contex processor list |
3376 | | context_module._standard_context_processors = None |
3377 | 3367 | self.client.login(username='super', password='secret') |
3378 | 3368 | |
3379 | 3369 | def tearDown(self): |
3380 | 3370 | self.client.logout() |
3381 | | if self._context_processors is not None: |
3382 | | settings.TEMPLATE_CONTEXT_PROCESSORS = self._context_processors |
3383 | | # Force re-evaluation of the contex processor list |
3384 | | context_module._standard_context_processors = None |
3385 | | settings.USE_I18N = self._use_i18n |
3386 | 3371 | |
| 3372 | @override_settings( |
| 3373 | TEMPLATE_CONTEXT_PROCESSORS=filter( |
| 3374 | lambda t:t!='django.core.context_processors.i18n', |
| 3375 | global_settings.TEMPLATE_CONTEXT_PROCESSORS), |
| 3376 | USE_I18N=False, |
| 3377 | ) |
3387 | 3378 | def testLangNamePresent(self): |
3388 | 3379 | response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit) |
3389 | 3380 | self.assertFalse(' lang=""' in response.content) |
diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
index 5feb8cc..5167e36 100644
a
|
b
|
import pickle
|
5 | 5 | import time |
6 | 6 | from datetime import datetime |
7 | 7 | |
8 | | from django.utils import unittest |
9 | 8 | from django.test import RequestFactory, TestCase |
10 | 9 | from django.conf import settings |
11 | | import django.template.context |
12 | 10 | from django.template import Template, Context |
13 | 11 | from django.template.response import (TemplateResponse, SimpleTemplateResponse, |
14 | 12 | ContentNotRenderedError) |
| 13 | from django.test.utils import override_settings |
15 | 14 | |
16 | 15 | def test_processor(request): |
17 | 16 | return {'processors': 'yes'} |
… |
… |
class CustomURLConfMiddleware(object):
|
24 | 23 | request.urlconf = 'regressiontests.templates.alternate_urls' |
25 | 24 | |
26 | 25 | |
27 | | class BaseTemplateResponseTest(unittest.TestCase): |
28 | | # tests rely on fact that global context |
29 | | # processors should only work when RequestContext is used. |
30 | | |
31 | | def setUp(self): |
32 | | self.factory = RequestFactory() |
33 | | self._old_processors = settings.TEMPLATE_CONTEXT_PROCESSORS |
34 | | self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS |
35 | | settings.TEMPLATE_CONTEXT_PROCESSORS = [test_processor_name] |
36 | | settings.TEMPLATE_DIRS = ( |
37 | | os.path.join( |
38 | | os.path.dirname(__file__), |
39 | | 'templates' |
40 | | ), |
41 | | ) |
42 | | # Force re-evaluation of the contex processor list |
43 | | django.template.context._standard_context_processors = None |
44 | | |
45 | | def tearDown(self): |
46 | | settings.TEMPLATE_DIRS = self._old_TEMPLATE_DIRS |
47 | | settings.TEMPLATE_CONTEXT_PROCESSORS = self._old_processors |
48 | | # Force re-evaluation of the contex processor list |
49 | | django.template.context._standard_context_processors = None |
50 | | |
51 | | |
52 | | class SimpleTemplateResponseTest(BaseTemplateResponseTest): |
| 26 | class SimpleTemplateResponseTest(TestCase): |
53 | 27 | |
54 | 28 | def _response(self, template='foo', *args, **kwargs): |
55 | 29 | return SimpleTemplateResponse(Template(template), *args, **kwargs) |
… |
… |
class SimpleTemplateResponseTest(BaseTemplateResponseTest):
|
215 | 189 | unpickled_response = pickle.loads(pickled_response) |
216 | 190 | repickled_response = pickle.dumps(unpickled_response) |
217 | 191 | |
218 | | class TemplateResponseTest(BaseTemplateResponseTest): |
| 192 | class TemplateResponseTest(TestCase): |
| 193 | |
| 194 | def setUp(self): |
| 195 | self.factory = RequestFactory() |
219 | 196 | |
220 | 197 | def _response(self, template='foo', *args, **kwargs): |
221 | 198 | return TemplateResponse(self.factory.get('/'), Template(template), |
… |
… |
class TemplateResponseTest(BaseTemplateResponseTest):
|
299 | 276 | unpickled_response = pickle.loads(pickled_response) |
300 | 277 | repickled_response = pickle.dumps(unpickled_response) |
301 | 278 | |
| 279 | TemplateResponseTest = override_settings( |
| 280 | TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name], |
| 281 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')), |
| 282 | )(TemplateResponseTest) |
| 283 | |
302 | 284 | |
303 | 285 | class CustomURLConfTest(TestCase): |
304 | 286 | urls = 'regressiontests.templates.urls' |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index f74aa75..9c56ee3 100644
a
|
b
|
from .parser import ParserTests
|
37 | 37 | from .unicode import UnicodeTests |
38 | 38 | from .nodelist import NodelistTest, ErrorIndexTest |
39 | 39 | from .smartif import SmartIfTests |
40 | | from .response import (TemplateResponseTest, BaseTemplateResponseTest, |
41 | | CacheMiddlewareTest, SimpleTemplateResponseTest, CustomURLConfTest) |
| 40 | from .response import (TemplateResponseTest, CacheMiddlewareTest, |
| 41 | SimpleTemplateResponseTest, CustomURLConfTest) |
42 | 42 | |
43 | 43 | try: |
44 | 44 | from .loaders import RenderToStringTest, EggLoaderTest |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1738 | 1738 | t = template.Template(ttext) |
1739 | 1739 | |
1740 | 1740 | |
1741 | | class RequestContextTests(BaseTemplateResponseTest): |
| 1741 | class RequestContextTests(unittest.TestCase): |
1742 | 1742 | |
1743 | 1743 | def setUp(self): |
1744 | 1744 | templates = { |
diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py
index 24bf6bb..df7a6fa 100644
a
|
b
|
import warnings
|
2 | 2 | |
3 | 3 | from django.conf import settings |
4 | 4 | from django.test import TestCase |
| 5 | from django.test.utils import override_settings |
5 | 6 | |
6 | 7 | class ShortcutTests(TestCase): |
7 | 8 | urls = 'regressiontests.views.generic_urls' |
… |
… |
class ShortcutTests(TestCase):
|
11 | 12 | warnings.filterwarnings('ignore', category=DeprecationWarning, |
12 | 13 | module='django.views.generic.simple') |
13 | 14 | |
14 | | self.old_STATIC_URL = settings.STATIC_URL |
15 | | self.old_TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS |
16 | | |
17 | | settings.STATIC_URL = '/path/to/static/media/' |
18 | | settings.TEMPLATE_CONTEXT_PROCESSORS = ( |
19 | | 'django.core.context_processors.static' |
20 | | ) |
21 | | |
22 | 15 | def tearDown(self): |
23 | 16 | self.restore_warnings_state() |
24 | 17 | |
25 | | def tearDown(self): |
26 | | settings.STATIC_URL = self.old_STATIC_URL |
27 | | settings.TEMPLATE_CONTEXT_PROCESSORS = self.old_TEMPLATE_CONTEXT_PROCESSORS |
28 | | |
29 | 18 | def test_render_to_response(self): |
30 | 19 | response = self.client.get('/shortcuts/render_to_response/') |
31 | 20 | self.assertEqual(response.status_code, 200) |
… |
… |
class ShortcutTests(TestCase):
|
75 | 64 | def test_render_with_current_app_conflict(self): |
76 | 65 | self.assertRaises(ValueError, self.client.get, '/shortcuts/render/current_app_conflict/') |
77 | 66 | |
| 67 | ShortcutTests = override_settings( |
| 68 | TEMPLATE_CONTEXT_PROCESSORS=('django.core.context_processors.static',), |
| 69 | STATIC_URL='/path/to/static/media/', |
| 70 | )(ShortcutTests) |