summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-12 12:32:08 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-12 14:44:40 +0200
commitd4a0b27838c815af87698920cc4db7d2afd6f05b (patch)
tree6fedc7203389ab1f80f8cc7e913230c51e9b8776 /tests/regressiontests/forms
parent79d62a71751140315227891bbe175630f9d3edc3 (diff)
[py3] Refactored __unicode__ to __str__.
* Renamed the __unicode__ methods * Applied the python_2_unicode_compatible decorator * Removed the StrAndUnicode mix-in that is superseded by python_2_unicode_compatible * Kept the __unicode__ methods in classes that specifically test it under Python 2
Diffstat (limited to 'tests/regressiontests/forms')
-rw-r--r--tests/regressiontests/forms/models.py7
-rw-r--r--tests/regressiontests/forms/tests/error_messages.py4
-rw-r--r--tests/regressiontests/forms/tests/extra.py28
-rw-r--r--tests/regressiontests/forms/tests/util.py4
-rw-r--r--tests/regressiontests/forms/tests/widgets.py7
5 files changed, 36 insertions, 14 deletions
diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py
index 18e6ddce6d..2f3ee9fa31 100644
--- a/tests/regressiontests/forms/models.py
+++ b/tests/regressiontests/forms/models.py
@@ -7,6 +7,7 @@ import tempfile
from django.core.files.storage import FileSystemStorage
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
temp_storage_location = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
@@ -36,6 +37,7 @@ class ChoiceModel(models.Model):
name = models.CharField(max_length=10)
+@python_2_unicode_compatible
class ChoiceOptionModel(models.Model):
"""Destination for ChoiceFieldModel's ForeignKey.
Can't reuse ChoiceModel because error_message tests require that it have no instances."""
@@ -44,7 +46,7 @@ class ChoiceOptionModel(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return 'ChoiceOption %d' % self.pk
@@ -66,10 +68,11 @@ class FileModel(models.Model):
file = models.FileField(storage=temp_storage, upload_to='tests')
+@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return '%s' % self.name
diff --git a/tests/regressiontests/forms/tests/error_messages.py b/tests/regressiontests/forms/tests/error_messages.py
index f69b419483..b76e122bc0 100644
--- a/tests/regressiontests/forms/tests/error_messages.py
+++ b/tests/regressiontests/forms/tests/error_messages.py
@@ -5,6 +5,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import *
from django.test import TestCase
from django.utils.safestring import mark_safe
+from django.utils.encoding import python_2_unicode_compatible
class AssertFormErrorsMixin(object):
@@ -213,8 +214,9 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
def clean(self):
raise ValidationError("I like to be awkward.")
+ @python_2_unicode_compatible
class CustomErrorList(util.ErrorList):
- def __unicode__(self):
+ def __str__(self):
return self.as_divs()
def as_divs(self):
diff --git a/tests/regressiontests/forms/tests/extra.py b/tests/regressiontests/forms/tests/extra.py
index e0e62858d0..2ab5d40942 100644
--- a/tests/regressiontests/forms/tests/extra.py
+++ b/tests/regressiontests/forms/tests/extra.py
@@ -8,8 +8,9 @@ from django.forms import *
from django.forms.extras import SelectDateWidget
from django.forms.util import ErrorList
from django.test import TestCase
+from django.utils import six
from django.utils import translation
-from django.utils.encoding import force_text, smart_text
+from django.utils.encoding import force_text, smart_text, python_2_unicode_compatible
from .error_messages import AssertFormErrorsMixin
@@ -553,14 +554,24 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
def test_smart_text(self):
class Test:
- def __str__(self):
- return 'ŠĐĆŽćžšđ'.encode('utf-8')
+ if six.PY3:
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'
+ else:
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'.encode('utf-8')
class TestU:
- def __str__(self):
- return 'Foo'
- def __unicode__(self):
- return '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+ if six.PY3:
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'
+ def __bytes__(self):
+ return b'Foo'
+ else:
+ def __str__(self):
+ return b'Foo'
+ def __unicode__(self):
+ return '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
self.assertEqual(smart_text(Test()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
self.assertEqual(smart_text(TestU()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
@@ -585,8 +596,9 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
self.assertEqual(f.cleaned_data['username'], 'sirrobin')
def test_overriding_errorlist(self):
+ @python_2_unicode_compatible
class DivErrorList(ErrorList):
- def __unicode__(self):
+ def __str__(self):
return self.as_divs()
def as_divs(self):
diff --git a/tests/regressiontests/forms/tests/util.py b/tests/regressiontests/forms/tests/util.py
index b7cc4ec809..c2d213ae23 100644
--- a/tests/regressiontests/forms/tests/util.py
+++ b/tests/regressiontests/forms/tests/util.py
@@ -7,6 +7,7 @@ from django.test import TestCase
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.translation import ugettext_lazy
+from django.utils.encoding import python_2_unicode_compatible
class FormsUtilTestCase(TestCase):
@@ -46,8 +47,9 @@ class FormsUtilTestCase(TestCase):
self.assertHTMLEqual(str(ErrorList(ValidationError(["First error.", "Not \u03C0.", ugettext_lazy("Error.")]).messages)),
'<ul class="errorlist"><li>First error.</li><li>Not π.</li><li>Error.</li></ul>')
+ @python_2_unicode_compatible
class VeryBadError:
- def __unicode__(self): return "A very bad error."
+ def __str__(self): return "A very bad error."
# Can take a non-string.
self.assertHTMLEqual(str(ErrorList(ValidationError(VeryBadError()).messages)),
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index 3ea42cf549..c950aef719 100644
--- a/tests/regressiontests/forms/tests/widgets.py
+++ b/tests/regressiontests/forms/tests/widgets.py
@@ -13,6 +13,7 @@ from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.translation import activate, deactivate
from django.test import TestCase
+from django.utils.encoding import python_2_unicode_compatible
class FormsWidgetTestCase(TestCase):
@@ -1096,6 +1097,7 @@ class WidgetTests(TestCase):
self.assertFalse(form.is_valid())
+@python_2_unicode_compatible
class FakeFieldFile(object):
"""
Quacks like a FieldFile (has a .url and unicode representation), but
@@ -1104,7 +1106,7 @@ class FakeFieldFile(object):
"""
url = 'something'
- def __unicode__(self):
+ def __str__(self):
return self.url
class ClearableFileInputTests(TestCase):
@@ -1125,10 +1127,11 @@ class ClearableFileInputTests(TestCase):
rendering HTML. Refs #15182.
"""
+ @python_2_unicode_compatible
class StrangeFieldFile(object):
url = "something?chapter=1&sect=2&copy=3&lang=en"
- def __unicode__(self):
+ def __str__(self):
return '''something<div onclick="alert('oops')">.jpg'''
widget = ClearableFileInput()