~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-18 12:18:50 UTC
  • mfrom: (13444.3.8 pcj-requester-bug-810957)
  • Revision ID: launchpad@pqm.canonical.com-20110718121850-cfc28kynn6k92qz2
[r=adeuring][no-qa] Enable PackageCopyJob to store the Person who
        requested it.

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()
148
152
            derived_series=derived_series)
149
153
        mother_package = self.factory.makeSourcePackageName()
150
154
        father_package = self.factory.makeSourcePackageName()
 
155
        requester = self.factory.makePerson()
151
156
        job_source = getUtility(IPlainPackageCopyJobSource)
152
157
        copy_tasks = [
153
158
            (
166
171
                ),
167
172
            ]
168
173
        job_ids = list(
169
 
            job_source.createMultiple(mother.derived_series, copy_tasks))
 
174
            job_source.createMultiple(mother.derived_series, copy_tasks,
 
175
                                      requester))
170
176
        jobs = list(job_source.getActiveJobs(derived_series.main_archive))
171
177
        self.assertContentEqual(job_ids, [job.id for job in jobs])
172
178
        self.assertEqual(len(copy_tasks), len(set([job.job for job in jobs])))
185
191
            for job in jobs]
186
192
        self.assertEqual(copy_tasks, requested_copies)
187
193
 
 
194
        # The passed requester should be the same on all jobs.
 
195
        actual_requester = set(job.requester for job in jobs)
 
196
        self.assertEqual(1, len(actual_requester))
 
197
        self.assertEqual(requester, jobs[0].requester)
 
198
 
188
199
    def test_getActiveJobs(self):
189
200
        # getActiveJobs() can retrieve all active jobs for an archive.
190
201
        distroseries = self.factory.makeDistroSeries()
191
202
        archive1 = self.factory.makeArchive(distroseries.distribution)
192
203
        archive2 = self.factory.makeArchive(distroseries.distribution)
193
204
        source = getUtility(IPlainPackageCopyJobSource)
 
205
        requester = self.factory.makePerson()
194
206
        job = source.create(
195
207
            package_name="foo", source_archive=archive1,
196
208
            target_archive=archive2, target_distroseries=distroseries,
197
209
            target_pocket=PackagePublishingPocket.RELEASE,
198
 
            package_version="1.0-1", include_binaries=False)
 
210
            package_version="1.0-1", include_binaries=False,
 
211
            requester=requester)
199
212
        self.assertContentEqual([job], source.getActiveJobs(archive2))
200
213
 
201
214
    def test_getActiveJobs_gets_oldest_first(self):
249
262
        distroseries = self.factory.makeDistroSeries()
250
263
        archive1 = self.factory.makeArchive(distroseries.distribution)
251
264
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
265
        requester = self.factory.makePerson()
252
266
        job_source = getUtility(IPlainPackageCopyJobSource)
253
267
        job = job_source.create(
254
268
            package_name="foo", source_archive=archive1,
255
269
            target_archive=archive2, target_distroseries=distroseries,
256
270
            target_pocket=PackagePublishingPocket.RELEASE,
257
 
            package_version="1.0-1", include_binaries=False)
 
271
            package_version="1.0-1", include_binaries=False,
 
272
            requester=requester)
258
273
        naked_job = removeSecurityProxy(job)
259
274
        naked_job.reportFailure = FakeMethod()
260
275
 
268
283
        package = self.factory.makeSourcePackageName()
269
284
        archive1 = self.factory.makeArchive(distroseries.distribution)
270
285
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
286
        requester = self.factory.makePerson()
271
287
        source = getUtility(IPlainPackageCopyJobSource)
272
288
        job = source.create(
273
289
            package_name=package.name, source_archive=archive1,
274
290
            target_archive=archive2, target_distroseries=distroseries,
275
291
            target_pocket=PackagePublishingPocket.UPDATES,
276
 
            include_binaries=False, package_version='1.0')
 
292
            include_binaries=False, package_version='1.0',
 
293
            requester=requester)
277
294
 
278
295
        naked_job = removeSecurityProxy(job)
279
296
        naked_job.reportFailure = FakeMethod()
315
332
            archive=target_archive)
316
333
 
317
334
        source = getUtility(IPlainPackageCopyJobSource)
 
335
        requester = self.factory.makePerson()
318
336
        job = source.create(
319
337
            package_name="libc",
320
338
            source_archive=breezy_archive, target_archive=target_archive,
321
339
            target_distroseries=target_series,
322
340
            target_pocket=PackagePublishingPocket.RELEASE,
323
 
            package_version="2.8-1", include_binaries=False)
 
341
            package_version="2.8-1", include_binaries=False,
 
342
            requester=requester)
324
343
        self.assertEqual("libc", job.package_name)
325
344
        self.assertEqual("2.8-1", job.package_version)
326
345
 
348
367
        distroseries = self.factory.makeDistroSeries()
349
368
        archive1 = self.factory.makeArchive(distroseries.distribution)
350
369
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
370
        requester = self.factory.makePerson()
351
371
        source = getUtility(IPlainPackageCopyJobSource)
352
372
        job = source.create(
353
373
            package_name="foo", source_archive=archive1,
354
374
            target_archive=archive2, target_distroseries=distroseries,
355
375
            target_pocket=PackagePublishingPocket.RELEASE,
356
 
            package_version="1.0-1", include_binaries=False)
 
376
            package_version="1.0-1", include_binaries=False,
 
377
            requester=requester)
357
378
        oops_vars = job.getOopsVars()
358
379
        naked_job = removeSecurityProxy(job)
359
380
        self.assertIn(
374
395
        distroseries = publisher.breezy_autotest
375
396
        archive1 = self.factory.makeArchive(distroseries.distribution)
376
397
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
398
        requester = self.factory.makePerson()
377
399
        publisher.getPubSource(
378
400
            distroseries=distroseries, sourcename="libc",
379
401
            version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
382
404
            package_name="libc", source_archive=archive1,
383
405
            target_archive=archive2, target_distroseries=distroseries,
384
406
            target_pocket=PackagePublishingPocket.RELEASE,
385
 
            package_version="2.8-1", include_binaries=False)
 
407
            package_version="2.8-1", include_binaries=False,
 
408
            requester=requester)
386
409
        transaction.commit()
387
410
 
388
411
        out, err, exit_code = run_script(
401
424
        distroseries = self.factory.makeDistroSeries()
402
425
        archive1 = self.factory.makeArchive(distroseries.distribution)
403
426
        archive2 = self.factory.makeArchive(distroseries.distribution)
 
427
        requester = self.factory.makePerson()
404
428
        source = getUtility(IPlainPackageCopyJobSource)
405
429
        job = source.create(
406
430
            package_name="foo", source_archive=archive1,
407
431
            target_archive=archive2, target_distroseries=distroseries,
408
432
            target_pocket=PackagePublishingPocket.RELEASE,
409
 
            package_version="1.0-1", include_binaries=True)
 
433
            package_version="1.0-1", include_binaries=True,
 
434
            requester=requester)
410
435
        self.assertEqual(
411
436
            ("<PlainPackageCopyJob to copy package foo from "
412
437
             "{distroseries.distribution.name}/{archive1.name} to "
519
544
        # target_archive.
520
545
 
521
546
        source = getUtility(IPlainPackageCopyJobSource)
 
547
        requester = self.factory.makePerson()
522
548
        job = source.create(
523
549
            package_name="libc",
524
550
            package_version="2.8-1",
526
552
            target_archive=target_archive,
527
553
            target_distroseries=distroseries,
528
554
            target_pocket=PackagePublishingPocket.RELEASE,
529
 
            include_binaries=False)
 
555
            include_binaries=False,
 
556
            requester=requester)
530
557
 
531
558
        self.runJob(job)
532
559
 
556
583
        # Now, run the copy job, which should raise an error because
557
584
        # there's no ancestry.
558
585
        source = getUtility(IPlainPackageCopyJobSource)
 
586
        requester = self.factory.makePerson()
559
587
        job = source.create(
560
588
            package_name="copyme",
561
589
            package_version="2.8-1",
563
591
            target_archive=target_archive,
564
592
            target_distroseries=distroseries,
565
593
            target_pocket=PackagePublishingPocket.RELEASE,
566
 
            include_binaries=False)
 
594
            include_binaries=False,
 
595
            requester=requester)
567
596
 
568
597
        self.assertRaises(SuspendJobException, self.runJob, job)
569
598
        # Simulate the job runner suspending after getting a
619
648
        # Now, run the copy job.
620
649
 
621
650
        source = getUtility(IPlainPackageCopyJobSource)
 
651
        requester = self.factory.makePerson()
622
652
        job = source.create(
623
653
            package_name="copyme",
624
654
            package_version="2.8-1",
626
656
            target_archive=target_archive,
627
657
            target_distroseries=distroseries,
628
658
            target_pocket=PackagePublishingPocket.RELEASE,
629
 
            include_binaries=False)
 
659
            include_binaries=False,
 
660
            requester=requester)
630
661
 
631
662
        # The job should be suspended and there's a PackageUpload with
632
663
        # its package_copy_job set.
672
703
 
673
704
        # Now, run the copy job.
674
705
        source = getUtility(IPlainPackageCopyJobSource)
 
706
        requester = self.factory.makePerson()
675
707
        job = source.create(
676
708
            package_name="copyme",
677
709
            package_version="2.8-1",
679
711
            target_archive=target_archive,
680
712
            target_distroseries=distroseries,
681
713
            target_pocket=PackagePublishingPocket.RELEASE,
682
 
            include_binaries=False)
 
714
            include_binaries=False,
 
715
            requester=requester)
683
716
 
684
717
        # The job should be suspended and there's a PackageUpload with
685
718
        # its package_copy_job set in the UNAPPROVED queue.
715
748
            archive=source_archive)
716
749
 
717
750
        source = getUtility(IPlainPackageCopyJobSource)
 
751
        requester = self.factory.makePerson()
718
752
        job = source.create(
719
753
            package_name="copyme",
720
754
            package_version="2.8-1",
722
756
            target_archive=target_archive,
723
757
            target_distroseries=distroseries,
724
758
            target_pocket=PackagePublishingPocket.RELEASE,
725
 
            include_binaries=False)
 
759
            include_binaries=False,
 
760
            requester=requester)
726
761
 
727
762
        # Run the job so it gains a PackageUpload.
728
763
        self.assertRaises(SuspendJobException, self.runJob, job)