Ticket #17848: 17848-2.diff

File 17848-2.diff, 9.7 KB (added by Claude Paroz, 12 years ago)

Use the signal_changed approach

  • django/contrib/auth/tests/context_processors.py

    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):  
    2424        Tests that the session is not accessed simply by including
    2525        the auth context processor
    2626        """
    27         context._standard_context_processors = None
    28 
    2927        response = self.client.get('/auth_processor_no_attr_access/')
    3028        self.assertContains(response, "Session not accessed")
    3129
    class AuthContextProcessorTests(TestCase):  
    3836        Tests that the session is accessed if the auth context processor
    3937        is used and relevant attributes accessed.
    4038        """
    41         context._standard_context_processors = None
    42 
    4339        response = self.client.get('/auth_processor_attr_access/')
    4440        self.assertContains(response, "Session accessed")
    4541
  • django/test/signals.py

    diff --git a/django/test/signals.py b/django/test/signals.py
    index 01d5581..290fdd1 100644
    a b def update_connections_time_zone(**kwargs):  
    2020        if tz_sql:
    2121            conn.cursor().execute(tz_sql, [tz])
    2222
     23def 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
    2328setting_changed.connect(update_connections_time_zone)
     29setting_changed.connect(clear_context_processors_cache)
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 12f1c67..9f71d04 100644
    a b import re  
    66import datetime
    77import urlparse
    88
    9 from django.conf import settings
     9from django.conf import settings, global_settings
    1010from django.core import mail
    1111from django.core.exceptions import SuspiciousOperation
    1212from django.core.files import temp as tempfile
    from django.contrib.auth import REDIRECT_FIELD_NAME  
    2323from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
    2424from django.contrib.contenttypes.models import ContentType
    2525from django.forms.util import ErrorList
    26 from django.template import context as context_module
    2726from django.template.response import TemplateResponse
    2827from django.test import TestCase
    2928from django.utils import formats, translation, unittest
    class ValidXHTMLTests(TestCase):  
    33653364    urlbit = 'admin'
    33663365
    33673366    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
    33773367        self.client.login(username='super', password='secret')
    33783368
    33793369    def tearDown(self):
    33803370        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
    33863371
     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    )
    33873378    def testLangNamePresent(self):
    33883379        response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit)
    33893380        self.assertFalse(' lang=""' in response.content)
  • tests/regressiontests/templates/response.py

    diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
    index 5feb8cc..5167e36 100644
    a b import pickle  
    55import time
    66from datetime import datetime
    77
    8 from django.utils import unittest
    98from django.test import RequestFactory, TestCase
    109from django.conf import settings
    11 import django.template.context
    1210from django.template import Template, Context
    1311from django.template.response import (TemplateResponse, SimpleTemplateResponse,
    1412                                      ContentNotRenderedError)
     13from django.test.utils import override_settings
    1514
    1615def test_processor(request):
    1716    return {'processors': 'yes'}
    class CustomURLConfMiddleware(object):  
    2423        request.urlconf = 'regressiontests.templates.alternate_urls'
    2524
    2625
    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):
     26class SimpleTemplateResponseTest(TestCase):
    5327
    5428    def _response(self, template='foo', *args, **kwargs):
    5529        return SimpleTemplateResponse(Template(template), *args, **kwargs)
    class SimpleTemplateResponseTest(BaseTemplateResponseTest):  
    215189        unpickled_response = pickle.loads(pickled_response)
    216190        repickled_response = pickle.dumps(unpickled_response)
    217191
    218 class TemplateResponseTest(BaseTemplateResponseTest):
     192class TemplateResponseTest(TestCase):
     193
     194    def setUp(self):
     195        self.factory = RequestFactory()
    219196
    220197    def _response(self, template='foo', *args, **kwargs):
    221198        return TemplateResponse(self.factory.get('/'), Template(template),
    class TemplateResponseTest(BaseTemplateResponseTest):  
    299276        unpickled_response = pickle.loads(pickled_response)
    300277        repickled_response = pickle.dumps(unpickled_response)
    301278
     279TemplateResponseTest = override_settings(
     280    TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name],
     281    TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')),
     282)(TemplateResponseTest)
     283
    302284
    303285class CustomURLConfTest(TestCase):
    304286    urls = 'regressiontests.templates.urls'
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index f74aa75..9c56ee3 100644
    a b from .parser import ParserTests  
    3737from .unicode import UnicodeTests
    3838from .nodelist import NodelistTest, ErrorIndexTest
    3939from .smartif import SmartIfTests
    40 from .response import (TemplateResponseTest, BaseTemplateResponseTest,
    41     CacheMiddlewareTest, SimpleTemplateResponseTest, CustomURLConfTest)
     40from .response import (TemplateResponseTest, CacheMiddlewareTest,
     41    SimpleTemplateResponseTest, CustomURLConfTest)
    4242
    4343try:
    4444    from .loaders import RenderToStringTest, EggLoaderTest
    class TemplateTagLoading(unittest.TestCase):  
    17381738        t = template.Template(ttext)
    17391739
    17401740
    1741 class RequestContextTests(BaseTemplateResponseTest):
     1741class RequestContextTests(unittest.TestCase):
    17421742
    17431743    def setUp(self):
    17441744        templates = {
  • tests/regressiontests/views/tests/shortcuts.py

    diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py
    index 24bf6bb..df7a6fa 100644
    a b import warnings  
    22
    33from django.conf import settings
    44from django.test import TestCase
     5from django.test.utils import override_settings
    56
    67class ShortcutTests(TestCase):
    78    urls = 'regressiontests.views.generic_urls'
    class ShortcutTests(TestCase):  
    1112        warnings.filterwarnings('ignore', category=DeprecationWarning,
    1213                                module='django.views.generic.simple')
    1314
    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 
    2215    def tearDown(self):
    2316        self.restore_warnings_state()
    2417
    25     def tearDown(self):
    26         settings.STATIC_URL = self.old_STATIC_URL
    27         settings.TEMPLATE_CONTEXT_PROCESSORS = self.old_TEMPLATE_CONTEXT_PROCESSORS
    28 
    2918    def test_render_to_response(self):
    3019        response = self.client.get('/shortcuts/render_to_response/')
    3120        self.assertEqual(response.status_code, 200)
    class ShortcutTests(TestCase):  
    7564    def test_render_with_current_app_conflict(self):
    7665        self.assertRaises(ValueError, self.client.get, '/shortcuts/render/current_app_conflict/')
    7766
     67ShortcutTests = override_settings(
     68    TEMPLATE_CONTEXT_PROCESSORS=('django.core.context_processors.static',),
     69    STATIC_URL='/path/to/static/media/',
     70)(ShortcutTests)
Back to Top