~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Julian Edwards
  • Date: 2011-12-22 15:25:55 UTC
  • mto: This revision was merged to the branch mainline in revision 14591.
  • Revision ID: julian.edwards@canonical.com-20111222152555-fcu2l7ywmdb3ipjm
Add PackageCopyJob.getIncompleteJobsForArchive() method in preparation for showing them on the PPA page

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from storm.store import Store
10
10
from testtools.content import text_content
11
 
from testtools.matchers import MatchesStructure
 
11
from testtools.matchers import (
 
12
    Equals,
 
13
    MatchesSetwise,
 
14
    MatchesStructure,
 
15
    )
12
16
import transaction
13
17
from zope.component import getUtility
14
18
from zope.security.interfaces import Unauthorized
96
100
            target_distroseries, target_pocket, requester=requester,
97
101
            package_version=dsd.parent_source_version, **kwargs)
98
102
 
 
103
    def makePPAJob(self, source_archive=None, target_archive=None, **kwargs):
 
104
        if source_archive is None:
 
105
            source_archive = self.factory.makeArchive(
 
106
                purpose=ArchivePurpose.PPA)
 
107
        if target_archive is None:
 
108
            target_archive = self.factory.makeArchive(
 
109
                purpose=ArchivePurpose.PPA)
 
110
        source_name = self.factory.getUniqueString('src-name')
 
111
        target_series = self.factory.makeDistroSeries()
 
112
        target_pocket = self.factory.getAnyPocket()
 
113
        requester = self.factory.makePerson()
 
114
        return getUtility(IPlainPackageCopyJobSource).create(
 
115
            source_name, source_archive, target_archive,
 
116
            target_series, target_pocket, requester=requester,
 
117
            package_version="1.0", **kwargs)
 
118
 
99
119
    def runJob(self, job):
100
120
        """Helper to switch to the right DB user and run the job."""
101
121
        # We are basically mimicking the job runner here.
530
550
        self.assertEqual(
531
551
            {}, job_source.getPendingJobsPerPackage(dsd.derived_series))
532
552
 
 
553
    def test_getIncompleteJobsForArchive_finds_jobs_in_right_archive(self):
 
554
        # getIncompleteJobsForArchive should return all the jobs in an
 
555
        # specified archive.
 
556
        target1 = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
 
557
        target2 = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
 
558
        job_source = getUtility(IPlainPackageCopyJobSource)
 
559
        target1_jobs = [
 
560
            self.makePPAJob(target_archive=target1)
 
561
            for counter in xrange(2)]
 
562
        self.makePPAJob(target2)
 
563
 
 
564
        pending_jobs = list(job_source.getIncompleteJobsForArchive(target1))
 
565
        has_both_jobs = MatchesSetwise(*(map(Equals, target1_jobs)))
 
566
        self.assertThat(pending_jobs, has_both_jobs)
 
567
 
 
568
    def test_getIncompleteJobsForArchive_finds_failed_and_running_jobs(self):
 
569
        # getIncompleteJobsForArchive should return only waiting, failed
 
570
        # and running jobs.
 
571
        jobs = []
 
572
        ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
 
573
        for status in JobStatus.items:
 
574
            job = self.makePPAJob(target_archive=ppa)
 
575
            removeSecurityProxy(job).job._status = status
 
576
 
 
577
        job_source = getUtility(IPlainPackageCopyJobSource)
 
578
        found_jobs = job_source.getIncompleteJobsForArchive(ppa)
 
579
        found_statuses = [job.status for job in found_jobs]
 
580
        self.assertThat(
 
581
            [JobStatus.WAITING, JobStatus.RUNNING, JobStatus.FAILED],
 
582
            MatchesSetwise(*(map(Equals, found_statuses))))
 
583
 
533
584
    def test_copying_to_main_archive_ancestry_overrides(self):
534
585
        # The job will complete right away for auto-approved copies to a
535
586
        # main archive and apply any ancestry overrides.