2010-09-13 13:28:38 +08:00
|
|
|
import datetime
|
|
|
|
|
2015-11-11 14:30:19 +08:00
|
|
|
from django.db import models
|
2010-09-13 13:28:38 +08:00
|
|
|
from django.test import TestCase
|
2015-11-17 13:39:28 +08:00
|
|
|
from django.test.utils import isolate_apps
|
2010-09-13 13:28:38 +08:00
|
|
|
|
2016-12-01 18:38:01 +08:00
|
|
|
from .models import InternationalArticle
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2010-09-13 13:28:38 +08:00
|
|
|
|
|
|
|
class SimpleTests(TestCase):
|
2012-08-16 15:44:00 +08:00
|
|
|
|
2010-09-13 13:28:38 +08:00
|
|
|
def test_international(self):
|
|
|
|
a = InternationalArticle.objects.create(
|
2012-06-08 00:08:47 +08:00
|
|
|
headline='Girl wins €12.500 in lottery',
|
2010-09-13 13:28:38 +08:00
|
|
|
pub_date=datetime.datetime(2005, 7, 28)
|
|
|
|
)
|
2016-11-20 04:54:19 +08:00
|
|
|
self.assertEqual(str(a), 'Girl wins €12.500 in lottery')
|
2015-11-11 14:30:19 +08:00
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps('str')
|
2015-11-11 14:30:19 +08:00
|
|
|
def test_defaults(self):
|
|
|
|
"""
|
|
|
|
The default implementation of __str__ and __repr__ should return
|
|
|
|
instances of str.
|
|
|
|
"""
|
|
|
|
class Default(models.Model):
|
2015-11-17 13:39:28 +08:00
|
|
|
pass
|
2015-11-11 14:30:19 +08:00
|
|
|
|
|
|
|
obj = Default()
|
|
|
|
# Explicit call to __str__/__repr__ to make sure str()/repr() don't
|
|
|
|
# coerce the returned value.
|
|
|
|
self.assertIsInstance(obj.__str__(), str)
|
|
|
|
self.assertIsInstance(obj.__repr__(), str)
|
2017-04-09 02:38:48 +08:00
|
|
|
self.assertEqual(str(obj), 'Default object (None)')
|
|
|
|
self.assertEqual(repr(obj), '<Default: Default object (None)>')
|
|
|
|
obj2 = Default(pk=100)
|
|
|
|
self.assertEqual(str(obj2), 'Default object (100)')
|
|
|
|
self.assertEqual(repr(obj2), '<Default: Default object (100)>')
|