~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/tests/test_garbo.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-04 16:24:40 UTC
  • mfrom: (8758.7.4 garbo-bulk-pruner)
  • Revision ID: launchpad@pqm.canonical.com-20120104162440-jy34l21i0bcirh1z
[r=wgrant][no-qa] Trash EmailAddress and Account records not linked
        to a Person.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Test the database garbage collector."""
51
51
    )
52
52
from lp.code.model.codeimportevent import CodeImportEvent
53
53
from lp.code.model.codeimportresult import CodeImportResult
54
 
from lp.registry.interfaces.person import (
55
 
    IPersonSet,
56
 
    PersonCreationRationale,
57
 
    )
 
54
from lp.registry.interfaces.person import IPersonSet
58
55
from lp.scripts.garbo import (
59
56
    AntiqueSessionPruner,
60
57
    BulkPruner,
626
623
        LaunchpadZopelessLayer.switchDbUser('testadmin')
627
624
        rev1 = self.factory.makeRevision('Author 1 <author-1@Example.Org>')
628
625
        rev2 = self.factory.makeRevision('Author 2 <author-2@Example.Org>')
629
 
        rev3 = self.factory.makeRevision('Author 3 <author-3@Example.Org>')
630
626
 
631
627
        person1 = self.factory.makePerson(email='Author-1@example.org')
632
628
        person2 = self.factory.makePerson(
633
629
            email='Author-2@example.org',
634
630
            email_address_status=EmailAddressStatus.NEW)
635
 
        account3 = self.factory.makeAccount(
636
 
            'Author 3', 'Author-3@example.org')
637
631
 
638
632
        self.assertEqual(rev1.revision_author.person, None)
639
633
        self.assertEqual(rev2.revision_author.person, None)
640
 
        self.assertEqual(rev3.revision_author.person, None)
641
634
 
642
635
        self.runDaily()
643
636
 
646
639
        LaunchpadZopelessLayer.switchDbUser('testadmin')
647
640
        self.assertEqual(rev1.revision_author.person, person1)
648
641
        self.assertEqual(rev2.revision_author.person, None)
649
 
        self.assertEqual(rev3.revision_author.person, None)
650
642
 
651
643
        # Validating an email address creates a linkage.
652
644
        person2.validateAndEnsurePreferredEmail(person2.guessedemails[0])
656
648
        LaunchpadZopelessLayer.switchDbUser('testadmin')
657
649
        self.assertEqual(rev2.revision_author.person, person2)
658
650
 
659
 
        # Creating a person for an existing account creates a linkage.
660
 
        person3 = account3.createPerson(PersonCreationRationale.UNKNOWN)
661
 
        self.assertEqual(rev3.revision_author.person, None)
662
 
 
663
 
        self.runDaily()
664
 
        LaunchpadZopelessLayer.switchDbUser('testadmin')
665
 
        self.assertEqual(rev3.revision_author.person, person3)
666
 
 
667
651
    def test_HWSubmissionEmailLinker(self):
668
652
        LaunchpadZopelessLayer.switchDbUser('testadmin')
669
653
        sub1 = self.factory.makeHWSubmission(
670
654
            emailaddress='author-1@Example.Org')
671
655
        sub2 = self.factory.makeHWSubmission(
672
656
            emailaddress='author-2@Example.Org')
673
 
        sub3 = self.factory.makeHWSubmission(
674
 
            emailaddress='author-3@Example.Org')
675
657
 
676
658
        person1 = self.factory.makePerson(email='Author-1@example.org')
677
659
        person2 = self.factory.makePerson(
678
660
            email='Author-2@example.org',
679
661
            email_address_status=EmailAddressStatus.NEW)
680
 
        account3 = self.factory.makeAccount(
681
 
            'Author 3', 'Author-3@example.org')
682
662
 
683
663
        self.assertEqual(sub1.owner, None)
684
664
        self.assertEqual(sub2.owner, None)
685
 
        self.assertEqual(sub3.owner, None)
686
665
 
687
666
        self.runDaily()
688
667
 
691
670
        LaunchpadZopelessLayer.switchDbUser('testadmin')
692
671
        self.assertEqual(sub1.owner, person1)
693
672
        self.assertEqual(sub2.owner, None)
694
 
        self.assertEqual(sub3.owner, None)
695
673
 
696
674
        # Validating an email address creates a linkage.
697
675
        person2.validateAndEnsurePreferredEmail(person2.guessedemails[0])
701
679
        LaunchpadZopelessLayer.switchDbUser('testadmin')
702
680
        self.assertEqual(sub2.owner, person2)
703
681
 
704
 
        # Creating a person for an existing account creates a linkage.
705
 
        person3 = account3.createPerson(PersonCreationRationale.UNKNOWN)
706
 
        self.assertEqual(sub3.owner, None)
707
 
 
708
 
        self.runDaily()
709
 
        LaunchpadZopelessLayer.switchDbUser('testadmin')
710
 
        self.assertEqual(sub3.owner, person3)
711
 
 
712
682
    def test_PersonPruner(self):
713
683
        personset = getUtility(IPersonSet)
714
684
        # Switch the DB user because the garbo_daily user isn't allowed to