Ticket #16507: 16507.2.diff
File 16507.2.diff, 4.4 KB (added by , 13 years ago) |
---|
-
django/contrib/messages/tests/cookie.py
3 3 from django.contrib.messages.storage.cookie import (CookieStorage, 4 4 MessageEncoder, MessageDecoder) 5 5 from django.contrib.messages.storage.base import Message 6 from django.test.utils import override_settings 6 7 from django.utils import simplejson as json 7 8 from django.conf import settings 8 9 … … 41 42 class CookieTest(BaseTest): 42 43 storage_class = CookieStorage 43 44 44 def setUp(self):45 super(CookieTest, self).setUp()46 self.old_SESSION_COOKIE_DOMAIN = settings.SESSION_COOKIE_DOMAIN47 settings.SESSION_COOKIE_DOMAIN = '.lawrence.com'48 49 def tearDown(self):50 super(CookieTest, self).tearDown()51 settings.SESSION_COOKIE_DOMAIN = self.old_SESSION_COOKIE_DOMAIN52 53 45 def stored_messages_count(self, storage, response): 54 46 return stored_cookie_messages_count(storage, response) 55 47 … … 139 131 value = encoder.encode(messages) 140 132 decoded_messages = json.loads(value, cls=MessageDecoder) 141 133 self.assertEqual(messages, decoded_messages) 134 135 136 CookieTest = override_settings( 137 SESSION_COOKIE_DOMAIN='.lawrence.com')(CookieTest) -
django/contrib/messages/tests/base.py
1 1 from django import http 2 2 from django.test import TestCase 3 from django.test.utils import override_settings 3 4 from django.conf import settings 4 5 from django.utils.translation import ugettext_lazy 5 6 from django.utils.unittest import skipIf … … 31 32 32 33 class BaseTest(TestCase): 33 34 storage_class = default_storage 34 restore_settings = ['MESSAGE_LEVEL', 'MESSAGE_TAGS']35 35 urls = 'django.contrib.messages.tests.urls' 36 36 levels = { 37 37 'debug': constants.DEBUG, … … 42 42 } 43 43 44 44 def setUp(self): 45 self._remembered_settings = {}46 for setting in self.restore_settings:47 if hasattr(settings, setting):48 self._remembered_settings[setting] = getattr(settings, setting)49 delattr(settings._wrapped, setting)50 # Backup these manually because we do not want them deleted.51 45 self._middleware_classes = settings.MIDDLEWARE_CLASSES 52 46 self._template_context_processors = \ 53 47 settings.TEMPLATE_CONTEXT_PROCESSORS … … 55 49 self._message_storage = settings.MESSAGE_STORAGE 56 50 settings.MESSAGE_STORAGE = '%s.%s' % (self.storage_class.__module__, 57 51 self.storage_class.__name__) 58 self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS59 settings.TEMPLATE_DIRS = ()60 52 61 53 def tearDown(self): 62 for setting in self.restore_settings:63 self.restore_setting(setting)64 # Restore these manually (see above).65 54 settings.MIDDLEWARE_CLASSES = self._middleware_classes 66 55 settings.TEMPLATE_CONTEXT_PROCESSORS = \ 67 56 self._template_context_processors 68 57 settings.INSTALLED_APPS = self._installed_apps 69 58 settings.MESSAGE_STORAGE = self._message_storage 70 settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS71 59 72 def restore_setting(self, setting):73 if setting in self._remembered_settings:74 value = self._remembered_settings.pop(setting)75 setattr(settings, setting, value)76 elif hasattr(settings, setting):77 delattr(settings._wrapped, setting)78 79 60 def get_request(self): 80 61 return http.HttpRequest() 81 62 … … 390 371 ['info', 'custom', 'extra-tag', '', 'bad', 'success']) 391 372 finally: 392 373 # Ensure the level tags constant is put back like we found it. 393 se lf.restore_setting('MESSAGE_TAGS')374 settings.MESSAGE_TAGS = {} 394 375 base.LEVEL_TAGS = utils.get_level_tags() 376 377 378 BaseTest = override_settings( 379 DEBUG_PROPAGATE_EXCEPTIONS=True, 380 # this is the default value, see storage.base.BaseStorage._get_level() 381 MESSAGE_LEVEL=constants.INFO, 382 # this is the default value, see utils.get_level_tags() 383 MESSAGE_TAGS={}, 384 TEMPLATE_DIRS=())(BaseTest)