0
0
mirror of https://github.com/django/django.git synced 2024-11-29 14:46:18 +01:00
django/tests/str/tests.py
Aymeric Augustin 589dc49e12 Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible.
Thanks jpic for the report and chmodas for working on a patch.

Reverts 2ea80b94. Refs #19362.
2013-10-13 18:14:04 +02:00

36 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
from unittest import skipIf
from django.test import TestCase
from django.utils import six
from .models import Article, 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'Area man programs in Python',
pub_date=datetime.datetime(2005, 7, 28)
)
self.assertEqual(str(a), str('Area man programs in Python'))
self.assertEqual(repr(a), str('<Article: Area man programs in Python>'))
def test_international(self):
a = InternationalArticle.objects.create(
headline='Girl wins €12.500 in lottery',
pub_date=datetime.datetime(2005, 7, 28)
)
if six.PY3:
self.assertEqual(str(a), 'Girl wins €12.500 in lottery')
else:
# On Python 2, the default str() output will be the UTF-8 encoded
# output of __unicode__() -- or __str__() when the
# python_2_unicode_compatible decorator is used.
self.assertEqual(str(a), b'Girl wins \xe2\x82\xac12.500 in lottery')