summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Cogdon <chris.cogdon@dtexsystems.com>2015-12-30 13:22:58 -0800
committerTim Graham <timograham@gmail.com>2015-12-30 17:30:37 -0500
commit8202ce45a5ae5dac2c6fdf94bf3554180bbdd7b7 (patch)
tree44499352a12216650399de6c6d3d6b5628ea8e68 /tests
parent4d9b98616f2d8b98946fdc752cc40f4283baf105 (diff)
[1.9.x] Fixed #26018 -- Prevented unecessary get_form() call in FormMixin.get_context_data().
Changed "dict.setdefault" to "if x in dict" pattern so that get_form() would not be called unnecessarily, specifically in the case where FormMixin.form_invalid() calls get_context_data() with the current form. Backport of e429c5186ceed81c4627165518e0c70c58e69595 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/generic_views/test_edit.py2
-rw-r--r--tests/generic_views/views.py5
2 files changed, 7 insertions, 0 deletions
diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py
index e0730b1118..ddbdcadf35 100644
--- a/tests/generic_views/test_edit.py
+++ b/tests/generic_views/test_edit.py
@@ -260,6 +260,7 @@ class UpdateViewTests(TestCase):
self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
self.assertTemplateUsed(res, 'generic_views/author_form.html')
+ self.assertEqual(res.context['view'].get_form_called_count, 1)
# Modification with both POST and PUT (browser compatible)
res = self.client.post('/edit/author/%d/update/' % a.pk,
@@ -279,6 +280,7 @@ class UpdateViewTests(TestCase):
self.assertTemplateUsed(res, 'generic_views/author_form.html')
self.assertEqual(len(res.context['form'].errors), 1)
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertEqual(res.context['view'].get_form_called_count, 1)
def test_update_with_object_url(self):
a = Artist.objects.create(name='Rene Magritte')
diff --git a/tests/generic_views/views.py b/tests/generic_views/views.py
index b7df1e410b..3ab5aca468 100644
--- a/tests/generic_views/views.py
+++ b/tests/generic_views/views.py
@@ -147,10 +147,15 @@ class NaiveAuthorUpdate(generic.UpdateView):
class AuthorUpdate(generic.UpdateView):
+ get_form_called_count = 0 # Used to ensure get_form() is called once.
model = Author
success_url = '/list/authors/'
fields = '__all__'
+ def get_form(self, *args, **kwargs):
+ self.get_form_called_count += 1
+ return super(AuthorUpdate, self).get_form(*args, **kwargs)
+
class OneAuthorUpdate(generic.UpdateView):
success_url = '/list/authors/'