summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul McMillan <Paul@McMillan.ws>2010-06-22 02:58:45 +0000
committerPaul McMillan <Paul@McMillan.ws>2010-06-22 02:58:45 +0000
commit6f851bca15880e7aaa115edd54fe19771445d30d (patch)
tree275001ed27774a911d3c31a90c08775b4b793ab3
parentdc2fd96803dd99ac466b4c22f9bdb1294c7b3c37 (diff)
[soc2010/test-refactor] Updated field_defaults modeltest to unittest
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/test-refactor@13379 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--tests/modeltests/field_defaults/models.py38
-rw-r--r--tests/modeltests/field_defaults/tests.py40
2 files changed, 40 insertions, 38 deletions
diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py
index f258134147..0dd1f72934 100644
--- a/tests/modeltests/field_defaults/models.py
+++ b/tests/modeltests/field_defaults/models.py
@@ -19,41 +19,3 @@ class Article(models.Model):
def __unicode__(self):
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()
-"""}
diff --git a/tests/modeltests/field_defaults/tests.py b/tests/modeltests/field_defaults/tests.py
new file mode 100644
index 0000000000..47eeaed538
--- /dev/null
+++ b/tests/modeltests/field_defaults/tests.py
@@ -0,0 +1,40 @@
+# coding: utf-8
+from datetime import datetime
+
+from django.test import TestCase
+from django.utils.safestring import SafeUnicode, SafeString
+
+from models import Article
+
+class FieldDefaultsTestCase(TestCase):
+ def test_article_defaults(self):
+ # No articles are in the system yet.
+ self.assertEqual(len(Article.objects.all()), 0)
+
+ # 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".
+ self.assertEqual(a.id, 1L)
+
+ # Access database columns via Python attributes.
+ self.assertEqual(a.headline, u'Default headline')
+
+ # make sure the two dates are sufficiently close
+ #fixme, use the new unittest2 function
+ d = now - a.pub_date
+ self.assertTrue(d.seconds < 5)
+
+ # make sure that SafeString/SafeUnicode fields work
+ 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()