~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-07-15 11:34:12 UTC
  • mto: (13410.1.22 async-copying-part-2)
  • mto: This revision was merged to the branch mainline in revision 13458.
  • Revision ID: julian.edwards@canonical.com-20110715113412-xwq0yvyqq67eg44e
Create single packagecopyjobs with a requester.

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
        target_archive = dsd.derived_series.main_archive
93
93
        target_distroseries = dsd.derived_series
94
94
        target_pocket = self.factory.getAnyPocket()
 
95
        requester = self.factory.makePerson()
95
96
        return getUtility(IPlainPackageCopyJobSource).create(
96
97
            dsd.source_package_name.name, source_archive, target_archive,
97
 
            target_distroseries, target_pocket,
 
98
            target_distroseries, target_pocket, requester=requester,
98
99
            package_version=dsd.parent_source_version, **kwargs)
99
100
 
100
101
    def runJob(self, job):
122
123
        distroseries = self.factory.makeDistroSeries()
123
124
        archive1 = self.factory.makeArchive(distroseries.distribution)
124
125
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
126
        requester  = self.factory.makePerson()
125
127
        source = getUtility(IPlainPackageCopyJobSource)
126
128
        job = source.create(
127
129
            package_name="foo", source_archive=archive1,
128
130
            target_archive=archive2, target_distroseries=distroseries,
129
131
            target_pocket=PackagePublishingPocket.RELEASE,
130
132
            package_version="1.0-1", include_binaries=False,
131
 
            copy_policy=PackageCopyPolicy.MASS_SYNC)
 
133
            copy_policy=PackageCopyPolicy.MASS_SYNC,
 
134
            requester=requester)
132
135
        self.assertProvides(job, IPackageCopyJob)
133
136
        self.assertEquals(archive1.id, job.source_archive_id)
134
137
        self.assertEquals(archive1, job.source_archive)
140
143
        self.assertEqual("1.0-1", job.package_version)
141
144
        self.assertEquals(False, job.include_binaries)
142
145
        self.assertEquals(PackageCopyPolicy.MASS_SYNC, job.copy_policy)
 
146
        self.assertEqual(requester, job.requester)
143
147
 
144
148
    def test_createMultiple_creates_one_job_per_copy(self):
145
149
        mother = self.factory.makeDistroSeriesParent()
191
195
        archive1 = self.factory.makeArchive(distroseries.distribution)
192
196
        archive2 = self.factory.makeArchive(distroseries.distribution)
193
197
        source = getUtility(IPlainPackageCopyJobSource)
 
198
        requester = self.factory.makePerson()
194
199
        job = source.create(
195
200
            package_name="foo", source_archive=archive1,
196
201
            target_archive=archive2, target_distroseries=distroseries,
197
202
            target_pocket=PackagePublishingPocket.RELEASE,
198
 
            package_version="1.0-1", include_binaries=False)
 
203
            package_version="1.0-1", include_binaries=False,
 
204
            requester=requester)
199
205
        self.assertContentEqual([job], source.getActiveJobs(archive2))
200
206
 
201
207
    def test_getActiveJobs_gets_oldest_first(self):
249
255
        distroseries = self.factory.makeDistroSeries()
250
256
        archive1 = self.factory.makeArchive(distroseries.distribution)
251
257
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
258
        requester = self.factory.makePerson()
252
259
        job_source = getUtility(IPlainPackageCopyJobSource)
253
260
        job = job_source.create(
254
261
            package_name="foo", source_archive=archive1,
255
262
            target_archive=archive2, target_distroseries=distroseries,
256
263
            target_pocket=PackagePublishingPocket.RELEASE,
257
 
            package_version="1.0-1", include_binaries=False)
 
264
            package_version="1.0-1", include_binaries=False,
 
265
            requester=requester)
258
266
        naked_job = removeSecurityProxy(job)
259
267
        naked_job.reportFailure = FakeMethod()
260
268
 
268
276
        package = self.factory.makeSourcePackageName()
269
277
        archive1 = self.factory.makeArchive(distroseries.distribution)
270
278
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
279
        requester = self.factory.makePerson()
271
280
        source = getUtility(IPlainPackageCopyJobSource)
272
281
        job = source.create(
273
282
            package_name=package.name, source_archive=archive1,
274
283
            target_archive=archive2, target_distroseries=distroseries,
275
284
            target_pocket=PackagePublishingPocket.UPDATES,
276
 
            include_binaries=False, package_version='1.0')
 
285
            include_binaries=False, package_version='1.0',
 
286
            requester=requester)
277
287
 
278
288
        naked_job = removeSecurityProxy(job)
279
289
        naked_job.reportFailure = FakeMethod()
315
325
            archive=target_archive)
316
326
 
317
327
        source = getUtility(IPlainPackageCopyJobSource)
 
328
        requester = self.factory.makePerson()
318
329
        job = source.create(
319
330
            package_name="libc",
320
331
            source_archive=breezy_archive, target_archive=target_archive,
321
332
            target_distroseries=target_series,
322
333
            target_pocket=PackagePublishingPocket.RELEASE,
323
 
            package_version="2.8-1", include_binaries=False)
 
334
            package_version="2.8-1", include_binaries=False,
 
335
            requester=requester)
324
336
        self.assertEqual("libc", job.package_name)
325
337
        self.assertEqual("2.8-1", job.package_version)
326
338
 
348
360
        distroseries = self.factory.makeDistroSeries()
349
361
        archive1 = self.factory.makeArchive(distroseries.distribution)
350
362
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
363
        requester = self.factory.makePerson()
351
364
        source = getUtility(IPlainPackageCopyJobSource)
352
365
        job = source.create(
353
366
            package_name="foo", source_archive=archive1,
354
367
            target_archive=archive2, target_distroseries=distroseries,
355
368
            target_pocket=PackagePublishingPocket.RELEASE,
356
 
            package_version="1.0-1", include_binaries=False)
 
369
            package_version="1.0-1", include_binaries=False,
 
370
            requester=requester)
357
371
        oops_vars = job.getOopsVars()
358
372
        naked_job = removeSecurityProxy(job)
359
373
        self.assertIn(
374
388
        distroseries = publisher.breezy_autotest
375
389
        archive1 = self.factory.makeArchive(distroseries.distribution)
376
390
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
391
        requester = self.factory.makePerson()
377
392
        publisher.getPubSource(
378
393
            distroseries=distroseries, sourcename="libc",
379
394
            version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
382
397
            package_name="libc", source_archive=archive1,
383
398
            target_archive=archive2, target_distroseries=distroseries,
384
399
            target_pocket=PackagePublishingPocket.RELEASE,
385
 
            package_version="2.8-1", include_binaries=False)
 
400
            package_version="2.8-1", include_binaries=False,
 
401
            requester=requester)
386
402
        transaction.commit()
387
403
 
388
404
        out, err, exit_code = run_script(
401
417
        distroseries = self.factory.makeDistroSeries()
402
418
        archive1 = self.factory.makeArchive(distroseries.distribution)
403
419
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
420
        requester = self.factory.makePerson()
404
421
        source = getUtility(IPlainPackageCopyJobSource)
405
422
        job = source.create(
406
423
            package_name="foo", source_archive=archive1,
407
424
            target_archive=archive2, target_distroseries=distroseries,
408
425
            target_pocket=PackagePublishingPocket.RELEASE,
409
 
            package_version="1.0-1", include_binaries=True)
 
426
            package_version="1.0-1", include_binaries=True,
 
427
            requester=requester)
410
428
        self.assertEqual(
411
429
            ("<PlainPackageCopyJob to copy package foo from "
412
430
             "{distroseries.distribution.name}/{archive1.name} to "
519
537
        # target_archive.
520
538
 
521
539
        source = getUtility(IPlainPackageCopyJobSource)
 
540
        requester = self.factory.makePerson()
522
541
        job = source.create(
523
542
            package_name="libc",
524
543
            package_version="2.8-1",
526
545
            target_archive=target_archive,
527
546
            target_distroseries=distroseries,
528
547
            target_pocket=PackagePublishingPocket.RELEASE,
529
 
            include_binaries=False)
 
548
            include_binaries=False,
 
549
            requester=requester)
530
550
 
531
551
        self.runJob(job)
532
552
 
556
576
        # Now, run the copy job, which should raise an error because
557
577
        # there's no ancestry.
558
578
        source = getUtility(IPlainPackageCopyJobSource)
 
579
        requester = self.factory.makePerson()
559
580
        job = source.create(
560
581
            package_name="copyme",
561
582
            package_version="2.8-1",
563
584
            target_archive=target_archive,
564
585
            target_distroseries=distroseries,
565
586
            target_pocket=PackagePublishingPocket.RELEASE,
566
 
            include_binaries=False)
 
587
            include_binaries=False,
 
588
            requester=requester)
567
589
 
568
590
        self.assertRaises(SuspendJobException, self.runJob, job)
569
591
        # Simulate the job runner suspending after getting a
619
641
        # Now, run the copy job.
620
642
 
621
643
        source = getUtility(IPlainPackageCopyJobSource)
 
644
        requester = self.factory.makePerson()
622
645
        job = source.create(
623
646
            package_name="copyme",
624
647
            package_version="2.8-1",
626
649
            target_archive=target_archive,
627
650
            target_distroseries=distroseries,
628
651
            target_pocket=PackagePublishingPocket.RELEASE,
629
 
            include_binaries=False)
 
652
            include_binaries=False,
 
653
            requester=requester)
630
654
 
631
655
        # The job should be suspended and there's a PackageUpload with
632
656
        # its package_copy_job set.
672
696
 
673
697
        # Now, run the copy job.
674
698
        source = getUtility(IPlainPackageCopyJobSource)
 
699
        requester = self.factory.makePerson()
675
700
        job = source.create(
676
701
            package_name="copyme",
677
702
            package_version="2.8-1",
679
704
            target_archive=target_archive,
680
705
            target_distroseries=distroseries,
681
706
            target_pocket=PackagePublishingPocket.RELEASE,
682
 
            include_binaries=False)
 
707
            include_binaries=False,
 
708
            requester=requester)
683
709
 
684
710
        # The job should be suspended and there's a PackageUpload with
685
711
        # its package_copy_job set in the UNAPPROVED queue.
715
741
            archive=source_archive)
716
742
 
717
743
        source = getUtility(IPlainPackageCopyJobSource)
 
744
        requester = self.factory.makePerson()
718
745
        job = source.create(
719
746
            package_name="copyme",
720
747
            package_version="2.8-1",
722
749
            target_archive=target_archive,
723
750
            target_distroseries=distroseries,
724
751
            target_pocket=PackagePublishingPocket.RELEASE,
725
 
            include_binaries=False)
 
752
            include_binaries=False,
 
753
            requester=requester)
726
754
 
727
755
        # Run the job so it gains a PackageUpload.
728
756
        self.assertRaises(SuspendJobException, self.runJob, job)