summaryrefslogtreecommitdiff
path: root/tests/str
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-12-01 11:38:01 +0100
committerClaude Paroz <claude@2xlibre.net>2017-01-18 16:21:28 +0100
commitc716fe87821df00f9f03ecc761c914d1682591a2 (patch)
tree0436706cdb190acbc76fb5fcf6d66f16e09fafa3 /tests/str
parente63d98b7beb16d1410168a2315cbe04c43c9c80d (diff)
downloaddjango-c716fe87821df00f9f03ecc761c914d1682591a2.tar.gz
Refs #23919 -- Removed six.PY2/PY3 usage
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/str')
-rw-r--r--tests/str/models.py27
-rw-r--r--tests/str/tests.py13
2 files changed, 7 insertions, 33 deletions
diff --git a/tests/str/models.py b/tests/str/models.py
index 12f0247570..d2f7a45c20 100644
--- a/tests/str/models.py
+++ b/tests/str/models.py
@@ -1,31 +1,16 @@
"""
-Adding __str__() or __unicode__() to models
+Adding __str__() to models
-Although it's not a strict requirement, each model should have a
-``_str__()`` or ``__unicode__()`` method to return a "human-readable"
-representation of the object. Do this not only for your own sanity when dealing
-with the interactive prompt, but also because objects' representations are used
-throughout Django's automatically-generated admin.
-
-Normally, you should write ``__unicode__()`` method, since this will work for
-all field types (and Django will automatically provide an appropriate
-``__str__()`` method). However, you can write a ``__str__()`` method directly,
-if you prefer. You must be careful to encode the results correctly, though.
+Although it's not a strict requirement, each model should have a ``_str__()``
+method to return a "human-readable" representation of the object. Do this not
+only for your own sanity when dealing with the interactive prompt, but also
+because objects' representations are used throughout Django's
+automatically-generated admin.
"""
from django.db import models
-class Article(models.Model):
- headline = models.CharField(max_length=100)
- pub_date = models.DateTimeField()
-
- def __str__(self):
- # Caution: this is only safe if you are certain that headline will be
- # in ASCII.
- return self.headline
-
-
class InternationalArticle(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
diff --git a/tests/str/tests.py b/tests/str/tests.py
index c4dd1d6b26..2d82c03ebf 100644
--- a/tests/str/tests.py
+++ b/tests/str/tests.py
@@ -1,25 +1,14 @@
import datetime
-from unittest import skipIf
from django.db import models
from django.test import TestCase
from django.test.utils import isolate_apps
-from django.utils import six
-from .models import Article, InternationalArticle
+from .models import InternationalArticle
class SimpleTests(TestCase):
- @skipIf(six.PY3, "tests a __str__ method returning unicode under Python 2")
- def test_basic(self):
- a = Article.objects.create(
- headline=b'Parrot programs in Python',
- pub_date=datetime.datetime(2005, 7, 28)
- )
- self.assertEqual(str(a), str('Parrot programs in Python'))
- self.assertEqual(repr(a), str('<Article: Parrot programs in Python>'))
-
def test_international(self):
a = InternationalArticle.objects.create(
headline='Girl wins €12.500 in lottery',