Kaydet (Commit) 521be8cd authored tarafından Russell Keith-Magee's avatar Russell Keith-Magee

Migrated i18n and field_defaults doctests. Thanks to Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13779 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst 3fe5c619
...@@ -19,41 +19,3 @@ class Article(models.Model): ...@@ -19,41 +19,3 @@ class Article(models.Model):
def __unicode__(self): def __unicode__(self):
return self.headline return self.headline
__test__ = {'API_TESTS': u"""
>>> from datetime import datetime
# No articles are in the system yet.
>>> Article.objects.all()
[]
# Create an Article.
>>> a = Article(id=None)
# Grab the current datetime it should be very close to the default that just
# got saved as a.pub_date
>>> now = datetime.now()
# Save it into the database. You have to call save() explicitly.
>>> a.save()
# Now it has an ID. Note it's a long integer, as designated by the trailing "L".
>>> a.id
1L
# Access database columns via Python attributes.
>>> a.headline
u'Default headline'
# make sure the two dates are sufficiently close
>>> d = now - a.pub_date
>>> d.seconds < 5
True
# make sure that SafeString/SafeUnicode fields work
>>> from django.utils.safestring import SafeUnicode, SafeString
>>> a.headline = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
>>> a.save()
>>> a.headline = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
>>> a.save()
"""}
from datetime import datetime
from django.test import TestCase
from models import Article
class DefaultTests(TestCase):
def test_field_defaults(self):
a = Article()
now = datetime.now()
a.save()
self.assertTrue(isinstance(a.id, (int, long)))
self.assertEqual(a.headline, "Default headline")
self.assertTrue((now - a.pub_date).seconds < 5)
...@@ -10,9 +10,3 @@ class Company(models.Model): ...@@ -10,9 +10,3 @@ class Company(models.Model):
date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0)) date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
cents_payed = models.DecimalField(max_digits=4, decimal_places=2) cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
products_delivered = models.IntegerField() products_delivered = models.IntegerField()
__test__ = {'API_TESTS': '''
>>> tm = TestModel()
>>> tm.save()
'''
}
...@@ -5,14 +5,17 @@ import os ...@@ -5,14 +5,17 @@ import os
import sys import sys
import pickle import pickle
from django.template import Template, Context
from django.conf import settings from django.conf import settings
from django.template import Template, Context
from django.test import TestCase
from django.utils.formats import get_format, date_format, time_format, localize, localize_input from django.utils.formats import get_format, date_format, time_format, localize, localize_input
from django.utils.numberformat import format as nformat from django.utils.numberformat import format as nformat
from django.test import TestCase from django.utils.safestring import mark_safe, SafeString, SafeUnicode
from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale
from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
from models import Company, TestModel
class TranslationTests(TestCase): class TranslationTests(TestCase):
...@@ -59,7 +62,6 @@ class TranslationTests(TestCase): ...@@ -59,7 +62,6 @@ class TranslationTests(TestCase):
""" """
Translating a string requiring no auto-escaping shouldn't change the "safe" status. Translating a string requiring no auto-escaping shouldn't change the "safe" status.
""" """
from django.utils.safestring import mark_safe, SafeString, SafeUnicode
s = mark_safe('Password') s = mark_safe('Password')
self.assertEqual(SafeString, type(s)) self.assertEqual(SafeString, type(s))
activate('de') activate('de')
...@@ -620,3 +622,16 @@ class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests): ...@@ -620,3 +622,16 @@ class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
def test_django_fallback(self): def test_django_fallback(self):
self.assertUgettext('Date/time', 'Datum/Zeit') self.assertUgettext('Date/time', 'Datum/Zeit')
class TestModels(TestCase):
def test_lazy(self):
tm = TestModel()
tm.save()
def test_safestr(self):
c = Company(cents_payed=12, products_delivered=1)
c.name = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
c.save()
c.name = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
c.save()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment