mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
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:
parent
c61d1361d0
commit
c2eea61dff
3 changed files with 27 additions and 3 deletions
|
@ -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/")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue