Ticket #14896: 14896-test.diff

File 14896-test.diff, 2.2 KB (added by Karen Tracey, 14 years ago)

Test that demonstrates the problem, fails on trunk, passes on 1.2.X

  • tests/regressiontests/delete_regress/tests.py

     
    44from django.db import backend, connection, transaction, DEFAULT_DB_ALIAS
    55from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
    66
    7 from models import Book, Award, AwardNote, Person, Child, Toy, PlayedWith, PlayedWithNote
     7from models import (Book, Award, AwardNote, Person, Child, Toy, PlayedWith,
     8    PlayedWithNote, Contact, Email, Researcher)
    89
    910
    1011# Can't run this test under SQLite, because you can't
     
    6263        transaction.commit()
    6364        self.assertEqual(1, Book.objects.count())
    6465
    65 class DeleteCascadeTests(TestCase):
     66class DeleteCascadeTests(TransactionTestCase):
    6667    def test_generic_relation_cascade(self):
    6768        """
    6869        Test that Django cascades deletes through generic-related
     
    108109        # first two asserts just sanity checks, this is the kicker:
    109110        self.assertEquals(PlayedWithNote.objects.count(), 0)
    110111
     112    def test_inheritance(self):
     113        r = Researcher.objects.create()
     114        email = Email.objects.create(
     115            label="office-email", email_address="carl@science.edu"
     116        )
     117        r.contacts.add(email)
     118
     119        email.delete()
     120
    111121class LargeDeleteTests(TestCase):
    112122    def test_large_deletes(self):
    113123        "Regression for #13309 -- if the number of objects > chunk size, deletion still occurs"
  • tests/regressiontests/delete_regress/models.py

     
    3535class PlayedWithNote(models.Model):
    3636    played = models.ForeignKey(PlayedWith)
    3737    note = models.TextField()
     38
     39class Contact(models.Model):
     40    label = models.CharField(max_length=100)
     41
     42class Email(Contact):
     43    email_address = models.EmailField(max_length=100)
     44
     45class Researcher(models.Model):
     46    contacts = models.ManyToManyField(Contact, related_name="research_contacts")
Back to Top