Code

Ticket #14711: test_case.py

File test_case.py, 1.1 KB (added by msundstr, 3 years ago)

the test case that should go in generic_views/dates.py (I can't get the tests.diff to upload)

Line 
1class NextPreviousMonthViewTests(TestCase):
2    urls = 'regressiontests.generic_views.urls'
3
4    def setUp(self):
5        self.pubdate_list = [
6            datetime.date(2010, month, day)
7            for month,day in ((9,1), (10,2), (11,3))
8        ]
9        for pubdate in self.pubdate_list:
10            name = str(pubdate)
11            Book.objects.create(name=name, slug=name, pages=100, pubdate=pubdate)
12
13    def test_previous_month_bug(self):
14        res = self.client.get('/dates/books/2010/nov/allow_empty/')
15        self.assertEqual(res.status_code, 200)
16        self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1))
17        # The following test demonstrates the bug
18        res = self.client.get('/dates/books/2010/nov/')
19        self.assertEqual(res.status_code, 200)
20        self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1))
21        # The bug does not occur here because a Book with pubdate of Sep 1 exists
22        res = self.client.get('/dates/books/2010/oct/')
23        self.assertEqual(res.status_code, 200)
24        self.assertEqual(res.context['previous_month'], datetime.date(2010,9,1))