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 (
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)
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)
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))
553
def test_getIncompleteJobsForArchive_finds_jobs_in_right_archive(self):
554
# getIncompleteJobsForArchive should return all the jobs in an
556
target1 = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
557
target2 = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
558
job_source = getUtility(IPlainPackageCopyJobSource)
560
self.makePPAJob(target_archive=target1)
561
for counter in xrange(2)]
562
self.makePPAJob(target2)
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)
568
def test_getIncompleteJobsForArchive_finds_failed_and_running_jobs(self):
569
# getIncompleteJobsForArchive should return only waiting, failed
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
577
job_source = getUtility(IPlainPackageCopyJobSource)
578
found_jobs = job_source.getIncompleteJobsForArchive(ppa)
579
found_statuses = [job.status for job in found_jobs]
581
[JobStatus.WAITING, JobStatus.RUNNING, JobStatus.FAILED],
582
MatchesSetwise(*(map(Equals, found_statuses))))
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.