Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Migrated i18n and field_defaults doctests. Thanks to Alex Gay…

…nor.

Backport of r13779 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13796 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f7f2c7251a91499e901a241e0bfd120485d025a2 1 parent 24f4a4b
Russell Keith-Magee authored
38  tests/modeltests/field_defaults/models.py
@@ -19,41 +19,3 @@ class Article(models.Model):
19 19
 
20 20
     def __unicode__(self):
21 21
         return self.headline
22  
-
23  
-__test__ = {'API_TESTS': u"""
24  
->>> from datetime import datetime
25  
-
26  
-# No articles are in the system yet.
27  
->>> Article.objects.all()
28  
-[]
29  
-
30  
-# Create an Article.
31  
->>> a = Article(id=None)
32  
-
33  
-# Grab the current datetime it should be very close to the default that just
34  
-# got saved as a.pub_date
35  
->>> now = datetime.now()
36  
-
37  
-# Save it into the database. You have to call save() explicitly.
38  
->>> a.save()
39  
-
40  
-# Now it has an ID. Note it's a long integer, as designated by the trailing "L".
41  
->>> a.id
42  
-1L
43  
-
44  
-# Access database columns via Python attributes.
45  
->>> a.headline
46  
-u'Default headline'
47  
-
48  
-# make sure the two dates are sufficiently close
49  
->>> d = now - a.pub_date
50  
->>> d.seconds < 5
51  
-True
52  
-
53  
-# make sure that SafeString/SafeUnicode fields work
54  
->>> from django.utils.safestring import SafeUnicode, SafeString
55  
->>> a.headline = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
56  
->>> a.save()
57  
->>> a.headline = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
58  
->>> a.save()
59  
-"""}
16  tests/modeltests/field_defaults/tests.py
... ...
@@ -0,0 +1,16 @@
  1
+from datetime import datetime
  2
+
  3
+from django.test import TestCase
  4
+
  5
+from models import Article
  6
+
  7
+
  8
+class DefaultTests(TestCase):
  9
+    def test_field_defaults(self):
  10
+        a = Article()
  11
+        now = datetime.now()
  12
+        a.save()
  13
+
  14
+        self.assertTrue(isinstance(a.id, (int, long)))
  15
+        self.assertEqual(a.headline, "Default headline")
  16
+        self.assertTrue((now - a.pub_date).seconds < 5)
6  tests/regressiontests/i18n/models.py
@@ -10,9 +10,3 @@ class Company(models.Model):
10 10
     date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
11 11
     cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
12 12
     products_delivered = models.IntegerField()
13  
-
14  
-__test__ = {'API_TESTS': '''
15  
->>> tm = TestModel()
16  
->>> tm.save()
17  
-'''
18  
-}
21  tests/regressiontests/i18n/tests.py
@@ -5,14 +5,17 @@
5 5
 import sys
6 6
 import pickle
7 7
 
8  
-from django.template import Template, Context
9 8
 from django.conf import settings
  9
+from django.template import Template, Context
  10
+from django.test import TestCase
10 11
 from django.utils.formats import get_format, date_format, time_format, localize, localize_input
11 12
 from django.utils.numberformat import format as nformat
12  
-from django.test import TestCase
  13
+from django.utils.safestring import mark_safe, SafeString, SafeUnicode
13 14
 from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale
14 15
 
  16
+
15 17
 from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
  18
+from models import Company, TestModel
16 19
 
17 20
 
18 21
 class TranslationTests(TestCase):
@@ -59,7 +62,6 @@ def test_safe_status(self):
59 62
         """
60 63
         Translating a string requiring no auto-escaping shouldn't change the "safe" status.
61 64
         """
62  
-        from django.utils.safestring import mark_safe, SafeString, SafeUnicode
63 65
         s = mark_safe('Password')
64 66
         self.assertEqual(SafeString, type(s))
65 67
         activate('de')
@@ -620,3 +622,16 @@ class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
620 622
 
621 623
     def test_django_fallback(self):
622 624
         self.assertUgettext('Date/time', 'Datum/Zeit')
  625
+
  626
+
  627
+class TestModels(TestCase):
  628
+    def test_lazy(self):
  629
+        tm = TestModel()
  630
+        tm.save()
  631
+
  632
+    def test_safestr(self):
  633
+        c = Company(cents_payed=12, products_delivered=1)
  634
+        c.name = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
  635
+        c.save()
  636
+        c.name = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
  637
+        c.save()

0 notes on commit f7f2c72

Please sign in to comment.
Something went wrong with that request. Please try again.