Code

Ticket #14711: tests.diff

File tests.diff, 2.4 KB (added by msundstr, 3 years ago)

test case demonstrating the problem

Line 
1Index: tests/regressiontests/generic_views/dates.py
2===================================================================
3--- tests/regressiontests/generic_views/dates.py        (revision 14597)
4+++ tests/regressiontests/generic_views/dates.py        (working copy)
5@@ -350,3 +350,28 @@
6     def test_invalid_url(self):
7         self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/")
8 
9+class NextPreviousMonthViewTests(TestCase):
10+    urls = 'regressiontests.generic_views.urls'
11+
12+    def setUp(self):
13+        self.pubdate_list = [
14+            datetime.date(2010, month, day)
15+            for month,day in ((9,1), (10,2), (11,3))
16+        ]
17+        for pubdate in self.pubdate_list:
18+            name = str(pubdate)
19+            Book.objects.create(name=name, slug=name, pages=100, pubdate=pubdate)
20+
21+    def test_previous_month_bug(self):
22+        res = self.client.get('/dates/books/2010/nov/allow_empty/')
23+        self.assertEqual(res.status_code, 200)
24+        self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1))
25+        # The following test demonstrates the bug
26+        res = self.client.get('/dates/books/2010/nov/')
27+        self.assertEqual(res.status_code, 200)
28+        self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1))
29+        # The bug does not occur here because a Book with pubdate of Sep 1 exists
30+        res = self.client.get('/dates/books/2010/oct/')
31+        self.assertEqual(res.status_code, 200)
32+        self.assertEqual(res.context['previous_month'], datetime.date(2010,9,1))
33+       
34\ No newline at end of file
35Index: tests/regressiontests/generic_views/tests.py
36===================================================================
37--- tests/regressiontests/generic_views/tests.py        (revision 14597)
38+++ tests/regressiontests/generic_views/tests.py        (working copy)
39@@ -2,4 +2,5 @@
40 from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests
41 from regressiontests.generic_views.detail import DetailViewTest
42 from regressiontests.generic_views.edit import CreateViewTests, UpdateViewTests, DeleteViewTests
43-from regressiontests.generic_views.list import ListViewTests
44\ No newline at end of file
45+from regressiontests.generic_views.list import ListViewTests
46+from regressiontests.generic_views.dates import NextPreviousMonthViewTests
47\ No newline at end of file