Commit 883c38c4 authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #17848 -- Added setting_changed signal for cases when...

Fixed #17848 -- Added setting_changed signal for cases when TEMPLATE_CONTEXT_PROCESSORS is overriden in tests.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 36ab8ae2
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -30,13 +30,9 @@ class AuthContextProcessorTests(TestCase):
        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")

        context._standard_context_processors = None

    @override_settings(
        MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES,
        TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS,
@@ -46,13 +42,9 @@ class AuthContextProcessorTests(TestCase):
        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")

        context._standard_context_processors = None

    def test_perms_attrs(self):
        self.client.login(username='super', password='secret')
        response = self.client.get('/auth_processor_perms/')
+1 −2
Original line number Diff line number Diff line
@@ -259,8 +259,7 @@ class BaseTest(TestCase):
                              args=(level,))
            response = self.client.post(add_url, data, follow=True)
            self.assertRedirects(response, show_url)
            self.assertTrue('messages' in response.context)
            self.assertEqual(list(response.context['messages']), [])
            self.assertFalse('messages' in response.context)

    def stored_messages_count(self, storage, response):
        """
+7 −2
Original line number Diff line number Diff line
from django.conf import settings
from django.db import connections
from django.dispatch import Signal
from django.dispatch import receiver, Signal
from django.template import context

template_rendered = Signal(providing_args=["template", "context"])

setting_changed = Signal(providing_args=["setting", "value"])

@receiver(setting_changed)
def update_connections_time_zone(**kwargs):
    if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
        USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE
@@ -20,4 +22,7 @@ def update_connections_time_zone(**kwargs):
        if tz_sql:
            conn.cursor().execute(tz_sql, [tz])

setting_changed.connect(update_connections_time_zone)
@receiver(setting_changed)
def clear_context_processors_cache(**kwargs):
    if kwargs['setting'] == 'TEMPLATE_CONTEXT_PROCESSORS':
        context._standard_context_processors = None
+7 −16
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import re
import datetime
import urlparse

from django.conf import settings
from django.conf import settings, global_settings
from django.core import mail
from django.core.exceptions import SuspiciousOperation
from django.core.files import temp as tempfile
@@ -23,7 +23,6 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.forms.util import ErrorList
from django.template import context as context_module
from django.template.response import TemplateResponse
from django.test import TestCase
from django.utils import formats, translation, unittest
@@ -3364,25 +3363,17 @@ class ValidXHTMLTests(TestCase):
    urlbit = 'admin'

    def setUp(self):
        self._context_processors = None
        self._use_i18n, settings.USE_I18N = settings.USE_I18N, False
        if 'django.core.context_processors.i18n' in settings.TEMPLATE_CONTEXT_PROCESSORS:
            self._context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
            cp = list(settings.TEMPLATE_CONTEXT_PROCESSORS)
            cp.remove('django.core.context_processors.i18n')
            settings.TEMPLATE_CONTEXT_PROCESSORS = tuple(cp)
            # Force re-evaluation of the contex processor list
            context_module._standard_context_processors = None
        self.client.login(username='super', password='secret')

    def tearDown(self):
        self.client.logout()
        if self._context_processors is not None:
            settings.TEMPLATE_CONTEXT_PROCESSORS = self._context_processors
            # Force re-evaluation of the contex processor list
            context_module._standard_context_processors = None
        settings.USE_I18N = self._use_i18n

    @override_settings(
        TEMPLATE_CONTEXT_PROCESSORS=filter(
            lambda t:t!='django.core.context_processors.i18n',
            global_settings.TEMPLATE_CONTEXT_PROCESSORS),
        USE_I18N=False,
    )
    def testLangNamePresent(self):
        response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit)
        self.assertFalse(' lang=""' in response.content)
+10 −29
Original line number Diff line number Diff line
@@ -3,13 +3,12 @@ import pickle
import time
from datetime import datetime

from django.utils import unittest
from django.test import RequestFactory, TestCase
from django.conf import settings
import django.template.context
from django.template import Template, Context
from django.template.response import (TemplateResponse, SimpleTemplateResponse,
                                      ContentNotRenderedError)
from django.test.utils import override_settings

def test_processor(request):
    return {'processors': 'yes'}
@@ -22,32 +21,7 @@ class CustomURLConfMiddleware(object):
        request.urlconf = 'regressiontests.templates.alternate_urls'


class BaseTemplateResponseTest(unittest.TestCase):
    # tests rely on fact that global context
    # processors should only work when RequestContext is used.

    def setUp(self):
        self.factory = RequestFactory()
        self._old_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
        self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
        settings.TEMPLATE_CONTEXT_PROCESSORS = [test_processor_name]
        settings.TEMPLATE_DIRS = (
            os.path.join(
                os.path.dirname(__file__),
                'templates'
            ),
        )
        # Force re-evaluation of the contex processor list
        django.template.context._standard_context_processors = None

    def tearDown(self):
        settings.TEMPLATE_DIRS = self._old_TEMPLATE_DIRS
        settings.TEMPLATE_CONTEXT_PROCESSORS = self._old_processors
        # Force re-evaluation of the contex processor list
        django.template.context._standard_context_processors = None


class SimpleTemplateResponseTest(BaseTemplateResponseTest):
class SimpleTemplateResponseTest(TestCase):

    def _response(self, template='foo', *args, **kwargs):
        return SimpleTemplateResponse(Template(template), *args, **kwargs)
@@ -213,7 +187,14 @@ class SimpleTemplateResponseTest(BaseTemplateResponseTest):
        unpickled_response = pickle.loads(pickled_response)
        repickled_response = pickle.dumps(unpickled_response)

class TemplateResponseTest(BaseTemplateResponseTest):
@override_settings(
    TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name],
    TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')),
)
class TemplateResponseTest(TestCase):

    def setUp(self):
        self.factory = RequestFactory()

    def _response(self, template='foo', *args, **kwargs):
        return TemplateResponse(self.factory.get('/'), Template(template),
Loading