Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.

Thanks Vinay Sajip for the support of his django3 branch and
Jannis Leidel for the review.
This commit is contained in:
Claude Paroz
2012-06-07 18:08:47 +02:00
parent a3e41a8193
commit c0fb8c1858
4 changed files with 63 additions and 55 deletions

View File

@@ -1,3 +1,5 @@
from __future__ import unicode_literals
import os
import re
import warnings
@@ -41,7 +43,7 @@ class PreviewTests(TestCase):
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'}
self.test_data = {'field1': 'foo', 'field1_': 'asdf'}
def test_unused_name(self):
"""
@@ -117,7 +119,7 @@ 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'})
self.test_data.update({'hash': hash, 'bool1': 'False'})
with warnings.catch_warnings(record=True):
response = self.client.post('/preview/', self.test_data)
self.assertEqual(response.content, success_string)
@@ -163,8 +165,8 @@ class FormHmacTests(unittest.TestCase):
leading/trailing whitespace so as to be friendly to broken browsers that
submit it (usually in textareas).
"""
f1 = HashTestForm({'name': u'joe', 'bio': u'Nothing notable.'})
f2 = HashTestForm({'name': u' joe', 'bio': u'Nothing notable. '})
f1 = HashTestForm({'name': 'joe', 'bio': 'Nothing notable.'})
f2 = HashTestForm({'name': ' joe', 'bio': 'Nothing notable. '})
hash1 = utils.form_hmac(f1)
hash2 = utils.form_hmac(f2)
self.assertEqual(hash1, hash2)
@@ -266,10 +268,10 @@ class WizardTests(TestCase):
Form should advance if the hash is present and good, as calculated using
current method.
"""
data = {"0-field": u"test",
"1-field": u"test2",
"hash_0": u"cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": u"1"}
data = {"0-field": "test",
"1-field": "test2",
"hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
response = self.client.post('/wizard1/', data)
self.assertEqual(2, response.context['step0'])
@@ -291,18 +293,18 @@ class WizardTests(TestCase):
reached[0] = True
wizard = WizardWithProcessStep([WizardPageOneForm])
data = {"0-field": u"test",
"1-field": u"test2",
"hash_0": u"cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": u"1"}
data = {"0-field": "test",
"1-field": "test2",
"hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
data = {"0-field": u"test",
"1-field": u"test2",
data = {"0-field": "test",
"1-field": "test2",
"hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"hash_1": u"1e6f6315da42e62f33a30640ec7e007ad3fbf1a1",
"wizard_step": u"2"}
"hash_1": "1e6f6315da42e62f33a30640ec7e007ad3fbf1a1",
"wizard_step": "2"}
self.assertRaises(http.Http404, wizard, DummyRequest(POST=data))
def test_14498(self):
@@ -321,10 +323,10 @@ class WizardTests(TestCase):
wizard = WizardWithProcessStep([WizardPageOneForm,
WizardPageTwoForm,
WizardPageThreeForm])
data = {"0-field": u"test",
"1-field": u"test2",
"hash_0": u"cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": u"1"}
data = {"0-field": "test",
"1-field": "test2",
"hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
@@ -345,10 +347,10 @@ class WizardTests(TestCase):
wizard = Wizard([WizardPageOneForm,
WizardPageTwoForm])
data = {"0-field": u"test",
"1-field": u"test2",
"hash_0": u"cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": u"1"}
data = {"0-field": "test",
"1-field": "test2",
"hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
@@ -371,10 +373,10 @@ class WizardTests(TestCase):
wizard = WizardWithProcessStep([WizardPageOneForm,
WizardPageTwoForm,
WizardPageThreeForm])
data = {"0-field": u"test",
"1-field": u"test2",
"hash_0": u"cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": u"1"}
data = {"0-field": "test",
"1-field": "test2",
"hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])

View File

@@ -1,3 +1,5 @@
from __future__ import unicode_literals
from django import forms, http
from django.conf import settings
from django.test import TestCase
@@ -64,22 +66,22 @@ class TestWizard(WizardView):
class FormTests(TestCase):
def test_form_init(self):
testform = TestWizard.get_initkwargs([Step1, Step2])
self.assertEqual(testform['form_list'], {u'0': Step1, u'1': Step2})
self.assertEqual(testform['form_list'], {'0': Step1, '1': Step2})
testform = TestWizard.get_initkwargs([('start', Step1), ('step2', Step2)])
self.assertEqual(
testform['form_list'], {u'start': Step1, u'step2': Step2})
testform['form_list'], {'start': Step1, 'step2': Step2})
testform = TestWizard.get_initkwargs([Step1, Step2, ('finish', Step3)])
self.assertEqual(
testform['form_list'], {u'0': Step1, u'1': Step2, u'finish': Step3})
testform['form_list'], {'0': Step1, '1': Step2, 'finish': Step3})
def test_first_step(self):
request = get_request()
testform = TestWizard.as_view([Step1, Step2])
response, instance = testform(request)
self.assertEqual(instance.steps.current, u'0')
self.assertEqual(instance.steps.current, '0')
testform = TestWizard.as_view([('start', Step1), ('step2', Step2)])
response, instance = testform(request)

View File

@@ -1,3 +1,5 @@
from __future__ import unicode_literals
from django.core.urlresolvers import reverse
from django.http import QueryDict
from django.test import TestCase
@@ -51,8 +53,8 @@ class NamedWizardTests(object):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form1')
self.assertEqual(response.context['wizard']['form'].errors,
{'name': [u'This field is required.'],
'user': [u'This field is required.']})
{'name': ['This field is required.'],
'user': ['This field is required.']})
def test_form_post_success(self):
response = self.client.post(
@@ -150,10 +152,10 @@ class NamedWizardTests(object):
self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
del all_data[1]['file1']
self.assertEqual(all_data, [
{'name': u'Pony', 'thirsty': True, 'user': self.testuser},
{'address1': u'123 Main St', 'address2': u'Djangoland'},
{'random_crap': u'blah blah'},
[{'random_crap': u'blah blah'}, {'random_crap': u'blah blah'}]])
{'name': 'Pony', 'thirsty': True, 'user': self.testuser},
{'address1': '123 Main St', 'address2': 'Djangoland'},
{'random_crap': 'blah blah'},
[{'random_crap': 'blah blah'}, {'random_crap': 'blah blah'}]])
def test_cleaned_data(self):
response = self.client.get(
@@ -203,11 +205,11 @@ class NamedWizardTests(object):
del all_data['file1']
self.assertEqual(
all_data,
{'name': u'Pony', 'thirsty': True, 'user': self.testuser,
'address1': u'123 Main St', 'address2': u'Djangoland',
'random_crap': u'blah blah', 'formset-form4': [
{'random_crap': u'blah blah'},
{'random_crap': u'blah blah'}
{'name': 'Pony', 'thirsty': True, 'user': self.testuser,
'address1': '123 Main St', 'address2': 'Djangoland',
'random_crap': 'blah blah', 'formset-form4': [
{'random_crap': 'blah blah'},
{'random_crap': 'blah blah'}
]})
def test_manipulated_data(self):

View File

@@ -1,3 +1,5 @@
from __future__ import unicode_literals
import os
from django import forms
@@ -33,8 +35,8 @@ class WizardTests(object):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form1')
self.assertEqual(response.context['wizard']['form'].errors,
{'name': [u'This field is required.'],
'user': [u'This field is required.']})
{'name': ['This field is required.'],
'user': ['This field is required.']})
def test_form_post_success(self):
response = self.client.post(self.wizard_url, self.wizard_step_data[0])
@@ -96,11 +98,11 @@ class WizardTests(object):
self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
del all_data[1]['file1']
self.assertEqual(all_data, [
{'name': u'Pony', 'thirsty': True, 'user': self.testuser},
{'address1': u'123 Main St', 'address2': u'Djangoland'},
{'random_crap': u'blah blah'},
[{'random_crap': u'blah blah'},
{'random_crap': u'blah blah'}]])
{'name': 'Pony', 'thirsty': True, 'user': self.testuser},
{'address1': '123 Main St', 'address2': 'Djangoland'},
{'random_crap': 'blah blah'},
[{'random_crap': 'blah blah'},
{'random_crap': 'blah blah'}]])
def test_cleaned_data(self):
response = self.client.get(self.wizard_url)
@@ -124,11 +126,11 @@ class WizardTests(object):
self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
del all_data['file1']
self.assertEqual(all_data, {
'name': u'Pony', 'thirsty': True, 'user': self.testuser,
'address1': u'123 Main St', 'address2': u'Djangoland',
'random_crap': u'blah blah', 'formset-form4': [
{'random_crap': u'blah blah'},
{'random_crap': u'blah blah'}]})
'name': 'Pony', 'thirsty': True, 'user': self.testuser,
'address1': '123 Main St', 'address2': 'Djangoland',
'random_crap': 'blah blah', 'formset-form4': [
{'random_crap': 'blah blah'},
{'random_crap': 'blah blah'}]})
def test_manipulated_data(self):
response = self.client.get(self.wizard_url)