summaryrefslogtreecommitdiff
path: root/tests/model_formsets/tests.py
diff options
context:
space:
mode:
authorAlexander Kavanaugh <alex@kavdev.io>2017-05-01 16:58:28 -0700
committerTim Graham <timograham@gmail.com>2017-05-03 07:45:51 -0400
commit362fba87c9bb4f88542ba82ce4a732fed2634be7 (patch)
tree175f701281df706f939d331754dc738da37982e3 /tests/model_formsets/tests.py
parent9b2d47bcded8320114193e9b2a200119a19974a6 (diff)
Fixed #28159 -- Fixed BaseInlineFormSet._construct_form() crash when using save_as_new.
Regression in 4a246a02bdcbc13b15480c014f51cb0682af7c1e.
Diffstat (limited to 'tests/model_formsets/tests.py')
-rw-r--r--tests/model_formsets/tests.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py
index 3873cb3b27..c440631ba7 100644
--- a/tests/model_formsets/tests.py
+++ b/tests/model_formsets/tests.py
@@ -10,6 +10,7 @@ from django.forms.models import (
BaseModelFormSet, _get_foreign_key, inlineformset_factory,
modelformset_factory,
)
+from django.http import QueryDict
from django.test import TestCase, skipUnlessDBFeature
from .models import (
@@ -699,7 +700,9 @@ class ModelFormsetTest(TestCase):
AuthorBooksFormSet = inlineformset_factory(Author, Book, can_delete=False, extra=2, fields="__all__")
Author.objects.create(name='Charles Baudelaire')
- data = {
+ # An immutable QueryDict simulates request.POST.
+ data = QueryDict(mutable=True)
+ data.update({
'book_set-TOTAL_FORMS': '3', # the number of forms rendered
'book_set-INITIAL_FORMS': '2', # the number of forms with initial data
'book_set-MAX_NUM_FORMS': '', # the max number of forms
@@ -708,10 +711,12 @@ class ModelFormsetTest(TestCase):
'book_set-1-id': '2',
'book_set-1-title': 'Les Paradis Artificiels',
'book_set-2-title': '',
- }
+ })
+ data._mutable = False
formset = AuthorBooksFormSet(data, instance=Author(), save_as_new=True)
self.assertTrue(formset.is_valid())
+ self.assertIs(data._mutable, False)
new_author = Author.objects.create(name='Charles Baudelaire')
formset = AuthorBooksFormSet(data, instance=new_author, save_as_new=True)