def create_multiple_jobs(derived_series, parent_series): """Create `DistroSeriesDifferenceJob`s between parent and derived series. :param derived_series: A `DistroSeries` that is assumed to be derived from another one. :param parent_series: A `DistroSeries` that is a parent of `derived_series`. :return: A list of newly-created `DistributionJob` ids. """ store = IStore(SourcePackagePublishingHistory) spn_ids = store.find( SourcePackagePublishingHistory.sourcepackagenameID, SourcePackagePublishingHistory.distroseries == derived_series.id, SourcePackagePublishingHistory.status.is_in(active_publishing_status)) spn_ids = list(spn_ids) if len(spn_ids) == 0: return [] job_ids = Job.createMultiple(store, len(spn_ids)) return bulk.create( (DistributionJob.distribution, DistributionJob.distroseries, DistributionJob.job_type, DistributionJob.job_id, DistributionJob.metadata), [(derived_series.distribution, derived_series, DistributionJobType.DISTROSERIESDIFFERENCE, job_id, make_metadata(spn_id, parent_series.id)) for job_id, spn_id in zip(job_ids, spn_ids)], get_primary_keys=True)
def createMultiple(cls, copy_tasks, requester, copy_policy=PackageCopyPolicy.INSECURE, include_binaries=False, sponsored=None, unembargo=False, auto_approve=False, silent=False): """See `IPlainPackageCopyJobSource`.""" store = IMasterStore(Job) job_ids = Job.createMultiple(store, len(copy_tasks), requester) job_contents = [ cls._composeJobInsertionTuple(copy_policy, include_binaries, job_id, task, sponsored, unembargo, auto_approve, silent) for job_id, task in zip(job_ids, copy_tasks) ] return bulk.create( (PackageCopyJob.job_type, PackageCopyJob.target_distroseries, PackageCopyJob.copy_policy, PackageCopyJob.source_archive, PackageCopyJob.target_archive, PackageCopyJob.package_name, PackageCopyJob.job_id, PackageCopyJob.metadata), job_contents, get_primary_keys=True)
def createMultiple( cls, copy_tasks, requester, copy_policy=PackageCopyPolicy.INSECURE, include_binaries=False, sponsored=None, unembargo=False, auto_approve=False, ): """See `IPlainPackageCopyJobSource`.""" store = IMasterStore(Job) job_ids = Job.createMultiple(store, len(copy_tasks), requester) job_contents = [ cls._composeJobInsertionTuple( copy_policy, include_binaries, job_id, task, sponsored, unembargo, auto_approve ) for job_id, task in zip(job_ids, copy_tasks) ] return bulk.create( ( PackageCopyJob.job_type, PackageCopyJob.target_distroseries, PackageCopyJob.copy_policy, PackageCopyJob.source_archive, PackageCopyJob.target_archive, PackageCopyJob.package_name, PackageCopyJob.job_id, PackageCopyJob.metadata, ), job_contents, get_primary_keys=True, )
def test_createMultiple_defaults_requester_to_None(self): store = IStore(Job) job = store.get(Job, Job.createMultiple(store, 1)[0]) self.assertEqual(None, job.requester)
def test_createMultiple_sets_requester(self): store = IStore(Job) requester = self.factory.makePerson() job = store.get(Job, Job.createMultiple(store, 1, requester)[0]) self.assertEqual(requester, job.requester)
def test_createMultiple_sets_status_to_WAITING(self): store = IStore(Job) job = store.get(Job, Job.createMultiple(store, 1)[0]) self.assertEqual(JobStatus.WAITING, job.status)
def test_createMultiple_returns_valid_job_ids(self): job_ids = list(Job.createMultiple(IStore(Job), 3)) store = IStore(Job) for job_id in job_ids: self.assertIsNot(None, store.get(Job, job_id))
def test_createMultiple_creates_requested_number_of_jobs(self): job_ids = list(Job.createMultiple(IStore(Job), 3)) self.assertEqual(3, len(job_ids)) self.assertEqual(3, len(set(job_ids)))