mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #14711 -- Corrected the calculation for the previous month in generic date views. Thanks to msundstr for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15438 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7494345c39
commit
d89ad6423c
2 changed files with 28 additions and 4 deletions
|
@ -198,6 +198,29 @@ class MonthArchiveViewTests(TestCase):
|
|||
res = self.client.get('/dates/books/2007/no_month/')
|
||||
self.assertEqual(res.status_code, 404)
|
||||
|
||||
def test_previous_month_without_content(self):
|
||||
"Content can exist on any day of the previous month. Refs #14711"
|
||||
self.pubdate_list = [
|
||||
datetime.date(2010, month, day)
|
||||
for month,day in ((9,1), (10,2), (11,3))
|
||||
]
|
||||
for pubdate in self.pubdate_list:
|
||||
name = str(pubdate)
|
||||
Book.objects.create(name=name, slug=name, pages=100, pubdate=pubdate)
|
||||
|
||||
res = self.client.get('/dates/books/2010/nov/allow_empty/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1))
|
||||
# The following test demonstrates the bug
|
||||
res = self.client.get('/dates/books/2010/nov/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1))
|
||||
# The bug does not occur here because a Book with pubdate of Sep 1 exists
|
||||
res = self.client.get('/dates/books/2010/oct/')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertEqual(res.context['previous_month'], datetime.date(2010,9,1))
|
||||
|
||||
|
||||
class WeekArchiveViewTests(TestCase):
|
||||
fixtures = ['generic-views-test-data.json']
|
||||
urls = 'regressiontests.generic_views.urls'
|
||||
|
@ -359,3 +382,4 @@ class DateDetailViewTests(TestCase):
|
|||
|
||||
def test_invalid_url(self):
|
||||
self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue