~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/scripts/tests/test_queue.py

[r=julian-edwards][bug=800641] Ensure that the queue tool can set
        overrides on package copy jobs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    CommandRunnerError,
63
63
    name_queue_map,
64
64
    QueueAction,
 
65
    QueueActionOverride
65
66
    )
66
67
from lp.testing import (
67
68
    celebrity_logged_in,
938
939
 
939
940
    layer = LaunchpadZopelessLayer
940
941
 
941
 
    def makeQueueAction(self, package_upload, distroseries=None):
 
942
    def makeQueueAction(self, package_upload, distroseries=None,
 
943
                        component=None, section=None,
 
944
                        action_type=QueueAction):
942
945
        """Create a `QueueAction` for use with a `PackageUpload`.
943
946
 
944
947
        The action's `display` method is set to a `FakeMethod`.
945
948
        """
946
949
        if distroseries is None:
947
950
            distroseries = self.factory.makeDistroSeries(
948
 
                status=SeriesStatus.CURRENT)
 
951
                status=SeriesStatus.CURRENT,
 
952
                name="distroseriestestingpcjs")
949
953
        distro = distroseries.distribution
950
954
        if package_upload is None:
951
955
            package_upload = self.factory.makePackageUpload(
952
956
                distroseries=distroseries, archive=distro.main_archive)
953
 
        component = self.factory.makeComponent()
954
 
        section = self.factory.makeSection()
955
 
        suite = "%s-%s" % (distroseries.name, "release")
956
 
        queue = None
 
957
        if component is None:
 
958
            component = self.factory.makeComponent()
 
959
        if section is None:
 
960
            section = self.factory.makeSection()
 
961
        queue = PackageUploadStatus.NEW
957
962
        priority_name = "STANDARD"
958
963
        display = FakeMethod()
959
964
        terms = ['*']
960
 
        return QueueAction(
961
 
            distro.name, suite, queue, terms, component.name,
 
965
        return action_type(
 
966
            distro.name, distroseries.name, queue, terms, component.name,
962
967
            section.name, priority_name, display)
963
968
 
 
969
    def makeQueueActionOverride(self, package_upload, component, section,
 
970
                                distroseries=None):
 
971
        return self.makeQueueAction(
 
972
            package_upload, distroseries, component, section,
 
973
            action_type=QueueActionOverride)
 
974
 
964
975
    def parseUploadSummaryLine(self, output_line):
965
976
        """Parse an output line from `QueueAction.displayItem`.
966
977
 
1029
1040
        self.assertThat(upload.displayname, StartsWith(name))
1030
1041
        self.assertThat(upload.package_version, StartsWith(version))
1031
1042
 
 
1043
    def test_override_works_with_PackageCopyJob(self):
 
1044
        # "Sync" PackageUploads can be overridden just like sources,
 
1045
        # test that here.
 
1046
        new_component = self.factory.makeComponent()
 
1047
        new_section = self.factory.makeSection()
 
1048
        pocket = PackagePublishingPocket.RELEASE
 
1049
        upload = self.factory.makeCopyJobPackageUpload(target_pocket=pocket)
 
1050
        action = self.makeQueueActionOverride(
 
1051
            upload, new_component, new_section,
 
1052
            distroseries=upload.distroseries)
 
1053
        # Patch this out because it uses data we don't have in the test;
 
1054
        # it's unnecessary anyway.
 
1055
        self.patch(action, "displayTitle", FakeMethod)
 
1056
        action.terms = ["source", str(upload.id)]
 
1057
        self.layer.txn.commit()
 
1058
        self.layer.switchDbUser(config.uploadqueue.dbuser)
 
1059
        action.initialize()
 
1060
        action.run()
 
1061
 
 
1062
        # Overriding a sync means putting the overrides in the job itself.
 
1063
        self.assertEqual(
 
1064
            new_component.name, upload.package_copy_job.component_name)
 
1065
        self.assertEqual(
 
1066
            new_section.name, upload.package_copy_job.section_name)
 
1067
 
1032
1068
    def test_makeTag_returns_S_for_source_upload(self):
1033
1069
        upload = self.factory.makeSourcePackageUpload()
1034
1070
        self.assertEqual('S-', self.makeQueueAction(upload)._makeTag(upload))