1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[soc2010/test-refactor] Updated custom_methods model test to unittests

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/test-refactor@13373 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Paul McMillan 2010-06-22 02:53:14 +00:00
parent cc4703d5ae
commit 078b13e97e
2 changed files with 26 additions and 21 deletions

View File

@ -36,24 +36,3 @@ class Article(models.Model):
# The asterisk in "(*row)" tells Python to expand the list into
# positional arguments to Article().
return [self.__class__(*row) for row in cursor.fetchall()]
__test__ = {'API_TESTS':"""
# Create a couple of Articles.
>>> from datetime import date
>>> a = Article(id=None, headline='Area man programs in Python', pub_date=date(2005, 7, 27))
>>> a.save()
>>> b = Article(id=None, headline='Beatles reunite', pub_date=date(2005, 7, 27))
>>> b.save()
# Test the custom methods.
>>> a.was_published_today()
False
>>> a.articles_from_same_day_1()
[<Article: Beatles reunite>]
>>> a.articles_from_same_day_2()
[<Article: Beatles reunite>]
>>> b.articles_from_same_day_1()
[<Article: Area man programs in Python>]
>>> b.articles_from_same_day_2()
[<Article: Area man programs in Python>]
"""}

View File

@ -0,0 +1,26 @@
from datetime import date
from django.test import TestCase
from models import Article
class CustomMethodsTestCase(TestCase):
def test_custom_methods(self):
# Create a couple of Articles.
a = Article(id=None, headline='Area man programs in Python', pub_date=date(2005, 7, 27))
a.save()
b = Article(id=None, headline='Beatles reunite', pub_date=date(2005, 7, 27))
b.save()
# Test the custom methods.
self.assertFalse(a.was_published_today())
self.assertQuerysetEqual(a.articles_from_same_day_1(),
['<Article: Beatles reunite>'])
self.assertQuerysetEqual(a.articles_from_same_day_2(),
['<Article: Beatles reunite>'])
self.assertQuerysetEqual(b.articles_from_same_day_1(),
['<Article: Area man programs in Python>'])
self.assertQuerysetEqual(b.articles_from_same_day_2(),
['<Article: Area man programs in Python>'])