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).
4
4
"""Test the database garbage collector."""
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 (
56
PersonCreationRationale,
54
from lp.registry.interfaces.person import IPersonSet
58
55
from lp.scripts.garbo import (
59
56
AntiqueSessionPruner,
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>')
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')
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)
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)
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)
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)
664
LaunchpadZopelessLayer.switchDbUser('testadmin')
665
self.assertEqual(rev3.revision_author.person, person3)
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')
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')
683
663
self.assertEqual(sub1.owner, None)
684
664
self.assertEqual(sub2.owner, None)
685
self.assertEqual(sub3.owner, None)
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)
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)
704
# Creating a person for an existing account creates a linkage.
705
person3 = account3.createPerson(PersonCreationRationale.UNKNOWN)
706
self.assertEqual(sub3.owner, None)
709
LaunchpadZopelessLayer.switchDbUser('testadmin')
710
self.assertEqual(sub3.owner, person3)
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