Fixed #28209 -- Made date-based generic views return a 404 rather than crash when given an out of range date.

This commit is contained in:
Adit Biswas 2017-05-16 00:26:30 +05:30 committed by Tim Graham
parent c61d1361d0
commit c2eea61dff
3 changed files with 27 additions and 3 deletions

View file

@ -661,6 +661,18 @@ class DateDetailViewTests(TestDataMixin, TestCase):
self.assertEqual(res.context['book'], b)
self.assertTemplateUsed(res, 'generic_views/book_detail.html')
def test_year_out_of_range(self):
urls = [
'/dates/books/9999/',
'/dates/books/9999/12/',
'/dates/books/9999/week/52/',
]
for url in urls:
with self.subTest(url=url):
res = self.client.get(url)
self.assertEqual(res.status_code, 404)
self.assertEqual(res.context['exception'], 'Date out of range')
def test_invalid_url(self):
with self.assertRaises(AttributeError):
self.client.get("/dates/books/2008/oct/01/nopk/")