Fixed #18042 -- Advanced deprecation warnings.

Thanks Ramiro for the patch.
This commit is contained in:
Aymeric Augustin 2012-05-03 15:27:01 +02:00
parent 227cec686e
commit e84f79f051
27 changed files with 75 additions and 38 deletions

View file

@ -1442,12 +1442,18 @@ def hello_world_view(request, value):
)
class CacheMiddlewareTest(TestCase):
# The following tests will need to be modified in Django 1.6 to not use
# deprecated ways of using the cache_page decorator that will be removed in
# such version
def setUp(self):
self.factory = RequestFactory()
self.default_cache = get_cache('default')
self.other_cache = get_cache('other')
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.views.decorators.cache')
def tearDown(self):
self.restore_warnings_state()
self.default_cache.clear()
self.other_cache.clear()

View file

@ -70,7 +70,7 @@ class DecoratorsTest(TestCase):
def setUp(self):
self.warning_state = get_warnings_state()
warnings.filterwarnings('ignore', category=PendingDeprecationWarning,
warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.views.decorators.cache')
def tearDown(self):

View file

@ -1,9 +1,10 @@
import copy
import warnings
from django.conf import compat_patch_logging_config
from django.core import mail
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.test.utils import override_settings, get_warnings_state, restore_warnings_state
from django.utils.log import CallbackFilter, RequireDebugFalse, getLogger
@ -40,7 +41,13 @@ class PatchLoggingConfigTest(TestCase):
"""
config = copy.deepcopy(OLD_LOGGING)
compat_patch_logging_config(config)
warnings_state = get_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.conf')
try:
compat_patch_logging_config(config)
finally:
restore_warnings_state(warnings_state)
self.assertEqual(
config["handlers"]["mail_admins"]["filters"],

View file

@ -420,5 +420,10 @@ class RequestsTests(unittest.TestCase):
'CONTENT_LENGTH': len(payload),
'wsgi.input': ExplodingStringIO(payload)})
with self.assertRaises(UnreadablePostError):
request.raw_post_data
warnings_state = get_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.http')
try:
with self.assertRaises(UnreadablePostError):
request.raw_post_data
finally:
restore_warnings_state(warnings_state)

View file

@ -1,4 +1,5 @@
import os
import warnings
from django.conf import settings, global_settings
from django.core.exceptions import ImproperlyConfigured
@ -274,10 +275,14 @@ class EnvironmentVariableTest(TestCase):
Ensures proper settings file is used in setup_environ if
DJANGO_SETTINGS_MODULE is set in the environment.
"""
# Decide what to do with these tests when setup_environ() gets removed in Django 1.6
def setUp(self):
self.original_value = os.environ.get('DJANGO_SETTINGS_MODULE')
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.core.management')
def tearDown(self):
self.restore_warnings_state()
if self.original_value:
os.environ['DJANGO_SETTINGS_MODULE'] = self.original_value
elif 'DJANGO_SETTINGS_MODULE' in os.environ:

View file

@ -1,9 +1,19 @@
# -*- coding: utf-8 -*-
import unittest
import warnings
from django.test import SimpleTestCase
from django.utils import text
class TestUtilsText(unittest.TestCase):
class TestUtilsText(SimpleTestCase):
# In Django 1.6 truncate_words() and truncate_html_words() will be removed
# so these tests will need to be adapted accordingly
def setUp(self):
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.utils.text')
def tearDown(self):
self.restore_warnings_state()
def test_truncate_chars(self):
truncator = text.Truncator(