Ticket #9023: 9023-test.diff

File 9023-test.diff, 2.7 KB (added by adurdin, 6 years ago)

Regression test to exemplify the bug.

  • tests/regressiontests/model_regress/tests.py

     
     1from django.test import TestCase
     2
     3class 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
  • tests/regressiontests/model_regress/models.py

     
    5858        # object).
    5959        return 'Názov: %s' % self.name
    6060
     61class Ticket9023Widget(models.Model):
     62    name = models.CharField(max_length=10)
    6163
     64class Ticket9023Sprocket(models.Model):
     65    name = models.CharField(max_length=10)
     66    w = models.OneToOneField(Ticket9023Widget, null=True, blank=True,
     67        related_name='sprocket')
     68
    6269__test__ = {'API_TESTS': """
    6370(NOTE: Part of the regression test here is merely parsing the model
    6471declaration. The verbose_name, in particular, did not always work.)
     
    146153>>> b.save()
    147154>>> BrokenUnicodeMethod.objects.all()
    148155[<BrokenUnicodeMethod: [Bad Unicode data]>]
    149 
    150156"""}
    151157
    152158if settings.DATABASE_ENGINE not in ("mysql", "oracle"):
     
    1671731
    168174
    169175"""
    170 
Back to Top