2014-03-30 19:11:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-07-29 17:19:04 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-09-13 05:28:38 +00:00
|
|
|
import datetime
|
2013-07-01 12:22:27 +00:00
|
|
|
from unittest import skipIf
|
2010-09-13 05:28:38 +00:00
|
|
|
|
|
|
|
from django.test import TestCase
|
2012-08-16 07:44:00 +00:00
|
|
|
from django.utils import six
|
2010-09-13 05:28:38 +00:00
|
|
|
|
2013-10-13 16:06:58 +00:00
|
|
|
from .models import Article, InternationalArticle
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-09-13 05:28:38 +00:00
|
|
|
|
|
|
|
class SimpleTests(TestCase):
|
2012-08-16 07:44:00 +00:00
|
|
|
|
|
|
|
@skipIf(six.PY3, "tests a __str__ method returning unicode under Python 2")
|
2010-09-13 05:28:38 +00:00
|
|
|
def test_basic(self):
|
|
|
|
a = Article.objects.create(
|
2015-08-22 18:05:54 +00:00
|
|
|
headline=b'Parrot programs in Python',
|
2010-09-13 05:28:38 +00:00
|
|
|
pub_date=datetime.datetime(2005, 7, 28)
|
|
|
|
)
|
2015-08-22 18:05:54 +00:00
|
|
|
self.assertEqual(str(a), str('Parrot programs in Python'))
|
|
|
|
self.assertEqual(repr(a), str('<Article: Parrot programs in Python>'))
|
2010-09-13 05:28:38 +00:00
|
|
|
|
|
|
|
def test_international(self):
|
|
|
|
a = InternationalArticle.objects.create(
|
2012-06-07 16:08:47 +00:00
|
|
|
headline='Girl wins €12.500 in lottery',
|
2010-09-13 05:28:38 +00:00
|
|
|
pub_date=datetime.datetime(2005, 7, 28)
|
|
|
|
)
|
2012-08-16 07:44:00 +00:00
|
|
|
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')
|