~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/test_person.py

  • Committer: Stuart Bishop
  • Date: 2011-09-28 12:49:24 UTC
  • mfrom: (9893.10.1 trivial)
  • mto: This revision was merged to the branch mainline in revision 14178.
  • Revision ID: stuart.bishop@canonical.com-20110928124924-m5a22fymqghw6c5i
Merged trivial into distinct-db-users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    PersonVisibility,
62
62
    )
63
63
from lp.registry.interfaces.personnotification import IPersonNotificationSet
 
64
from lp.registry.interfaces.pocket import PackagePublishingPocket
64
65
from lp.registry.interfaces.product import IProductSet
65
66
from lp.registry.model.karma import (
66
67
    KarmaCategory,
437
438
            list(user.getBugSubscriberPackages())
438
439
        self.assertThat(recorder, HasQueryCount(Equals(1)))
439
440
 
 
441
    def createCopiedPackage(self, spph, copier, dest_distroseries=None,
 
442
                            dest_archive=None):
 
443
        if dest_distroseries is None:
 
444
            dest_distroseries = self.factory.makeDistroSeries()
 
445
        if dest_archive is None:
 
446
            dest_archive = dest_distroseries.main_archive
 
447
        return spph.copyTo(
 
448
            dest_distroseries, creator=copier,
 
449
            pocket=PackagePublishingPocket.UPDATES,
 
450
            archive=dest_archive)
 
451
 
 
452
    def test_getLatestSynchronisedPublishings_most_recent_first(self):
 
453
        # getLatestSynchronisedPublishings returns the latest copies sorted
 
454
        # by most recent first.
 
455
        spph = self.factory.makeSourcePackagePublishingHistory()
 
456
        copier = self.factory.makePerson()
 
457
        copied_spph1 = self.createCopiedPackage(spph, copier)
 
458
        copied_spph2 = self.createCopiedPackage(spph, copier)
 
459
        synchronised_spphs = copier.getLatestSynchronisedPublishings()
 
460
 
 
461
        self.assertContentEqual(
 
462
            [copied_spph2, copied_spph1],
 
463
            synchronised_spphs)
 
464
 
 
465
    def test_getLatestSynchronisedPublishings_other_creator(self):
 
466
        spph = self.factory.makeSourcePackagePublishingHistory()
 
467
        copier = self.factory.makePerson()
 
468
        self.createCopiedPackage(spph, copier)
 
469
        someone_else = self.factory.makePerson()
 
470
        synchronised_spphs = someone_else.getLatestSynchronisedPublishings()
 
471
 
 
472
        self.assertEqual(
 
473
            0,
 
474
            synchronised_spphs.count())
 
475
 
 
476
    def test_getLatestSynchronisedPublishings_latest(self):
 
477
        # getLatestSynchronisedPublishings returns only the latest copy of
 
478
        # a package in a distroseries
 
479
        spph = self.factory.makeSourcePackagePublishingHistory()
 
480
        copier = self.factory.makePerson()
 
481
        dest_distroseries = self.factory.makeDistroSeries()
 
482
        self.createCopiedPackage(
 
483
            spph, copier, dest_distroseries)
 
484
        copied_spph2 = self.createCopiedPackage(
 
485
            spph, copier, dest_distroseries)
 
486
        synchronised_spphs = copier.getLatestSynchronisedPublishings()
 
487
 
 
488
        self.assertContentEqual(
 
489
            [copied_spph2],
 
490
            synchronised_spphs)
 
491
 
 
492
    def test_getLatestSynchronisedPublishings_cross_archive_copies(self):
 
493
        # getLatestSynchronisedPublishings returns only the copies copied
 
494
        # cross archive.
 
495
        spph = self.factory.makeSourcePackagePublishingHistory()
 
496
        copier = self.factory.makePerson()
 
497
        dest_distroseries2 = self.factory.makeDistroSeries(
 
498
            distribution=spph.distroseries.distribution)
 
499
        self.createCopiedPackage(
 
500
            spph, copier, dest_distroseries2)
 
501
        synchronised_spphs = copier.getLatestSynchronisedPublishings()
 
502
 
 
503
        self.assertEqual(
 
504
            0,
 
505
            synchronised_spphs.count())
 
506
 
 
507
    def test_getLatestSynchronisedPublishings_main_archive(self):
 
508
        # getLatestSynchronisedPublishings returns only the copies copied in
 
509
        # a primary archive (as opposed to a ppa).
 
510
        spph = self.factory.makeSourcePackagePublishingHistory()
 
511
        copier = self.factory.makePerson()
 
512
        dest_distroseries = self.factory.makeDistroSeries()
 
513
        ppa = self.factory.makeArchive(
 
514
            distribution=dest_distroseries.distribution)
 
515
        self.createCopiedPackage(
 
516
            spph, copier, dest_distroseries, ppa)
 
517
        synchronised_spphs = copier.getLatestSynchronisedPublishings()
 
518
 
 
519
        self.assertEqual(
 
520
            0,
 
521
            synchronised_spphs.count())
 
522
 
440
523
 
441
524
class TestPersonStates(TestCaseWithFactory):
442
525
 
1636
1719
                              super_team_member_person,
1637
1720
                              super_team_member_team]),
1638
1721
                         set(recipients))
 
1722
 
 
1723
    def test_get_recipients_team_with_disabled_owner_account(self):
 
1724
        """Mail is not sent to a team owner whose account is disabled.
 
1725
 
 
1726
        See <https://bugs.launchpad.net/launchpad/+bug/855150>
 
1727
        """
 
1728
        owner = self.factory.makePerson(email='foo@bar.com')
 
1729
        team = self.factory.makeTeam(owner)
 
1730
        owner.account.status = AccountStatus.DEACTIVATED
 
1731
        self.assertContentEqual([], get_recipients(team))
 
1732
 
 
1733
    def test_get_recipients_team_with_disabled_member_account(self):
 
1734
        """Mail is not sent to a team member whose account is disabled.
 
1735
 
 
1736
        See <https://bugs.launchpad.net/launchpad/+bug/855150>
 
1737
        """
 
1738
        person = self.factory.makePerson(email='foo@bar.com')
 
1739
        person.account.status = AccountStatus.DEACTIVATED
 
1740
        team = self.factory.makeTeam(members=[person])
 
1741
        self.assertContentEqual([team.teamowner], get_recipients(team))
 
1742
 
 
1743
    def test_get_recipients_team_with_nested_disabled_member_account(self):
 
1744
        """Mail is not sent to transitive team member with disabled account.
 
1745
 
 
1746
        See <https://bugs.launchpad.net/launchpad/+bug/855150>
 
1747
        """
 
1748
        person = self.factory.makePerson(email='foo@bar.com')
 
1749
        person.account.status = AccountStatus.DEACTIVATED
 
1750
        team1 = self.factory.makeTeam(members=[person])
 
1751
        team2 = self.factory.makeTeam(members=[team1])
 
1752
        self.assertContentEqual(
 
1753
            [team2.teamowner],
 
1754
            get_recipients(team2))