summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-07-20 14:48:51 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-07-22 09:29:54 +0200
commitbdca5ea345c548a82a80d198906818c9ccbef896 (patch)
tree5c3f5fe5ad2522175d67b96a1fce1ff1763ba125 /tests/regressiontests
parent3cb2457f46b3e40ff6b6acffcb3fd44cbea091e5 (diff)
[py3] Replaced unicode/str by six.text_type/bytes.
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/admin_changelist/tests.py9
-rw-r--r--tests/regressiontests/admin_util/models.py3
-rw-r--r--tests/regressiontests/admin_util/tests.py7
-rw-r--r--tests/regressiontests/admin_views/tests.py7
-rw-r--r--tests/regressiontests/backends/tests.py5
-rw-r--r--tests/regressiontests/datatypes/tests.py3
-rw-r--r--tests/regressiontests/defaultfilters/tests.py7
-rw-r--r--tests/regressiontests/file_uploads/views.py3
-rw-r--r--tests/regressiontests/fixtures_regress/models.py3
-rw-r--r--tests/regressiontests/forms/tests/models.py3
-rw-r--r--tests/regressiontests/forms/tests/util.py3
-rw-r--r--tests/regressiontests/forms/tests/widgets.py7
-rw-r--r--tests/regressiontests/i18n/contenttypes/tests.py7
-rw-r--r--tests/regressiontests/i18n/tests.py9
-rw-r--r--tests/regressiontests/inline_formsets/tests.py5
-rw-r--r--tests/regressiontests/model_forms_regress/tests.py9
-rw-r--r--tests/regressiontests/model_formsets_regress/tests.py11
-rw-r--r--tests/regressiontests/model_regress/tests.py5
-rw-r--r--tests/regressiontests/queries/models.py3
-rw-r--r--tests/regressiontests/select_related_regress/tests.py5
-rw-r--r--tests/regressiontests/templates/templatetags/custom.py23
-rw-r--r--tests/regressiontests/templates/unicode.py3
-rw-r--r--tests/regressiontests/utils/simplelazyobject.py7
-rw-r--r--tests/regressiontests/wsgi/tests.py3
24 files changed, 87 insertions, 63 deletions
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index 62166ce174..1ed963aaf2 100644
--- a/tests/regressiontests/admin_changelist/tests.py
+++ b/tests/regressiontests/admin_changelist/tests.py
@@ -10,6 +10,7 @@ from django.template import Context, Template
from django.test import TestCase
from django.test.client import RequestFactory
from django.utils import formats
+from django.utils import six
from .admin import (ChildAdmin, QuartetAdmin, BandAdmin, ChordsBandAdmin,
GroupAdmin, ParentAdmin, DynamicListDisplayChildAdmin,
@@ -339,7 +340,7 @@ class ChangeListTests(TestCase):
event = Event.objects.create(date=datetime.date.today())
response = self.client.get('/admin/admin_changelist/event/')
self.assertContains(response, formats.localize(event.date))
- self.assertNotContains(response, unicode(event.date))
+ self.assertNotContains(response, six.text_type(event.date))
def test_dynamic_list_display(self):
"""
@@ -443,9 +444,9 @@ class ChangeListTests(TestCase):
request = self._mocked_authenticated_request('/swallow/', superuser)
response = model_admin.changelist_view(request)
# just want to ensure it doesn't blow up during rendering
- self.assertContains(response, unicode(swallow.origin))
- self.assertContains(response, unicode(swallow.load))
- self.assertContains(response, unicode(swallow.speed))
+ self.assertContains(response, six.text_type(swallow.origin))
+ self.assertContains(response, six.text_type(swallow.load))
+ self.assertContains(response, six.text_type(swallow.speed))
def test_deterministic_order_for_unordered_model(self):
"""
diff --git a/tests/regressiontests/admin_util/models.py b/tests/regressiontests/admin_util/models.py
index 0e81df3817..5541097022 100644
--- a/tests/regressiontests/admin_util/models.py
+++ b/tests/regressiontests/admin_util/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.utils import six
class Article(models.Model):
@@ -22,7 +23,7 @@ class Count(models.Model):
parent = models.ForeignKey('self', null=True)
def __unicode__(self):
- return unicode(self.num)
+ return six.text_type(self.num)
class Event(models.Model):
date = models.DateTimeField(auto_now_add=True)
diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py
index ba2be363ca..6b6dad4336 100644
--- a/tests/regressiontests/admin_util/tests.py
+++ b/tests/regressiontests/admin_util/tests.py
@@ -15,6 +15,7 @@ from django.test import TestCase
from django.utils import unittest
from django.utils.formats import localize
from django.utils.safestring import mark_safe
+from django.utils import six
from .models import Article, Count, Event, Location
@@ -249,17 +250,17 @@ class UtilTests(unittest.TestCase):
log_entry.action_flag = admin.models.ADDITION
self.assertTrue(
- unicode(log_entry).startswith('Added ')
+ six.text_type(log_entry).startswith('Added ')
)
log_entry.action_flag = admin.models.CHANGE
self.assertTrue(
- unicode(log_entry).startswith('Changed ')
+ six.text_type(log_entry).startswith('Changed ')
)
log_entry.action_flag = admin.models.DELETION
self.assertTrue(
- unicode(log_entry).startswith('Deleted ')
+ six.text_type(log_entry).startswith('Deleted ')
)
def test_safestring_in_field_label(self):
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 630758a91d..a139016f27 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -30,6 +30,7 @@ from django.utils.cache import get_max_age
from django.utils.encoding import iri_to_uri
from django.utils.html import escape
from django.utils.http import urlencode
+from django.utils import six
from django.test.utils import override_settings
# local test models
@@ -2478,7 +2479,7 @@ class AdminCustomQuerysetTest(TestCase):
response = self.client.post('/test_admin/admin/admin_views/paper/%s/' % p.pk,
post_data, follow=True)
self.assertEqual(response.status_code, 200)
- # Message should contain non-ugly model name. Instance representation is set by unicode() (ugly)
+ # Message should contain non-ugly model name. Instance representation is set by six.text_type() (ugly)
self.assertContains(response, '<li class="info">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
# defer() is used in ModelAdmin.queryset()
@@ -2530,8 +2531,8 @@ class AdminInlineFileUploadTest(TestCase):
"pictures-TOTAL_FORMS": "2",
"pictures-INITIAL_FORMS": "1",
"pictures-MAX_NUM_FORMS": "0",
- "pictures-0-id": unicode(self.picture.id),
- "pictures-0-gallery": unicode(self.gallery.id),
+ "pictures-0-id": six.text_type(self.picture.id),
+ "pictures-0-gallery": six.text_type(self.gallery.id),
"pictures-0-name": "Test Picture",
"pictures-0-image": "",
"pictures-1-id": "",
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index cb25ac0a32..fa41aa7401 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -16,6 +16,7 @@ from django.db.utils import ConnectionHandler, DatabaseError, load_backend
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
TransactionTestCase)
from django.test.utils import override_settings
+from django.utils import six
from django.utils import unittest
from . import models
@@ -50,7 +51,7 @@ class OracleChecks(unittest.TestCase):
# than 4000 chars and read it properly
c = connection.cursor()
c.execute('CREATE TABLE ltext ("TEXT" NCLOB)')
- long_str = ''.join([unicode(x) for x in xrange(4000)])
+ long_str = ''.join([six.text_type(x) for x in xrange(4000)])
c.execute('INSERT INTO ltext VALUES (%s)',[long_str])
c.execute('SELECT text FROM ltext')
row = c.fetchone()
@@ -154,7 +155,7 @@ class LastExecutedQueryTest(TestCase):
sql, params = tags.query.sql_with_params()
cursor = tags.query.get_compiler('default').execute_sql(None)
last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
- self.assertTrue(isinstance(last_sql, unicode))
+ self.assertTrue(isinstance(last_sql, six.text_type))
class ParameterHandlingTest(TestCase):
diff --git a/tests/regressiontests/datatypes/tests.py b/tests/regressiontests/datatypes/tests.py
index f8f6802041..f0ec5f3c0a 100644
--- a/tests/regressiontests/datatypes/tests.py
+++ b/tests/regressiontests/datatypes/tests.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
import datetime
from django.test import TestCase, skipIfDBFeature
+from django.utils import six
from django.utils.timezone import utc
from .models import Donut, RumBaba
@@ -73,7 +74,7 @@ class DataTypesTestCase(TestCase):
database should be unicode."""
d = Donut.objects.create(name='Jelly Donut', review='Outstanding')
newd = Donut.objects.get(id=d.id)
- self.assertTrue(isinstance(newd.review, unicode))
+ self.assertTrue(isinstance(newd.review, six.text_type))
@skipIfDBFeature('supports_timezones')
def test_error_on_timezone(self):
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index ffa0a01132..e2907632ef 100644
--- a/tests/regressiontests/defaultfilters/tests.py
+++ b/tests/regressiontests/defaultfilters/tests.py
@@ -6,6 +6,7 @@ import decimal
from django.template.defaultfilters import *
from django.test import TestCase
+from django.utils import six
from django.utils import unittest, translation
from django.utils.safestring import SafeData
@@ -48,13 +49,13 @@ class DefaultFiltersTests(TestCase):
'0.00000000000000000002')
pos_inf = float(1e30000)
- self.assertEqual(floatformat(pos_inf), unicode(pos_inf))
+ self.assertEqual(floatformat(pos_inf), six.text_type(pos_inf))
neg_inf = float(-1e30000)
- self.assertEqual(floatformat(neg_inf), unicode(neg_inf))
+ self.assertEqual(floatformat(neg_inf), six.text_type(neg_inf))
nan = pos_inf / pos_inf
- self.assertEqual(floatformat(nan), unicode(nan))
+ self.assertEqual(floatformat(nan), six.text_type(nan))
class FloatWrapper(object):
def __init__(self, value):
diff --git a/tests/regressiontests/file_uploads/views.py b/tests/regressiontests/file_uploads/views.py
index 73b09cbcff..c5d2720e1a 100644
--- a/tests/regressiontests/file_uploads/views.py
+++ b/tests/regressiontests/file_uploads/views.py
@@ -6,6 +6,7 @@ import os
from django.core.files.uploadedfile import UploadedFile
from django.http import HttpResponse, HttpResponseServerError
+from django.utils import six
from .models import FileModel, UPLOAD_TO
from .tests import UNICODE_FILENAME
@@ -19,7 +20,7 @@ def file_upload_view(request):
"""
form_data = request.POST.copy()
form_data.update(request.FILES)
- if isinstance(form_data.get('file_field'), UploadedFile) and isinstance(form_data['name'], unicode):
+ if isinstance(form_data.get('file_field'), UploadedFile) and isinstance(form_data['name'], six.text_type):
# If a file is posted, the dummy client should only post the file name,
# not the full path.
if os.path.dirname(form_data['file_field'].name) != '':
diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py
index 14cf880003..7151cb0ed9 100644
--- a/tests/regressiontests/fixtures_regress/models.py
+++ b/tests/regressiontests/fixtures_regress/models.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
from django.contrib.auth.models import User
from django.db import models
+from django.utils import six
class Animal(models.Model):
@@ -29,7 +30,7 @@ class Stuff(models.Model):
owner = models.ForeignKey(User, null=True)
def __unicode__(self):
- return unicode(self.name) + ' is owned by ' + unicode(self.owner)
+ return six.text_type(self.name) + ' is owned by ' + six.text_type(self.owner)
class Absolute(models.Model):
diff --git a/tests/regressiontests/forms/tests/models.py b/tests/regressiontests/forms/tests/models.py
index 5bea49b840..7687335b48 100644
--- a/tests/regressiontests/forms/tests/models.py
+++ b/tests/regressiontests/forms/tests/models.py
@@ -8,6 +8,7 @@ from django.db import models
from django.forms import Form, ModelForm, FileField, ModelChoiceField
from django.forms.models import ModelFormMetaclass
from django.test import TestCase
+from django.utils import six
from ..models import (ChoiceOptionModel, ChoiceFieldModel, FileModel, Group,
BoundaryModel, Defaults)
@@ -40,7 +41,7 @@ class ModelFormCallableModelDefault(TestCase):
choices = list(ChoiceFieldForm().fields['choice'].choices)
self.assertEqual(len(choices), 1)
- self.assertEqual(choices[0], (option.pk, unicode(option)))
+ self.assertEqual(choices[0], (option.pk, six.text_type(option)))
def test_callable_initial_value(self):
"The initial value for a callable default returning a queryset is the pk (refs #13769)"
diff --git a/tests/regressiontests/forms/tests/util.py b/tests/regressiontests/forms/tests/util.py
index 280049c97b..b7cc4ec809 100644
--- a/tests/regressiontests/forms/tests/util.py
+++ b/tests/regressiontests/forms/tests/util.py
@@ -5,6 +5,7 @@ from django.core.exceptions import ValidationError
from django.forms.util import flatatt, ErrorDict, ErrorList
from django.test import TestCase
from django.utils.safestring import mark_safe
+from django.utils import six
from django.utils.translation import ugettext_lazy
@@ -30,7 +31,7 @@ class FormsUtilTestCase(TestCase):
'<ul class="errorlist"><li>There was an error.</li></ul>')
# Can take a unicode string.
- self.assertHTMLEqual(unicode(ErrorList(ValidationError("Not \u03C0.").messages)),
+ self.assertHTMLEqual(six.text_type(ErrorList(ValidationError("Not \u03C0.").messages)),
'<ul class="errorlist"><li>Not π.</li></ul>')
# Can take a lazy string.
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index d5f6334fe9..3ea42cf549 100644
--- a/tests/regressiontests/forms/tests/widgets.py
+++ b/tests/regressiontests/forms/tests/widgets.py
@@ -10,6 +10,7 @@ from django.forms import *
from django.forms.widgets import RadioFieldRenderer
from django.utils import formats
from django.utils.safestring import mark_safe
+from django.utils import six
from django.utils.translation import activate, deactivate
from django.test import TestCase
@@ -676,7 +677,7 @@ beatle J R Ringo False""")
# You can create your own custom renderers for RadioSelect to use.
class MyRenderer(RadioFieldRenderer):
def render(self):
- return '<br />\n'.join([unicode(choice) for choice in self])
+ return '<br />\n'.join([six.text_type(choice) for choice in self])
w = RadioSelect(renderer=MyRenderer)
self.assertHTMLEqual(w.render('beatle', 'G', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))), """<label><input type="radio" name="beatle" value="J" /> John</label><br />
<label><input type="radio" name="beatle" value="P" /> Paul</label><br />
@@ -716,7 +717,7 @@ beatle J R Ringo False""")
# Unicode choices are correctly rendered as HTML
w = RadioSelect()
- self.assertHTMLEqual(unicode(w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')])), '<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="radio" name="email" value="\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>')
+ self.assertHTMLEqual(six.text_type(w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')])), '<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="radio" name="email" value="\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>')
# Attributes provided at instantiation are passed to the constituent inputs
w = RadioSelect(attrs={'id':'foo'})
@@ -1135,7 +1136,7 @@ class ClearableFileInputTests(TestCase):
output = widget.render('my<div>file', field)
self.assertFalse(field.url in output)
self.assertTrue('href="something?chapter=1&amp;sect=2&amp;copy=3&amp;lang=en"' in output)
- self.assertFalse(unicode(field) in output)
+ self.assertFalse(six.text_type(field) in output)
self.assertTrue('something&lt;div onclick=&quot;alert(&#39;oops&#39;)&quot;&gt;.jpg' in output)
self.assertTrue('my&lt;div&gt;file' in output)
self.assertFalse('my<div>file' in output)
diff --git a/tests/regressiontests/i18n/contenttypes/tests.py b/tests/regressiontests/i18n/contenttypes/tests.py
index bed94da8b8..178232f543 100644
--- a/tests/regressiontests/i18n/contenttypes/tests.py
+++ b/tests/regressiontests/i18n/contenttypes/tests.py
@@ -6,6 +6,7 @@ import os
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.test.utils import override_settings
+from django.utils import six
from django.utils import translation
@@ -24,11 +25,11 @@ class ContentTypeTests(TestCase):
def test_verbose_name(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
with translation.override('en'):
- self.assertEqual(unicode(company_type), 'Company')
+ self.assertEqual(six.text_type(company_type), 'Company')
with translation.override('fr'):
- self.assertEqual(unicode(company_type), 'Société')
+ self.assertEqual(six.text_type(company_type), 'Société')
def test_field_override(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
company_type.name = 'Other'
- self.assertEqual(unicode(company_type), 'Other')
+ self.assertEqual(six.text_type(company_type), 'Other')
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 69260edb0a..9ca66bdb9b 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -19,6 +19,7 @@ from django.utils.formats import (get_format, date_format, time_format,
from django.utils.importlib import import_module
from django.utils.numberformat import format as nformat
from django.utils.safestring import mark_safe, SafeString, SafeUnicode
+from django.utils import six
from django.utils.six import PY3
from django.utils.translation import (ugettext, ugettext_lazy, activate,
deactivate, gettext_lazy, pgettext, npgettext, to_locale,
@@ -81,9 +82,9 @@ class TranslationTests(TestCase):
def test_lazy_pickle(self):
s1 = ugettext_lazy("test")
- self.assertEqual(unicode(s1), "test")
+ self.assertEqual(six.text_type(s1), "test")
s2 = pickle.loads(pickle.dumps(s1))
- self.assertEqual(unicode(s2), "test")
+ self.assertEqual(six.text_type(s2), "test")
def test_pgettext(self):
# Reset translation catalog to include other/locale/de
@@ -222,10 +223,10 @@ class TranslationTests(TestCase):
def test_string_concat(self):
"""
- unicode(string_concat(...)) should not raise a TypeError - #4796
+ six.text_type(string_concat(...)) should not raise a TypeError - #4796
"""
import django.utils.translation
- self.assertEqual('django', unicode(django.utils.translation.string_concat("dja", "ngo")))
+ self.assertEqual('django', six.text_type(django.utils.translation.string_concat("dja", "ngo")))
def test_safe_status(self):
"""
diff --git a/tests/regressiontests/inline_formsets/tests.py b/tests/regressiontests/inline_formsets/tests.py
index 8ad84f221f..6e63f34ed0 100644
--- a/tests/regressiontests/inline_formsets/tests.py
+++ b/tests/regressiontests/inline_formsets/tests.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
from django.forms.models import inlineformset_factory
from django.test import TestCase
+from django.utils import six
from .models import Poet, Poem, School, Parent, Child
@@ -66,8 +67,8 @@ class DeletionTests(TestCase):
'poem_set-TOTAL_FORMS': '1',
'poem_set-INITIAL_FORMS': '1',
'poem_set-MAX_NUM_FORMS': '0',
- 'poem_set-0-id': unicode(poem.id),
- 'poem_set-0-poem': unicode(poem.id),
+ 'poem_set-0-id': six.text_type(poem.id),
+ 'poem_set-0-poem': six.text_type(poem.id),
'poem_set-0-name': 'x' * 1000,
}
formset = PoemFormSet(data, instance=poet)
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index a0f9bba170..3cb129f84e 100644
--- a/tests/regressiontests/model_forms_regress/tests.py
+++ b/tests/regressiontests/model_forms_regress/tests.py
@@ -7,6 +7,7 @@ from django.core.exceptions import FieldError, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms.models import (modelform_factory, ModelChoiceField,
fields_for_model, construct_instance, ModelFormMetaclass)
+from django.utils import six
from django.utils import unittest
from django.test import TestCase
@@ -392,14 +393,14 @@ class FileFieldTests(unittest.TestCase):
"""
form = DocumentForm()
- self.assertTrue('name="myfile"' in unicode(form))
- self.assertTrue('myfile-clear' not in unicode(form))
+ self.assertTrue('name="myfile"' in six.text_type(form))
+ self.assertTrue('myfile-clear' not in six.text_type(form))
form = DocumentForm(files={'myfile': SimpleUploadedFile('something.txt', b'content')})
self.assertTrue(form.is_valid())
doc = form.save(commit=False)
self.assertEqual(doc.myfile.name, 'something.txt')
form = DocumentForm(instance=doc)
- self.assertTrue('myfile-clear' in unicode(form))
+ self.assertTrue('myfile-clear' in six.text_type(form))
form = DocumentForm(instance=doc, data={'myfile-clear': 'true'})
doc = form.save(commit=False)
self.assertEqual(bool(doc.myfile), False)
@@ -420,7 +421,7 @@ class FileFieldTests(unittest.TestCase):
self.assertTrue(not form.is_valid())
self.assertEqual(form.errors['myfile'],
['Please either submit a file or check the clear checkbox, not both.'])
- rendered = unicode(form)
+ rendered = six.text_type(form)
self.assertTrue('something.txt' in rendered)
self.assertTrue('myfile-clear' in rendered)
diff --git a/tests/regressiontests/model_formsets_regress/tests.py b/tests/regressiontests/model_formsets_regress/tests.py
index 68ebe48bde..1fbdb9744f 100644
--- a/tests/regressiontests/model_formsets_regress/tests.py
+++ b/tests/regressiontests/model_formsets_regress/tests.py
@@ -5,6 +5,7 @@ from django.forms.formsets import BaseFormSet, DELETION_FIELD_NAME
from django.forms.util import ErrorDict, ErrorList
from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory, BaseModelFormSet
from django.test import TestCase
+from django.utils import six
from .models import User, UserSite, Restaurant, Manager, Network, Host
@@ -51,7 +52,7 @@ class InlineFormsetTests(TestCase):
'usersite_set-TOTAL_FORMS': '1',
'usersite_set-INITIAL_FORMS': '1',
'usersite_set-MAX_NUM_FORMS': '0',
- 'usersite_set-0-id': unicode(usersite[0]['id']),
+ 'usersite_set-0-id': six.text_type(usersite[0]['id']),
'usersite_set-0-data': '11',
'usersite_set-0-user': 'apollo13'
}
@@ -69,7 +70,7 @@ class InlineFormsetTests(TestCase):
'usersite_set-TOTAL_FORMS': '2',
'usersite_set-INITIAL_FORMS': '1',
'usersite_set-MAX_NUM_FORMS': '0',
- 'usersite_set-0-id': unicode(usersite[0]['id']),
+ 'usersite_set-0-id': six.text_type(usersite[0]['id']),
'usersite_set-0-data': '11',
'usersite_set-0-user': 'apollo13',
'usersite_set-1-data': '42',
@@ -124,7 +125,7 @@ class InlineFormsetTests(TestCase):
'manager_set-TOTAL_FORMS': '1',
'manager_set-INITIAL_FORMS': '1',
'manager_set-MAX_NUM_FORMS': '0',
- 'manager_set-0-id': unicode(manager[0]['id']),
+ 'manager_set-0-id': six.text_type(manager[0]['id']),
'manager_set-0-name': 'Terry Gilliam'
}
form_set = FormSet(data, instance=restaurant)
@@ -140,7 +141,7 @@ class InlineFormsetTests(TestCase):
'manager_set-TOTAL_FORMS': '2',
'manager_set-INITIAL_FORMS': '1',
'manager_set-MAX_NUM_FORMS': '0',
- 'manager_set-0-id': unicode(manager[0]['id']),
+ 'manager_set-0-id': six.text_type(manager[0]['id']),
'manager_set-0-name': 'Terry Gilliam',
'manager_set-1-name': 'John Cleese'
}
@@ -188,7 +189,7 @@ class InlineFormsetTests(TestCase):
'host_set-TOTAL_FORMS': '2',
'host_set-INITIAL_FORMS': '1',
'host_set-MAX_NUM_FORMS': '0',
- 'host_set-0-id': unicode(host1.id),
+ 'host_set-0-id': six.text_type(host1.id),
'host_set-0-hostname': 'tranquility.hub.dal.net',
'host_set-1-hostname': 'matrix.de.eu.dal.net'
}
diff --git a/tests/regressiontests/model_regress/tests.py b/tests/regressiontests/model_regress/tests.py
index 7f9f514c7a..6a45a83052 100644
--- a/tests/regressiontests/model_regress/tests.py
+++ b/tests/regressiontests/model_regress/tests.py
@@ -5,6 +5,7 @@ from operator import attrgetter
from django.core.exceptions import ValidationError
from django.test import TestCase, skipUnlessDBFeature
+from django.utils import six
from django.utils import tzinfo
from .models import (Worker, Article, Party, Event, Department,
@@ -38,7 +39,7 @@ class ModelTests(TestCase):
# Empty strings should be returned as Unicode
a = Article.objects.get(pk=a.pk)
self.assertEqual(a.misc_data, '')
- self.assertIs(type(a.misc_data), unicode)
+ self.assertIs(type(a.misc_data), six.text_type)
def test_long_textfield(self):
# TextFields can hold more than 4000 characters (this was broken in
@@ -138,7 +139,7 @@ class ModelTests(TestCase):
# Check Department and Worker (non-default PK type)
d = Department.objects.create(id=10, name="IT")
w = Worker.objects.create(department=d, name="Full-time")
- self.assertEqual(unicode(w), "Full-time")
+ self.assertEqual(six.text_type(w), "Full-time")
def test_broken_unicode(self):
# Models with broken unicode methods should still have a printable repr
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 8c34b50e93..6328776e91 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -6,6 +6,7 @@ from __future__ import unicode_literals
import threading
from django.db import models
+from django.utils import six
class DumbCategory(models.Model):
@@ -122,7 +123,7 @@ class Number(models.Model):
num = models.IntegerField()
def __unicode__(self):
- return unicode(self.num)
+ return six.text_type(self.num)
# Symmetrical m2m field with a normal field using the reverse accesor name
# ("valid").
diff --git a/tests/regressiontests/select_related_regress/tests.py b/tests/regressiontests/select_related_regress/tests.py
index 73b0a8a875..7f93a1c33c 100644
--- a/tests/regressiontests/select_related_regress/tests.py
+++ b/tests/regressiontests/select_related_regress/tests.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals
from django.test import TestCase
+from django.utils import six
from .models import (Building, Child, Device, Port, Item, Country, Connection,
ClientStatus, State, Client, SpecialClient, TUser, Person, Student,
@@ -33,11 +34,11 @@ class SelectRelatedRegressTests(TestCase):
c2=Connection.objects.create(start=port2, end=port3)
connections=Connection.objects.filter(start__device__building=b, end__device__building=b).order_by('id')
- self.assertEqual([(c.id, unicode(c.start), unicode(c.end)) for c in connections],
+ self.assertEqual([(c.id, six.text_type(c.start), six.text_type(c.end)) for c in connections],
[(c1.id, 'router/4', 'switch/7'), (c2.id, 'switch/7', 'server/1')])
connections=Connection.objects.filter(start__device__building=b, end__device__building=b).select_related().order_by('id')
- self.assertEqual([(c.id, unicode(c.start), unicode(c.end)) for c in connections],
+ self.assertEqual([(c.id, six.text_type(c.start), six.text_type(c.end)) for c in connections],
[(c1.id, 'router/4', 'switch/7'), (c2.id, 'switch/7', 'server/1')])
# This final query should only have seven tables (port, device and building
diff --git a/tests/regressiontests/templates/templatetags/custom.py b/tests/regressiontests/templates/templatetags/custom.py
index 7f788311c6..95fcd551de 100644
--- a/tests/regressiontests/templates/templatetags/custom.py
+++ b/tests/regressiontests/templates/templatetags/custom.py
@@ -3,6 +3,7 @@ import operator
from django import template
from django.template.defaultfilters import stringfilter
from django.template.loader import get_template
+from django.utils import six
register = template.Library()
@@ -56,13 +57,13 @@ simple_one_default.anything = "Expected simple_one_default __dict__"
@register.simple_tag
def simple_unlimited_args(one, two='hi', *args):
"""Expected simple_unlimited_args __doc__"""
- return "simple_unlimited_args - Expected result: %s" % (', '.join([unicode(arg) for arg in [one, two] + list(args)]))
+ return "simple_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))
simple_unlimited_args.anything = "Expected simple_unlimited_args __dict__"
@register.simple_tag
def simple_only_unlimited_args(*args):
"""Expected simple_only_unlimited_args __doc__"""
- return "simple_only_unlimited_args - Expected result: %s" % ', '.join([unicode(arg) for arg in args])
+ return "simple_only_unlimited_args - Expected result: %s" % ', '.join([six.text_type(arg) for arg in args])
simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dict__"
@register.simple_tag
@@ -71,7 +72,7 @@ def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
- ', '.join([unicode(arg) for arg in [one, two] + list(args)]),
+ ', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
)
simple_unlimited_args_kwargs.anything = "Expected simple_unlimited_args_kwargs __dict__"
@@ -183,25 +184,25 @@ inclusion_one_default_from_template.anything = "Expected inclusion_one_default_f
@register.inclusion_tag('inclusion.html')
def inclusion_unlimited_args(one, two='hi', *args):
"""Expected inclusion_unlimited_args __doc__"""
- return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join([unicode(arg) for arg in [one, two] + list(args)]))}
+ return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))}
inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__"
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_unlimited_args_from_template(one, two='hi', *args):
"""Expected inclusion_unlimited_args_from_template __doc__"""
- return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join([unicode(arg) for arg in [one, two] + list(args)]))}
+ return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))}
inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_only_unlimited_args(*args):
"""Expected inclusion_only_unlimited_args __doc__"""
- return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join([unicode(arg) for arg in args]))}
+ return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in args]))}
inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__"
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_only_unlimited_args_from_template(*args):
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
- return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join([unicode(arg) for arg in args]))}
+ return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join([six.text_type(arg) for arg in args]))}
inclusion_only_unlimited_args_from_template.anything = "Expected inclusion_only_unlimited_args_from_template __dict__"
@register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True)
@@ -222,7 +223,7 @@ def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
- ', '.join([unicode(arg) for arg in [one, two] + list(args)]),
+ ', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
)}
inclusion_unlimited_args_kwargs.anything = "Expected inclusion_unlimited_args_kwargs __dict__"
@@ -278,13 +279,13 @@ assignment_one_default.anything = "Expected assignment_one_default __dict__"
@register.assignment_tag
def assignment_unlimited_args(one, two='hi', *args):
"""Expected assignment_unlimited_args __doc__"""
- return "assignment_unlimited_args - Expected result: %s" % (', '.join([unicode(arg) for arg in [one, two] + list(args)]))
+ return "assignment_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))
assignment_unlimited_args.anything = "Expected assignment_unlimited_args __dict__"
@register.assignment_tag
def assignment_only_unlimited_args(*args):
"""Expected assignment_only_unlimited_args __doc__"""
- return "assignment_only_unlimited_args - Expected result: %s" % ', '.join([unicode(arg) for arg in args])
+ return "assignment_only_unlimited_args - Expected result: %s" % ', '.join([six.text_type(arg) for arg in args])
assignment_only_unlimited_args.anything = "Expected assignment_only_unlimited_args __dict__"
@register.assignment_tag
@@ -293,7 +294,7 @@ def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
return "assignment_unlimited_args_kwargs - Expected result: %s / %s" % (
- ', '.join([unicode(arg) for arg in [one, two] + list(args)]),
+ ', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
)
assignment_unlimited_args_kwargs.anything = "Expected assignment_unlimited_args_kwargs __dict__"
diff --git a/tests/regressiontests/templates/unicode.py b/tests/regressiontests/templates/unicode.py
index 2c41176b01..7cb2a28d15 100644
--- a/tests/regressiontests/templates/unicode.py
+++ b/tests/regressiontests/templates/unicode.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.template import Template, TemplateEncodingError, Context
from django.utils.safestring import SafeData
+from django.utils import six
from django.utils.unittest import TestCase
@@ -27,5 +28,5 @@ class UnicodeTests(TestCase):
# they all render the same (and are returned as unicode objects and
# "safe" objects as well, for auto-escaping purposes).
self.assertEqual(t1.render(c3), t2.render(c3))
- self.assertIsInstance(t1.render(c3), unicode)
+ self.assertIsInstance(t1.render(c3), six.text_type)
self.assertIsInstance(t1.render(c3), SafeData)
diff --git a/tests/regressiontests/utils/simplelazyobject.py b/tests/regressiontests/utils/simplelazyobject.py
index 982d2226e6..960a5e3201 100644
--- a/tests/regressiontests/utils/simplelazyobject.py
+++ b/tests/regressiontests/utils/simplelazyobject.py
@@ -4,6 +4,7 @@ import copy
import pickle
from django.test.utils import str_prefix
+from django.utils import six
from django.utils.unittest import TestCase
from django.utils.functional import SimpleLazyObject, empty
@@ -22,7 +23,7 @@ class _ComplexObject(object):
return "I am _ComplexObject(%r)" % self.name
def __unicode__(self):
- return unicode(self.name)
+ return six.text_type(self.name)
def __repr__(self):
return "_ComplexObject(%r)" % self.name
@@ -58,7 +59,7 @@ class TestUtilsSimpleLazyObject(TestCase):
str(SimpleLazyObject(complex_object)))
def test_unicode(self):
- self.assertEqual("joe", unicode(SimpleLazyObject(complex_object)))
+ self.assertEqual("joe", six.text_type(SimpleLazyObject(complex_object)))
def test_class(self):
# This is important for classes that use __class__ in things like
@@ -108,5 +109,5 @@ class TestUtilsSimpleLazyObject(TestCase):
pickled = pickle.dumps(x)
unpickled = pickle.loads(pickled)
self.assertEqual(unpickled, x)
- self.assertEqual(unicode(unpickled), unicode(x))
+ self.assertEqual(six.text_type(unpickled), six.text_type(x))
self.assertEqual(unpickled.name, x.name)
diff --git a/tests/regressiontests/wsgi/tests.py b/tests/regressiontests/wsgi/tests.py
index 9614a81c67..a482a5c1eb 100644
--- a/tests/regressiontests/wsgi/tests.py
+++ b/tests/regressiontests/wsgi/tests.py
@@ -6,6 +6,7 @@ from django.core.wsgi import get_wsgi_application
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
+from django.utils import six
from django.utils import unittest
@@ -39,7 +40,7 @@ class WSGITest(TestCase):
response_data["headers"],
[('Content-Type', 'text/html; charset=utf-8')])
self.assertEqual(
- unicode(response),
+ six.text_type(response),
"Content-Type: text/html; charset=utf-8\n\nHello World!")