diff --git a/django/contrib/auth/tests/context_processors.py b/django/contrib/auth/tests/context_processors.py
index bba2046..31a56f4 100644
a
|
b
|
class AuthContextProcessorTests(TestCase):
|
30 | 30 | Tests that the session is not accessed simply by including |
31 | 31 | the auth context processor |
32 | 32 | """ |
33 | | context._standard_context_processors = None |
34 | | |
35 | 33 | response = self.client.get('/auth_processor_no_attr_access/') |
36 | 34 | self.assertContains(response, "Session not accessed") |
37 | 35 | |
38 | | context._standard_context_processors = None |
39 | | |
40 | 36 | @override_settings( |
41 | 37 | MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES, |
42 | 38 | TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS, |
… |
… |
class AuthContextProcessorTests(TestCase):
|
46 | 42 | Tests that the session is accessed if the auth context processor |
47 | 43 | is used and relevant attributes accessed. |
48 | 44 | """ |
49 | | context._standard_context_processors = None |
50 | | |
51 | 45 | response = self.client.get('/auth_processor_attr_access/') |
52 | 46 | self.assertContains(response, "Session accessed") |
53 | 47 | |
54 | | context._standard_context_processors = None |
55 | | |
56 | 48 | def test_perms_attrs(self): |
57 | 49 | self.client.login(username='super', password='secret') |
58 | 50 | response = self.client.get('/auth_processor_perms/') |
diff --git a/django/contrib/messages/tests/base.py b/django/contrib/messages/tests/base.py
index 8d04532..4a00324 100644
a
|
b
|
class BaseTest(TestCase):
|
259 | 259 | args=(level,)) |
260 | 260 | response = self.client.post(add_url, data, follow=True) |
261 | 261 | self.assertRedirects(response, show_url) |
262 | | self.assertTrue('messages' in response.context) |
263 | | self.assertEqual(list(response.context['messages']), []) |
| 262 | self.assertFalse('messages' in response.context) |
264 | 263 | |
265 | 264 | def stored_messages_count(self, storage, response): |
266 | 265 | """ |
diff --git a/django/test/signals.py b/django/test/signals.py
index 01d5581..ed16831 100644
a
|
b
|
|
1 | 1 | from django.conf import settings |
2 | 2 | from django.db import connections |
3 | | from django.dispatch import Signal |
| 3 | from django.dispatch import receiver, Signal |
| 4 | from django.template import context |
4 | 5 | |
5 | 6 | template_rendered = Signal(providing_args=["template", "context"]) |
6 | 7 | |
7 | 8 | setting_changed = Signal(providing_args=["setting", "value"]) |
8 | 9 | |
| 10 | @receiver(setting_changed) |
9 | 11 | def update_connections_time_zone(**kwargs): |
10 | 12 | if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC': |
11 | 13 | USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE |
… |
… |
def update_connections_time_zone(**kwargs):
|
20 | 22 | if tz_sql: |
21 | 23 | conn.cursor().execute(tz_sql, [tz]) |
22 | 24 | |
23 | | setting_changed.connect(update_connections_time_zone) |
| 25 | @receiver(setting_changed) |
| 26 | def clear_context_processors_cache(**kwargs): |
| 27 | if kwargs['setting'] == 'TEMPLATE_CONTEXT_PROCESSORS': |
| 28 | context._standard_context_processors = None |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 564e492..d2d6c87 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):
|
3364 | 3363 | urlbit = 'admin' |
3365 | 3364 | |
3366 | 3365 | def setUp(self): |
3367 | | self._context_processors = None |
3368 | | self._use_i18n, settings.USE_I18N = settings.USE_I18N, False |
3369 | | if 'django.core.context_processors.i18n' in settings.TEMPLATE_CONTEXT_PROCESSORS: |
3370 | | self._context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS |
3371 | | cp = list(settings.TEMPLATE_CONTEXT_PROCESSORS) |
3372 | | cp.remove('django.core.context_processors.i18n') |
3373 | | settings.TEMPLATE_CONTEXT_PROCESSORS = tuple(cp) |
3374 | | # Force re-evaluation of the contex processor list |
3375 | | context_module._standard_context_processors = None |
3376 | 3366 | self.client.login(username='super', password='secret') |
3377 | 3367 | |
3378 | 3368 | def tearDown(self): |
3379 | 3369 | self.client.logout() |
3380 | | if self._context_processors is not None: |
3381 | | settings.TEMPLATE_CONTEXT_PROCESSORS = self._context_processors |
3382 | | # Force re-evaluation of the contex processor list |
3383 | | context_module._standard_context_processors = None |
3384 | | settings.USE_I18N = self._use_i18n |
3385 | 3370 | |
| 3371 | @override_settings( |
| 3372 | TEMPLATE_CONTEXT_PROCESSORS=filter( |
| 3373 | lambda t:t!='django.core.context_processors.i18n', |
| 3374 | global_settings.TEMPLATE_CONTEXT_PROCESSORS), |
| 3375 | USE_I18N=False, |
| 3376 | ) |
3386 | 3377 | def testLangNamePresent(self): |
3387 | 3378 | response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit) |
3388 | 3379 | self.assertFalse(' lang=""' in response.content) |
diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
index 7c59da2..3c45b7a 100644
a
|
b
|
import pickle
|
3 | 3 | import time |
4 | 4 | from datetime import datetime |
5 | 5 | |
6 | | from django.utils import unittest |
7 | 6 | from django.test import RequestFactory, TestCase |
8 | 7 | from django.conf import settings |
9 | | import django.template.context |
10 | 8 | from django.template import Template, Context |
11 | 9 | from django.template.response import (TemplateResponse, SimpleTemplateResponse, |
12 | 10 | ContentNotRenderedError) |
| 11 | from django.test.utils import override_settings |
13 | 12 | |
14 | 13 | def test_processor(request): |
15 | 14 | return {'processors': 'yes'} |
… |
… |
class CustomURLConfMiddleware(object):
|
22 | 21 | request.urlconf = 'regressiontests.templates.alternate_urls' |
23 | 22 | |
24 | 23 | |
25 | | class BaseTemplateResponseTest(unittest.TestCase): |
26 | | # tests rely on fact that global context |
27 | | # processors should only work when RequestContext is used. |
28 | | |
29 | | def setUp(self): |
30 | | self.factory = RequestFactory() |
31 | | self._old_processors = settings.TEMPLATE_CONTEXT_PROCESSORS |
32 | | self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS |
33 | | settings.TEMPLATE_CONTEXT_PROCESSORS = [test_processor_name] |
34 | | settings.TEMPLATE_DIRS = ( |
35 | | os.path.join( |
36 | | os.path.dirname(__file__), |
37 | | 'templates' |
38 | | ), |
39 | | ) |
40 | | # Force re-evaluation of the contex processor list |
41 | | django.template.context._standard_context_processors = None |
42 | | |
43 | | def tearDown(self): |
44 | | settings.TEMPLATE_DIRS = self._old_TEMPLATE_DIRS |
45 | | settings.TEMPLATE_CONTEXT_PROCESSORS = self._old_processors |
46 | | # Force re-evaluation of the contex processor list |
47 | | django.template.context._standard_context_processors = None |
48 | | |
49 | | |
50 | | class SimpleTemplateResponseTest(BaseTemplateResponseTest): |
| 24 | class SimpleTemplateResponseTest(TestCase): |
51 | 25 | |
52 | 26 | def _response(self, template='foo', *args, **kwargs): |
53 | 27 | return SimpleTemplateResponse(Template(template), *args, **kwargs) |
… |
… |
class SimpleTemplateResponseTest(BaseTemplateResponseTest):
|
213 | 187 | unpickled_response = pickle.loads(pickled_response) |
214 | 188 | repickled_response = pickle.dumps(unpickled_response) |
215 | 189 | |
216 | | class TemplateResponseTest(BaseTemplateResponseTest): |
| 190 | @override_settings( |
| 191 | TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name], |
| 192 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')), |
| 193 | ) |
| 194 | class TemplateResponseTest(TestCase): |
| 195 | |
| 196 | def setUp(self): |
| 197 | self.factory = RequestFactory() |
217 | 198 | |
218 | 199 | def _response(self, template='foo', *args, **kwargs): |
219 | 200 | return TemplateResponse(self.factory.get('/'), Template(template), |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index e166f7e..e40ffcb 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..d20b6d1 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 | |
| 7 | @override_settings( |
| 8 | TEMPLATE_CONTEXT_PROCESSORS=('django.core.context_processors.static',), |
| 9 | STATIC_URL='/path/to/static/media/', |
| 10 | ) |
6 | 11 | class ShortcutTests(TestCase): |
7 | 12 | urls = 'regressiontests.views.generic_urls' |
8 | 13 | |
… |
… |
class ShortcutTests(TestCase):
|
11 | 16 | warnings.filterwarnings('ignore', category=DeprecationWarning, |
12 | 17 | module='django.views.generic.simple') |
13 | 18 | |
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 | 19 | def tearDown(self): |
23 | 20 | self.restore_warnings_state() |
24 | 21 | |
25 | | def tearDown(self): |
26 | | settings.STATIC_URL = self.old_STATIC_URL |
27 | | settings.TEMPLATE_CONTEXT_PROCESSORS = self.old_TEMPLATE_CONTEXT_PROCESSORS |
28 | | |
29 | 22 | def test_render_to_response(self): |
30 | 23 | response = self.client.get('/shortcuts/render_to_response/') |
31 | 24 | self.assertEqual(response.status_code, 200) |
… |
… |
class ShortcutTests(TestCase):
|
74 | 67 | |
75 | 68 | def test_render_with_current_app_conflict(self): |
76 | 69 | self.assertRaises(ValueError, self.client.get, '/shortcuts/render/current_app_conflict/') |
77 | | |