diff options
author | Sebastian Sassi <ssassi@sophilabs.com> | 2017-08-17 18:55:58 -0300 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-09-04 10:55:18 -0400 |
commit | 5848305218a08eb0c0a32086813d14dc6f46b463 (patch) | |
tree | 861ae3f64abf906f2d6fa531745543c5d04c5edc /tests/generic_views | |
parent | 0d3f567a7ace9ca688712ffea9a396e118a4a697 (diff) | |
download | django-5848305218a08eb0c0a32086813d14dc6f46b463.tar.gz |
Fixed #28082 -- Made BaseDateListView pass context from get_dated_items() to subclasses.
Thanks leon-matthews for the report and fix.
Diffstat (limited to 'tests/generic_views')
-rw-r--r-- | tests/generic_views/test_dates.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py index ff3b09ddf3..054ec7d223 100644 --- a/tests/generic_views/test_dates.py +++ b/tests/generic_views/test_dates.py @@ -1,4 +1,5 @@ import datetime +from unittest import mock from django.core.exceptions import ImproperlyConfigured from django.test import TestCase, override_settings, skipUnlessDBFeature @@ -274,6 +275,22 @@ class YearArchiveViewTests(TestDataMixin, TestCase): res = self.client.get('/dates/books/2011/') self.assertEqual(list(res.context['date_list']), list(sorted(res.context['date_list']))) + @mock.patch('django.views.generic.list.MultipleObjectMixin.get_context_data') + def test_get_context_data_receives_extra_context(self, mock): + """ + MultipleObjectMixin.get_context_data() receives the context set by + BaseYearArchiveView.get_dated_items(). This behavior is implemented in + BaseDateListView.get(). + """ + BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0)) + with self.assertRaisesMessage(TypeError, 'context must be a dict rather than MagicMock.'): + self.client.get('/dates/booksignings/2008/') + args, kwargs = mock.call_args + # These are context values from get_dated_items(). + self.assertEqual(kwargs['year'], datetime.date(2008, 1, 1)) + self.assertIsNone(kwargs['previous_year']) + self.assertIsNone(kwargs['next_year']) + @override_settings(ROOT_URLCONF='generic_views.urls') class MonthArchiveViewTests(TestDataMixin, TestCase): |