summaryrefslogtreecommitdiff
path: root/tests/generic_views
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-06-25 23:00:51 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-06-26 11:12:57 +0200
commit8984cab8a80af8555b1ccfa5b552d411b47f9bca (patch)
tree0951ce3e3396d696a2a28595d4019e1becd0abc9 /tests/generic_views
parentd2c135da4c75079e45661ec609bd72f27dddf2a9 (diff)
downloaddjango-8984cab8a80af8555b1ccfa5b552d411b47f9bca.tar.gz
Fixed #31620 -- Added support for %V format to WeekMixin/WeekArchiveView.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/generic_views')
-rw-r--r--tests/generic_views/test_dates.py21
-rw-r--r--tests/generic_views/urls.py8
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index 0109345c41..bff58dcd0c 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -538,10 +538,29 @@ class WeekArchiveViewTests(TestDataMixin, TestCase):
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context['week'], datetime.date(2008, 9, 29))
+ def test_week_iso_format(self):
+ res = self.client.get('/dates/books/2008/week/40/iso_format/')
+ self.assertEqual(res.status_code, 200)
+ self.assertTemplateUsed(res, 'generic_views/book_archive_week.html')
+ self.assertEqual(
+ list(res.context['book_list']),
+ [Book.objects.get(pubdate=datetime.date(2008, 10, 1))],
+ )
+ self.assertEqual(res.context['week'], datetime.date(2008, 9, 29))
+
def test_unknown_week_format(self):
- with self.assertRaisesMessage(ValueError, "Unknown week format '%T'. Choices are: %U, %W"):
+ msg = "Unknown week format '%T'. Choices are: %U, %V, %W"
+ with self.assertRaisesMessage(ValueError, msg):
self.client.get('/dates/books/2008/week/39/unknown_week_format/')
+ def test_incompatible_iso_week_format_view(self):
+ msg = (
+ "ISO week directive '%V' is incompatible with the year directive "
+ "'%Y'. Use the ISO year '%G' instead."
+ )
+ with self.assertRaisesMessage(ValueError, msg):
+ self.client.get('/dates/books/2008/week/40/invalid_iso_week_year_format/')
+
def test_datetime_week_view(self):
BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0))
res = self.client.get('/dates/booksignings/2008/week/13/')
diff --git a/tests/generic_views/urls.py b/tests/generic_views/urls.py
index d547c5be4a..9537240ab8 100644
--- a/tests/generic_views/urls.py
+++ b/tests/generic_views/urls.py
@@ -190,6 +190,14 @@ urlpatterns = [
'dates/books/<int:year>/week/<int:week>/unknown_week_format/',
views.BookWeekArchive.as_view(week_format='%T'),
),
+ path(
+ 'dates/books/<int:year>/week/<int:week>/iso_format/',
+ views.BookWeekArchive.as_view(year_format='%G', week_format='%V'),
+ ),
+ path(
+ 'dates/books/<int:year>/week/<int:week>/invalid_iso_week_year_format/',
+ views.BookWeekArchive.as_view(week_format='%V'),
+ ),
path('dates/booksignings/<int:year>/week/<int:week>/', views.BookSigningWeekArchive.as_view()),
# DayArchiveView