diff options
| author | Ole Laursen <olau@iola.dk> | 2013-10-31 13:38:51 +0100 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-10-31 19:39:10 +0200 |
| commit | f4f01fb03c2855d42b4d9589c0c090439e02c55b (patch) | |
| tree | eae456fc601b1259bf148984d4bdc37f05ad5d31 /tests/model_formsets | |
| parent | c64efe37345cc632e24beb8c7e2a81ef5d3713ba (diff) | |
Fixed #18508 -- tests for repeated deletion bug in ModelFormSet
The ticket's issue was already fixed by patch for #14877.
Diffstat (limited to 'tests/model_formsets')
| -rw-r--r-- | tests/model_formsets/tests.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index 94e1ccbe53..4c57e0f549 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -100,6 +100,36 @@ class DeletionTests(TestCase): formset.save() self.assertEqual(Poet.objects.count(), 0) + def test_outdated_deletion(self): + poet = Poet.objects.create(name='test') + poem = Poem.objects.create(name='Brevity is the soul of wit', poet=poet) + + PoemFormSet = inlineformset_factory(Poet, Poem, fields="__all__", can_delete=True) + + # Simulate deletion of an object that doesn't exist in the database + data = { + 'form-TOTAL_FORMS': '2', + 'form-INITIAL_FORMS': '2', + 'form-0-id': str(poem.pk), + 'form-0-name': 'foo', + 'form-1-id': str(poem.pk + 1), # doesn't exist + 'form-1-name': 'bar', + 'form-1-DELETE': 'on', + } + formset = PoemFormSet(data, instance=poet, prefix="form") + + # The formset is valid even though poem.pk + 1 doesn't exist, + # because it's marked for deletion anyway + self.assertTrue(formset.is_valid()) + + formset.save() + + # Make sure the save went through correctly + self.assertEqual(Poem.objects.get(pk=poem.pk).name, "foo") + self.assertEqual(poet.poem_set.count(), 1) + self.assertFalse(Poem.objects.filter(pk=poem.pk + 1).exists()) + + class ModelFormsetTest(TestCase): def test_simple_save(self): qs = Author.objects.all() |
