~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/tests/test_packagecopyjob.py

[rs=buildbot-poller] automatic merge from stable. Revisions: 13831,
        13832, 13833, 13834, 13835 included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from storm.store import Store
9
9
from testtools.content import text_content
10
10
from testtools.matchers import MatchesStructure
 
11
from textwrap import dedent
11
12
import transaction
12
13
from zope.component import getUtility
13
14
from zope.security.interfaces import Unauthorized
21
22
    LaunchpadZopelessLayer,
22
23
    ZopelessDatabaseLayer,
23
24
    )
 
25
from lp.bugs.interfaces.bugtask import BugTaskStatus
24
26
from lp.registry.interfaces.pocket import PackagePublishingPocket
25
27
from lp.registry.interfaces.series import SeriesStatus
26
28
from lp.registry.model.distroseriesdifferencecomment import (
919
921
            "Nancy Requester <requester@example.com>",
920
922
            emails[1]['From'])
921
923
 
 
924
    def test_copying_closes_bugs(self):
 
925
        # Copying a package into a primary archive should close any bugs
 
926
        # mentioned in its changelog for versions added since the most
 
927
        # recently published version in the target.
 
928
 
 
929
        # Firstly, lots of boring set up.
 
930
        publisher = SoyuzTestPublisher()
 
931
        publisher.prepareBreezyAutotest()
 
932
        distroseries = publisher.breezy_autotest
 
933
        target_archive = self.factory.makeArchive(
 
934
            distroseries.distribution, purpose=ArchivePurpose.PRIMARY)
 
935
        source_archive = self.factory.makeArchive()
 
936
        bug280 = self.factory.makeBug()
 
937
        bug281 = self.factory.makeBug()
 
938
        bug282 = self.factory.makeBug()
 
939
 
 
940
        # Publish a package in the source archive and give it a changelog
 
941
        # entry that closes a bug.
 
942
        source_pub = self.factory.makeSourcePackagePublishingHistory(
 
943
            distroseries=distroseries, sourcepackagename="libc",
 
944
            version="2.8-2", status=PackagePublishingStatus.PUBLISHED,
 
945
            archive=source_archive)
 
946
        spr = removeSecurityProxy(source_pub).sourcepackagerelease
 
947
        changelog = dedent("""\
 
948
            libc (2.8-2) unstable; urgency=low
 
949
 
 
950
              * closes: %s
 
951
 
 
952
             -- Foo Bar <foo@example.com>  Tue, 01 Jan 1970 01:50:41 +0000
 
953
 
 
954
            libc (2.8-1) unstable; urgency=low
 
955
 
 
956
              * closes: %s
 
957
 
 
958
             -- Foo Bar <foo@example.com>  Tue, 01 Jan 1970 01:50:41 +0000
 
959
 
 
960
            libc (2.8-0) unstable; urgency=low
 
961
 
 
962
              * closes: %s
 
963
 
 
964
             -- Foo Bar <foo@example.com>  Tue, 01 Jan 1970 01:50:41 +0000
 
965
            """ % (bug282.id, bug281.id, bug280.id))
 
966
        spr.changelog = self.factory.makeLibraryFileAlias(content=changelog)
 
967
        spr.changelog_entry = "dummy"
 
968
        self.layer.txn.commit()  # Librarian.
 
969
        bugtask280 = self.factory.makeBugTask(
 
970
            target=spr.sourcepackage, bug=bug280)
 
971
        bugtask281 = self.factory.makeBugTask(
 
972
            target=spr.sourcepackage, bug=bug281)
 
973
        bugtask282 = self.factory.makeBugTask(
 
974
            target=spr.sourcepackage, bug=bug282)
 
975
 
 
976
        # Now put the same named package in the target archive at the
 
977
        # oldest version in the changelog.
 
978
        publisher.getPubSource(
 
979
            distroseries=distroseries, sourcename="libc",
 
980
            version="2.8-0", status=PackagePublishingStatus.PUBLISHED,
 
981
            archive=target_archive)
 
982
 
 
983
        # Run the copy job.
 
984
        source = getUtility(IPlainPackageCopyJobSource)
 
985
        requester = self.factory.makePerson()
 
986
        with person_logged_in(target_archive.owner):
 
987
            target_archive.newComponentUploader(requester, "main")
 
988
        job = source.create(
 
989
            package_name="libc",
 
990
            package_version="2.8-2",
 
991
            source_archive=source_archive,
 
992
            target_archive=target_archive,
 
993
            target_distroseries=distroseries,
 
994
            target_pocket=PackagePublishingPocket.RELEASE,
 
995
            include_binaries=False,
 
996
            requester=requester)
 
997
        self.runJob(job)
 
998
 
 
999
        # All the bugs apart from the one for 2.8-0 should be fixed.
 
1000
        self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask282.status)
 
1001
        self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask281.status)
 
1002
        self.assertEqual(BugTaskStatus.NEW, bugtask280.status)
 
1003
 
922
1004
    def test_findMatchingDSDs_matches_all_DSDs_for_job(self):
923
1005
        # findMatchingDSDs finds matching DSDs for any of the packages
924
1006
        # in the job.