Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: django/django
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: OleLaursen/django
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Oct 31, 2013

  1. Copy the full SHA
    acc14da View commit details
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/model_formsets/tests.py
30 changes: 30 additions & 0 deletions tests/model_formsets/tests.py
Original file line number Diff line number Diff line change
@@ -100,6 +100,36 @@ def test_change_form_deletion_when_invalid(self):
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.assertTrue(not Poem.objects.filter(pk=poem.pk + 1).exists())


class ModelFormsetTest(TestCase):
def test_simple_save(self):
qs = Author.objects.all()