| 1 | from django.test import TestCase |
| 2 | |
| 3 | class OneToOneDeletion(TestCase): |
| 4 | """Regression test for #9023""" |
| 5 | |
| 6 | def setUp(self): |
| 7 | from models import Ticket9023Widget, Ticket9023Sprocket |
| 8 | self.w = Ticket9023Widget(name="Some Widget") |
| 9 | self.w.save() |
| 10 | self.s = Ticket9023Sprocket(name="Some Sprocket") |
| 11 | self.s.w = self.w |
| 12 | self.s.save() |
| 13 | |
| 14 | def testNullAndDelete(self): |
| 15 | from models import Ticket9023Widget, Ticket9023Sprocket |
| 16 | self.assertEqual(Ticket9023Widget.objects.all().count(), 1) |
| 17 | self.assertEqual(Ticket9023Sprocket.objects.all().count(), 1) |
| 18 | |
| 19 | self.s.w = None |
| 20 | self.s.save() |
| 21 | self.w.delete() |
| 22 | |
| 23 | self.assertEqual(Ticket9023Widget.objects.all().count(), 0) |
| 24 | self.assertEqual(Ticket9023Sprocket.objects.all().count(), 1) |
| 25 | |
| 26 | def testNullAccessAndDelete(self): |
| 27 | from models import Ticket9023Widget, Ticket9023Sprocket |
| 28 | self.assertEqual(Ticket9023Widget.objects.all().count(), 1) |
| 29 | self.assertEqual(Ticket9023Sprocket.objects.all().count(), 1) |
| 30 | |
| 31 | self.w.sprocket.name |
| 32 | self.s.w = None |
| 33 | self.s.save() |
| 34 | self.w.delete() |
| 35 | |
| 36 | self.assertEqual(Ticket9023Widget.objects.all().count(), 0) |
| 37 | self.assertEqual(Ticket9023Sprocket.objects.all().count(), 1) |
| 38 | |
| 39 | def tearDown(self): |
| 40 | from models import Ticket9023Widget, Ticket9023Sprocket |
| 41 | Ticket9023Widget.objects.all().delete() |
| 42 | Ticket9023Sprocket.objects.all().delete() |
| 43 | |