Ticket #16128: 16128.patch

File 16128.patch, 2.3 KB (added by Aymeric Augustin, 13 years ago)
  • modeltests/proxy_models/tests.py

     
    1010from models import MyPersonProxy, Abstract, OtherPerson, User, UserProxy
    1111from models import UserProxyProxy, Country, State, StateProxy, TrackerUser
    1212from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug
    13 from models import ProxyBug, ProxyImprovement
     13from models import Issue, IssueWithProxy, ProxyBug, ProxyImprovement
    1414
    1515class ProxyModelTests(TestCase):
    1616    def test_same_manager_queries(self):
     
    312312        management.call_command('loaddata', 'mypeople.json', verbosity=0, commit=False)
    313313        p = MyPerson.objects.get(pk=100)
    314314        self.assertEqual(p.name, 'Elvis Presley')
     315
     316    def test_delete_cascade_to_proxy_objects(self):
     317        """
     318        Test that delete() cascades to proxy objects. Regression for #16128.
     319        """
     320        # delete with a foreign key on a regular model
     321        joe = TrackerUser.objects.create(name='Regular Joe', status='contrib')
     322        joe_s_issue = Issue.objects.create(summary='deep magic', assignee=joe)
     323        self.assertEqual(Issue.objects.count(), 1)
     324        joe.delete()
     325        self.assertEqual(Issue.objects.count(), 0)
     326        # delete with a foreign key on a proxy model
     327        joe = ProxyTrackerUser.objects.create(name='Proxy Joe', status='contrib')
     328        joe_s_issue = IssueWithProxy.objects.create(summary='deeper magic', assignee=joe)
     329        self.assertEqual(IssueWithProxy.objects.count(), 1)
     330        joe.delete()
     331        self.assertEqual(IssueWithProxy.objects.count(), 0)
  • modeltests/proxy_models/models.py

     
    131131    def __unicode__(self):
    132132        return ':'.join((self.__class__.__name__,self.summary,))
    133133
     134class IssueWithProxy(models.Model):
     135    summary = models.CharField(max_length=255)
     136    assignee = models.ForeignKey(ProxyTrackerUser)
     137
     138
    134139class Bug(Issue):
    135140    version = models.CharField(max_length=50)
    136141    reporter = models.ForeignKey(BaseUser)
Back to Top