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 custom_methods doctests. Thanks to Alex Gaynor.

Backport of r13775 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 574ee8279219ac12b5e66cd57f4a21d69694bae0 1 parent e41d1b7
Russell Keith-Magee authored September 12, 2010
23  tests/modeltests/custom_methods/models.py
@@ -33,27 +33,4 @@ def articles_from_same_day_2(self):
33 33
             WHERE pub_date = %s
34 34
                 AND id != %s""", [connection.ops.value_to_db_date(self.pub_date),
35 35
                                   self.id])
36  
-        # The asterisk in "(*row)" tells Python to expand the list into
37  
-        # positional arguments to Article().
38 36
         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  
-"""}
42  tests/modeltests/custom_methods/tests.py
... ...
@@ -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 notes on commit 574ee82

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