| 353 | class NextPreviousMonthViewTests(TestCase): |
| 354 | urls = 'regressiontests.generic_views.urls' |
| 355 | |
| 356 | def setUp(self): |
| 357 | self.pubdate_list = [ |
| 358 | datetime.date(2010, month, day) |
| 359 | for month,day in ((9,1), (10,2), (11,3)) |
| 360 | ] |
| 361 | for pubdate in self.pubdate_list: |
| 362 | name = str(pubdate) |
| 363 | Book.objects.create(name=name, slug=name, pages=100, pubdate=pubdate) |
| 364 | |
| 365 | def test_previous_month_bug(self): |
| 366 | res = self.client.get('/dates/books/2010/nov/allow_empty/') |
| 367 | self.assertEqual(res.status_code, 200) |
| 368 | self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1)) |
| 369 | # The following test demonstrates the bug |
| 370 | res = self.client.get('/dates/books/2010/nov/') |
| 371 | self.assertEqual(res.status_code, 200) |
| 372 | self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1)) |
| 373 | # The bug does not occur here because a Book with pubdate of Sep 1 exists |
| 374 | res = self.client.get('/dates/books/2010/oct/') |
| 375 | self.assertEqual(res.status_code, 200) |
| 376 | self.assertEqual(res.context['previous_month'], datetime.date(2010,9,1)) |
| 377 | |
| 378 | No newline at end of file |