summaryrefslogtreecommitdiff
path: root/tests/generic_views/test_dates.py
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2018-10-26 17:10:17 +0200
committerTim Graham <timograham@gmail.com>2018-10-27 18:37:44 -0400
commit4c13b907023692f75f37ba980cf2215e413aa1d8 (patch)
tree41588b17cc1cbdf88134e586e101f3368bcc8135 /tests/generic_views/test_dates.py
parentf892781b957f674806a227a10c58768f66a48c07 (diff)
Added test coverage for views.generic.dates.MonthMixin.get_month() KeyError branch.
Diffstat (limited to 'tests/generic_views/test_dates.py')
-rw-r--r--tests/generic_views/test_dates.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index 6a18e090e6..2daac10b31 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -408,6 +408,20 @@ class MonthArchiveViewTests(TestDataMixin, TestCase):
res = self.client.get('/dates/booksignings/2008/apr/')
self.assertEqual(res.status_code, 200)
+ def test_month_view_get_month_from_request(self):
+ oct1 = datetime.date(2008, 10, 1)
+ res = self.client.get('/dates/books/without_month/2008/?month=oct')
+ self.assertEqual(res.status_code, 200)
+ self.assertTemplateUsed(res, 'generic_views/book_archive_month.html')
+ self.assertEqual(list(res.context['date_list']), [oct1])
+ self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate=oct1)))
+ self.assertEqual(res.context['month'], oct1)
+
+ def test_month_view_without_month_in_url(self):
+ res = self.client.get('/dates/books/without_month/2008/')
+ self.assertEqual(res.status_code, 404)
+ self.assertEqual(res.context['exception'], 'No month specified')
+
@skipUnlessDBFeature('has_zoneinfo_database')
@override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi')
def test_aware_datetime_month_view(self):