File: tests.py

package info (click to toggle)
python-django 1.2.3-3%2Bsqueeze10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 29,064 kB
  • ctags: 20,458
  • sloc: python: 101,293; xml: 574; makefile: 149; sh: 121; sql: 7
file content (22 lines) | stat: -rw-r--r-- 903 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.test import TestCase
from regressiontests.one_to_one_regress.models import Place, UndergroundBar

class OneToOneDeletionTests(TestCase):
    def test_reverse_relationship_cache_cascade(self):
        """
        Regression test for #9023: accessing the reverse relationship shouldn't
        result in a cascading delete().
        """
        place = Place.objects.create(name="Dempsey's", address="623 Vermont St")
        bar = UndergroundBar.objects.create(place=place, serves_cocktails=False)

        # The bug in #9023: if you access the one-to-one relation *before*
        # setting to None and deleting, the cascade happens anyway.
        place.undergroundbar
        bar.place.name='foo'
        bar.place = None
        bar.save()
        place.delete()

        self.assertEqual(Place.objects.all().count(), 0)
        self.assertEqual(UndergroundBar.objects.all().count(), 1)