Skip to content

Commit b26f1d4

Browse files
committed
Migrated custom_methods doctests. Thanks to Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13775 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent ca90d15 commit b26f1d4

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

tests/modeltests/custom_methods/models.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,4 @@ def articles_from_same_day_2(self):
3333
WHERE pub_date = %s
3434
AND id != %s""", [connection.ops.value_to_db_date(self.pub_date),
3535
self.id])
36-
# The asterisk in "(*row)" tells Python to expand the list into
37-
# positional arguments to Article().
3836
return [self.__class__(*row) for row in cursor.fetchall()]
39-
40-
__test__ = {'API_TESTS':"""
41-
# Create a couple of Articles.
42-
>>> from datetime import date
43-
>>> a = Article(id=None, headline='Area man programs in Python', pub_date=date(2005, 7, 27))
44-
>>> a.save()
45-
>>> b = Article(id=None, headline='Beatles reunite', pub_date=date(2005, 7, 27))
46-
>>> b.save()
47-
48-
# Test the custom methods.
49-
>>> a.was_published_today()
50-
False
51-
>>> a.articles_from_same_day_1()
52-
[<Article: Beatles reunite>]
53-
>>> a.articles_from_same_day_2()
54-
[<Article: Beatles reunite>]
55-
>>> b.articles_from_same_day_1()
56-
[<Article: Area man programs in Python>]
57-
>>> b.articles_from_same_day_2()
58-
[<Article: Area man programs in Python>]
59-
"""}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from datetime import date
2+
3+
from django.test import TestCase
4+
5+
from models import Article
6+
7+
8+
class MethodsTests(TestCase):
9+
def test_custom_methods(self):
10+
a = Article.objects.create(
11+
headline="Area man programs in Python", pub_date=date(2005, 7, 27)
12+
)
13+
b = Article.objects.create(
14+
headline="Beatles reunite", pub_date=date(2005, 7, 27)
15+
)
16+
17+
self.assertFalse(a.was_published_today())
18+
self.assertQuerysetEqual(
19+
a.articles_from_same_day_1(), [
20+
"Beatles reunite",
21+
],
22+
lambda a: a.headline,
23+
)
24+
self.assertQuerysetEqual(
25+
a.articles_from_same_day_2(), [
26+
"Beatles reunite",
27+
],
28+
lambda a: a.headline
29+
)
30+
31+
self.assertQuerysetEqual(
32+
b.articles_from_same_day_1(), [
33+
"Area man programs in Python",
34+
],
35+
lambda a: a.headline,
36+
)
37+
self.assertQuerysetEqual(
38+
b.articles_from_same_day_2(), [
39+
"Area man programs in Python",
40+
],
41+
lambda a: a.headline
42+
)

0 commit comments

Comments
 (0)