Anonymous avatar Anonymous committed 42a02ee

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

Comments (0)

Files changed (2)

tests/modeltests/custom_methods/models.py

         # 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>]
-"""}

tests/modeltests/custom_methods/tests.py

+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>'])
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.