1. import datetime
    
  2. 
    
  3. from django.db import models
    
  4. from django.test import TestCase
    
  5. from django.test.utils import isolate_apps
    
  6. 
    
  7. from .models import InternationalArticle
    
  8. 
    
  9. 
    
  10. class SimpleTests(TestCase):
    
  11.     def test_international(self):
    
  12.         a = InternationalArticle.objects.create(
    
  13.             headline="Girl wins €12.500 in lottery",
    
  14.             pub_date=datetime.datetime(2005, 7, 28),
    
  15.         )
    
  16.         self.assertEqual(str(a), "Girl wins €12.500 in lottery")
    
  17. 
    
  18.     @isolate_apps("str")
    
  19.     def test_defaults(self):
    
  20.         """
    
  21.         The default implementation of __str__ and __repr__ should return
    
  22.         instances of str.
    
  23.         """
    
  24. 
    
  25.         class Default(models.Model):
    
  26.             pass
    
  27. 
    
  28.         obj = Default()
    
  29.         # Explicit call to __str__/__repr__ to make sure str()/repr() don't
    
  30.         # coerce the returned value.
    
  31.         self.assertIsInstance(obj.__str__(), str)
    
  32.         self.assertIsInstance(obj.__repr__(), str)
    
  33.         self.assertEqual(str(obj), "Default object (None)")
    
  34.         self.assertEqual(repr(obj), "<Default: Default object (None)>")
    
  35.         obj2 = Default(pk=100)
    
  36.         self.assertEqual(str(obj2), "Default object (100)")
    
  37.         self.assertEqual(repr(obj2), "<Default: Default object (100)>")