|
5 | 5 |
|
6 | 6 | from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
7 | 7 | from django.test import TestCase, override_settings
|
| 8 | +from django.test.client import RequestFactory |
8 | 9 | from django.views.generic.base import View
|
| 10 | +from django.views.generic.detail import SingleObjectTemplateResponseMixin |
| 11 | +from django.views.generic.edit import ModelFormMixin |
9 | 12 |
|
10 | 13 | from .models import Artist, Author, Book, Page
|
11 | 14 |
|
@@ -137,6 +140,25 @@ def test_duplicated_context_object_name(self):
|
137 | 140 | self.assertNotIn('author', res.context)
|
138 | 141 | self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
139 | 142 |
|
| 143 | + def test_deferred_queryset_template_name(self): |
| 144 | + class FormContext(SingleObjectTemplateResponseMixin): |
| 145 | + request = RequestFactory().get('/') |
| 146 | + model = Author |
| 147 | + object = Author.objects.defer('name').get(pk=self.author1.pk) |
| 148 | + |
| 149 | + self.assertEqual(FormContext().get_template_names()[0], 'generic_views/author_detail.html') |
| 150 | + |
| 151 | + def test_deferred_queryset_context_object_name(self): |
| 152 | + class FormContext(ModelFormMixin): |
| 153 | + request = RequestFactory().get('/') |
| 154 | + model = Author |
| 155 | + object = Author.objects.defer('name').get(pk=self.author1.pk) |
| 156 | + fields = ('name',) |
| 157 | + |
| 158 | + form_context_data = FormContext().get_context_data() |
| 159 | + self.assertEqual(form_context_data['object'], self.author1) |
| 160 | + self.assertEqual(form_context_data['author'], self.author1) |
| 161 | + |
140 | 162 | def test_invalid_url(self):
|
141 | 163 | self.assertRaises(AttributeError, self.client.get, '/detail/author/invalid/url/')
|
142 | 164 |
|
|
0 commit comments