Increased test coverage of django/views/generic/dates.py.
This commit is contained in:
parent
916aecd29d
commit
c1c68d1ac0
|
@ -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):
|
||||
|
|
|
@ -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/<int:year>/<month>/<int:day>/<int:pk>/', 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()),
|
||||
]
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
Loading…
Reference in New Issue