summaryrefslogtreecommitdiff
path: root/tests/generic_views
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
parentf892781b957f674806a227a10c58768f66a48c07 (diff)
downloaddjango-4c13b907023692f75f37ba980cf2215e413aa1d8.tar.gz
Added test coverage for views.generic.dates.MonthMixin.get_month() KeyError branch.
Diffstat (limited to 'tests/generic_views')
-rw-r--r--tests/generic_views/test_dates.py14
-rw-r--r--tests/generic_views/urls.py1
2 files changed, 15 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):
diff --git a/tests/generic_views/urls.py b/tests/generic_views/urls.py
index 1c1fed3386..f2af8ad1a3 100644
--- a/tests/generic_views/urls.py
+++ b/tests/generic_views/urls.py
@@ -168,6 +168,7 @@ urlpatterns = [
# MonthArchiveView
path('dates/books/<int:year>/<int:month>/', views.BookMonthArchive.as_view(month_format='%m')),
path('dates/books/<int:year>/<month>/', views.BookMonthArchive.as_view()),
+ path('dates/books/without_month/<int:year>/', views.BookMonthArchive.as_view()),
path('dates/books/<int:year>/<month>/allow_empty/', views.BookMonthArchive.as_view(allow_empty=True)),
path('dates/books/<int:year>/<month>/allow_future/', views.BookMonthArchive.as_view(allow_future=True)),
path('dates/books/<int:year>/<month>/paginated/', views.BookMonthArchive.as_view(paginate_by=30)),