2010-09-13 05:28:38 +00:00
|
|
|
import datetime
|
|
|
|
|
2015-11-11 06:30:19 +00:00
|
|
|
from django.db import models
|
2010-09-13 05:28:38 +00:00
|
|
|
from django.test import TestCase
|
2015-11-17 05:39:28 +00:00
|
|
|
from django.test.utils import isolate_apps
|
2010-09-13 05:28:38 +00:00
|
|
|
|
2016-12-01 10:38:01 +00:00
|
|
|
from .models import 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
|
|
|
|
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)
|
|
|
|
)
|
2016-11-19 20:54:19 +00:00
|
|
|
self.assertEqual(str(a), 'Girl wins €12.500 in lottery')
|
2015-11-11 06:30:19 +00:00
|
|
|
|
2015-11-17 05:39:28 +00:00
|
|
|
@isolate_apps('str')
|
2015-11-11 06:30:19 +00:00
|
|
|
def test_defaults(self):
|
|
|
|
"""
|
|
|
|
The default implementation of __str__ and __repr__ should return
|
|
|
|
instances of str.
|
|
|
|
"""
|
|
|
|
class Default(models.Model):
|
2015-11-17 05:39:28 +00:00
|
|
|
pass
|
2015-11-11 06:30:19 +00: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)
|
|
|
|
self.assertEqual(str(obj), str('Default object'))
|
|
|
|
self.assertEqual(repr(obj), str('<Default: Default object>'))
|