Ticket #16366: 16366-4.diff

File 16366-4.diff, 2.5 KB (added by ryankask, 3 years ago)
  • 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 49172c6..8f77940 100644
    a b  
    11import os
    22
    3 from django.conf import settings
     3from django.conf import global_settings
    44from django.contrib.auth import authenticate
    55from django.db.models import Q
     6from django.template import context
    67from django.test import TestCase
     8from django.test.utils import override_settings
    79
    810
    911class AuthContextProcessorTests(TestCase):
    class AuthContextProcessorTests(TestCase): 
    1315    urls = 'django.contrib.auth.tests.urls'
    1416    fixtures = ['context-processors-users.xml']
    1517
    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    )
    2522    def test_session_not_accessed(self):
    2623        """
    2724        Tests that the session is not accessed simply by including
    2825        the auth context processor
    2926        """
     27        context._standard_context_processors = None
     28
    3029        response = self.client.get('/auth_processor_no_attr_access/')
    3130        self.assertContains(response, "Session not accessed")
    3231
     32    @override_settings(
     33        MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES,
     34        TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS,
     35    )
    3336    def test_session_is_accessed(self):
    3437        """
    3538        Tests that the session is accessed if the auth context processor
    3639        is used and relevant attributes accessed.
    3740        """
     41        context._standard_context_processors = None
     42
    3843        response = self.client.get('/auth_processor_attr_access/')
    3944        self.assertContains(response, "Session accessed")
    4045
    class AuthContextProcessorTests(TestCase): 
    8691        # See bug #12060
    8792        self.assertEqual(response.context['user'], user)
    8893        self.assertEqual(user, response.context['user'])
     94
     95AuthContextProcessorTests = override_settings(
     96    TEMPLATE_DIRS = (
     97            os.path.join(os.path.dirname(__file__), 'templates'),
     98        )
     99)(AuthContextProcessorTests)
Back to Top