Used catch_warnings instead of save/restore methods. Refs #17049.

This commit is contained in:
Claude Paroz
2012-05-03 18:19:18 +02:00
parent 8fb9b1804b
commit 91387d75d0

View File

@@ -7,16 +7,12 @@ from django.conf import settings
from django.contrib.formtools import preview, utils
from django.contrib.formtools.wizard import FormWizard
from django.test import TestCase
from django.test.utils import get_warnings_state, restore_warnings_state
from django.test.utils import override_settings
from django.utils import unittest
from django.contrib.formtools.tests.wizard import *
from django.contrib.formtools.tests.forms import *
warnings.filterwarnings('ignore', category=PendingDeprecationWarning,
module='django.contrib.formtools.wizard')
success_string = "Done was called!"
class TestFormPreview(preview.FormPreview):
@@ -41,20 +37,12 @@ class PreviewTests(TestCase):
def setUp(self):
super(PreviewTests, self).setUp()
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.contrib.formtools.wizard.legacy')
# Create a FormPreview instance to share between tests
self.preview = preview.FormPreview(TestForm)
input_template = '<input type="hidden" name="%s" value="%s" />'
self.input = input_template % (self.preview.unused_name('stage'), "%d")
self.test_data = {'field1':u'foo', 'field1_':u'asdf'}
def tearDown(self):
super(PreviewTests, self).tearDown()
self.restore_warnings_state()
def test_unused_name(self):
"""
Verifies name mangling to get uniue field name.
@@ -130,8 +118,9 @@ class PreviewTests(TestCase):
self.test_data.update({'stage':2})
hash = self.preview.security_hash(None, TestForm(self.test_data))
self.test_data.update({'hash':hash, 'bool1':u'False'})
response = self.client.post('/preview/', self.test_data)
self.assertEqual(response.content, success_string)
with warnings.catch_warnings(record=True):
response = self.client.post('/preview/', self.test_data)
self.assertEqual(response.content, success_string)
def test_form_submit_good_hash(self):
"""
@@ -241,6 +230,16 @@ class WizardTests(TestCase):
}
)
def setUp(self):
super(WizardTests, self).setUp()
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.contrib.formtools.wizard')
def tearDown(self):
super(WizardTests, self).tearDown()
self.restore_warnings_state()
def test_step_starts_at_zero(self):
"""
step should be zero for the first form