diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py index 8cd2b2a8be6..0109345c41f 100644 --- a/tests/generic_views/test_dates.py +++ b/tests/generic_views/test_dates.py @@ -156,6 +156,11 @@ class ArchiveIndexViewTests(TestDataMixin, TestCase): self.assertEqual(list(res.context['latest']), list(Book.objects.order_by('-name').all())) self.assertTemplateUsed(res, 'generic_views/book_archive.html') + def test_archive_view_without_date_field(self): + msg = 'BookArchiveWithoutDateField.date_field is required.' + with self.assertRaisesMessage(ImproperlyConfigured, msg): + self.client.get('/dates/books/without_date_field/') + @override_settings(ROOT_URLCONF='generic_views.urls') class YearArchiveViewTests(TestDataMixin, TestCase): @@ -291,6 +296,11 @@ class YearArchiveViewTests(TestDataMixin, TestCase): self.assertIsNone(kwargs['previous_year']) self.assertIsNone(kwargs['next_year']) + def test_get_dated_items_not_implemented(self): + msg = 'A DateView must provide an implementation of get_dated_items()' + with self.assertRaisesMessage(NotImplementedError, msg): + self.client.get('/BaseDateListViewTest/') + @override_settings(ROOT_URLCONF='generic_views.urls') class MonthArchiveViewTests(TestDataMixin, TestCase): diff --git a/tests/generic_views/urls.py b/tests/generic_views/urls.py index 8fbcbbc8cb9..5295bff08d2 100644 --- a/tests/generic_views/urls.py +++ b/tests/generic_views/urls.py @@ -2,7 +2,7 @@ from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required from django.urls import path, re_path from django.views.decorators.cache import cache_page -from django.views.generic import TemplateView +from django.views.generic import TemplateView, dates from . import views from .models import Book @@ -115,6 +115,7 @@ urlpatterns = [ path('dates/booksignings/', views.BookSigningArchive.as_view()), path('dates/books/sortedbyname/', views.BookArchive.as_view(ordering='name')), path('dates/books/sortedbynamedec/', views.BookArchive.as_view(ordering='-name')), + path('dates/books/without_date_field/', views.BookArchiveWithoutDateField.as_view()), # ListView @@ -225,5 +226,7 @@ urlpatterns = [ path('dates/booksignings/////', views.BookSigningDetail.as_view()), # Useful for testing redirects - path('accounts/login/', auth_views.LoginView.as_view()) + path('accounts/login/', auth_views.LoginView.as_view()), + + path('BaseDateListViewTest/', dates.BaseDateListView.as_view()), ] diff --git a/tests/generic_views/views.py b/tests/generic_views/views.py index ff08313cb6f..02717333a6b 100644 --- a/tests/generic_views/views.py +++ b/tests/generic_views/views.py @@ -295,6 +295,10 @@ class BookSigningTodayArchive(BookSigningConfig, generic.TodayArchiveView): pass +class BookArchiveWithoutDateField(generic.ArchiveIndexView): + queryset = Book.objects.all() + + class BookSigningDetail(BookSigningConfig, generic.DateDetailView): context_object_name = 'book'