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,
33
from lp.testing.matchers import HasQueryCount
31
36
class TestDominator(TestNativePublishingBase):
280
285
bpph.binarypackagerelease.version,
281
286
GeneralizedPublication(is_source=False).getPackageVersion(bpph))
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]))
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]))
283
301
def test_compare_sorts_versions(self):
480
498
self.assertEqual(
481
499
[spr, spr, None], [pub.supersededby for pub in pubs])
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)))
483
511
def test_dominatePackage_advanced_scenario(self):
484
512
# Put dominatePackage through its paces with complex combined
571
599
self.assertEqual(
572
600
expected_supersededby, [pub.supersededby for pub in pubs])
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
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])
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)
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)
671
699
status=PackagePublishingStatus.PUBLISHED)
672
700
for counter in xrange(2)]
673
701
dominator = self.makeDominator(spphs)
674
[(name, publications)] = dominator.findPublishedSourcePackageNames(
676
self.assertEqual(len(spphs), publications)
702
self.assertContentEqual(
703
[(spr.sourcepackagename.name, len(spphs))],
704
dominator.findPublishedSourcePackageNames(series, pocket))
678
706
def test_findPublishedSourcePackageNames_counts_no_other_state(self):
679
707
series = self.factory.makeDistroSeries()
686
714
for status in PackagePublishingStatus.items]
687
715
dominator = self.makeDominator(spphs)
688
[(name, publications)] = dominator.findPublishedSourcePackageNames(
690
self.assertEqual(1, publications)
716
self.assertContentEqual(
717
[(spr.sourcepackagename.name, 1)],
718
dominator.findPublishedSourcePackageNames(series, pocket))
692
720
def test_findPublishedSPPHs_finds_published_SPPH(self):
693
721
spph = self.factory.makeSourcePackagePublishingHistory(