~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/archivepublisher/tests/test_dominator.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-26 15:32:36 UTC
  • mfrom: (14017.3.5 post-857155)
  • Revision ID: launchpad@pqm.canonical.com-20110926153236-pdldzk96qfb71z51
[r=allenap][bug=857155] Bit more optimization and a renaming for Gina
 domination.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from operator import attrgetter
10
10
 
11
11
import apt_pkg
 
12
from testtools.matchers import LessThan
12
13
from zope.security.proxy import removeSecurityProxy
13
14
 
14
15
from canonical.database.sqlbase import flush_database_updates
25
26
from lp.soyuz.enums import PackagePublishingStatus
26
27
from lp.soyuz.interfaces.publishing import ISourcePackagePublishingHistory
27
28
from lp.soyuz.tests.test_publishing import TestNativePublishingBase
28
 
from lp.testing import TestCaseWithFactory
 
29
from lp.testing import (
 
30
    StormStatementRecorder,
 
31
    TestCaseWithFactory,
 
32
    )
 
33
from lp.testing.matchers import HasQueryCount
29
34
 
30
35
 
31
36
class TestDominator(TestNativePublishingBase):
280
285
            bpph.binarypackagerelease.version,
281
286
            GeneralizedPublication(is_source=False).getPackageVersion(bpph))
282
287
 
 
288
    def test_load_releases_loads_sourcepackagerelease(self):
 
289
        spph = self.factory.makeSourcePackagePublishingHistory()
 
290
        self.assertContentEqual(
 
291
            [spph.sourcepackagerelease],
 
292
            GeneralizedPublication(is_source=True).load_releases([spph]))
 
293
 
 
294
    def test_load_releases_loads_binarypackagerelease(self):
 
295
        bpph = self.factory.makeBinaryPackagePublishingHistory(
 
296
            binarypackagerelease=self.factory.makeBinaryPackageRelease())
 
297
        self.assertContentEqual(
 
298
            [bpph.binarypackagerelease],
 
299
            GeneralizedPublication(is_source=False).load_releases([bpph]))
 
300
 
283
301
    def test_compare_sorts_versions(self):
284
302
        versions = [
285
303
            '1.1v2',
480
498
        self.assertEqual(
481
499
            [spr, spr, None], [pub.supersededby for pub in pubs])
482
500
 
 
501
    def test_dominatePackage_is_efficient(self):
 
502
        # dominatePackage avoids issuing too many queries.
 
503
        versions = ["1.%s" % revision for revision in xrange(5)]
 
504
        pubs = make_spphs_for_versions(self.factory, versions)
 
505
        with StormStatementRecorder() as recorder:
 
506
            self.makeDominator(pubs).dominatePackage(
 
507
                pubs, versions[2:-1],
 
508
                GeneralizedPublication(True))
 
509
        self.assertThat(recorder, HasQueryCount(LessThan(5)))
 
510
 
483
511
    def test_dominatePackage_advanced_scenario(self):
484
512
        # Put dominatePackage through its paces with complex combined
485
513
        # data.
571
599
            self.assertEqual(
572
600
                expected_supersededby, [pub.supersededby for pub in pubs])
573
601
 
574
 
    def test_dominateRemovedSourceVersions_dominates_publications(self):
575
 
        # dominateRemovedSourceVersions finds the publications for a
576
 
        # package and calls dominatePackage on them.
 
602
    def test_dominateSourceVersions_dominates_publications(self):
 
603
        # dominateSourceVersions finds the publications for a package
 
604
        # and calls dominatePackage on them.
577
605
        pubs = make_spphs_for_versions(self.factory, ['0.1', '0.2', '0.3'])
578
606
        package_name = pubs[0].sourcepackagerelease.sourcepackagename.name
579
607
 
580
 
        self.makeDominator(pubs).dominateRemovedSourceVersions(
 
608
        self.makeDominator(pubs).dominateSourceVersions(
581
609
            pubs[0].distroseries, pubs[0].pocket, package_name, ['0.2'])
582
610
        self.assertEqual([
583
611
                PackagePublishingStatus.SUPERSEDED,
589
617
            [pubs[1].sourcepackagerelease, None, None],
590
618
            [pub.supersededby for pub in pubs])
591
619
 
592
 
    def test_dominateRemovedSourceVersions_ignores_other_pockets(self):
593
 
        # dominateRemovedSourceVersions ignores publications in other
594
 
        # pockets than the one specified.
 
620
    def test_dominateSourceVersions_ignores_other_pockets(self):
 
621
        # dominateSourceVersions ignores publications in other pockets
 
622
        # than the one specified.
595
623
        pubs = make_spphs_for_versions(self.factory, ['2.3', '2.4'])
596
624
        package_name = pubs[0].sourcepackagerelease.sourcepackagename.name
597
625
        removeSecurityProxy(pubs[0]).pocket = PackagePublishingPocket.UPDATES
598
626
        removeSecurityProxy(pubs[1]).pocket = PackagePublishingPocket.PROPOSED
599
 
        self.makeDominator(pubs).dominateRemovedSourceVersions(
 
627
        self.makeDominator(pubs).dominateSourceVersions(
600
628
            pubs[0].distroseries, pubs[0].pocket, package_name, ['2.3'])
601
629
        self.assertEqual(PackagePublishingStatus.PUBLISHED, pubs[1].status)
602
630
 
603
 
    def test_dominateRemovedSourceVersions_ignores_other_packages(self):
 
631
    def test_dominateSourceVersions_ignores_other_packages(self):
604
632
        pubs = make_spphs_for_versions(self.factory, ['1.0', '1.1'])
605
633
        other_package_name = self.factory.makeSourcePackageName().name
606
 
        self.makeDominator(pubs).dominateRemovedSourceVersions(
 
634
        self.makeDominator(pubs).dominateSourceVersions(
607
635
            pubs[0].distroseries, pubs[0].pocket, other_package_name, ['1.1'])
608
636
        self.assertEqual(PackagePublishingStatus.PUBLISHED, pubs[0].status)
609
637
 
671
699
                status=PackagePublishingStatus.PUBLISHED)
672
700
            for counter in xrange(2)]
673
701
        dominator = self.makeDominator(spphs)
674
 
        [(name, publications)] = dominator.findPublishedSourcePackageNames(
675
 
            series, pocket)
676
 
        self.assertEqual(len(spphs), publications)
 
702
        self.assertContentEqual(
 
703
            [(spr.sourcepackagename.name, len(spphs))],
 
704
            dominator.findPublishedSourcePackageNames(series, pocket))
677
705
 
678
706
    def test_findPublishedSourcePackageNames_counts_no_other_state(self):
679
707
        series = self.factory.makeDistroSeries()
685
713
                status=status)
686
714
            for status in PackagePublishingStatus.items]
687
715
        dominator = self.makeDominator(spphs)
688
 
        [(name, publications)] = dominator.findPublishedSourcePackageNames(
689
 
            series, pocket)
690
 
        self.assertEqual(1, publications)
 
716
        self.assertContentEqual(
 
717
            [(spr.sourcepackagename.name, 1)],
 
718
            dominator.findPublishedSourcePackageNames(series, pocket))
691
719
 
692
720
    def test_findPublishedSPPHs_finds_published_SPPH(self):
693
721
        spph = self.factory.makeSourcePackagePublishingHistory(