~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-26 14:57:54 UTC
  • mfrom: (13794.1.12 bug-832661)
  • Revision ID: launchpad@pqm.canonical.com-20110826145754-364nkd1s6ofz4nqd
[r=adeuring][bug=832661] Create DSDJs from requestDeletion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from lp.services.database import bulk
28
28
from lp.services.features.testing import FeatureFixture
29
29
from lp.services.job.interfaces.job import JobStatus
30
 
from lp.soyuz.enums import PackagePublishingStatus
 
30
from lp.soyuz.enums import (
 
31
    ArchivePurpose,
 
32
    PackagePublishingStatus,
 
33
    )
31
34
from lp.soyuz.interfaces.distributionjob import (
32
35
    DistributionJobType,
33
36
    IDistroSeriesDifferenceJobSource,
322
325
            [],
323
326
            find_waiting_jobs(dsp.derived_series, package, dsp.parent_series))
324
327
 
 
328
    def test_createForSPPHs_creates_job_for_derived_series(self):
 
329
        dsp = self.factory.makeDistroSeriesParent()
 
330
        spph = self.factory.makeSourcePackagePublishingHistory(
 
331
            dsp.parent_series, pocket=PackagePublishingPocket.RELEASE)
 
332
        spn = spph.sourcepackagerelease.sourcepackagename
 
333
 
 
334
        self.getJobSource().createForSPPHs([spph])
 
335
 
 
336
        self.assertEqual(
 
337
            1, len(find_waiting_jobs(
 
338
                dsp.derived_series, spn, dsp.parent_series)))
 
339
 
 
340
    def test_createForSPPHs_creates_job_for_parent_series(self):
 
341
        dsp = self.factory.makeDistroSeriesParent()
 
342
        spph = self.factory.makeSourcePackagePublishingHistory(
 
343
            dsp.derived_series, pocket=PackagePublishingPocket.RELEASE)
 
344
        spn = spph.sourcepackagerelease.sourcepackagename
 
345
 
 
346
        self.getJobSource().createForSPPHs([spph])
 
347
 
 
348
        self.assertEqual(
 
349
            1, len(find_waiting_jobs(
 
350
                dsp.derived_series, spn, dsp.parent_series)))
 
351
 
 
352
    def test_createForSPPHs_obeys_feature_flag(self):
 
353
        self.useFixture(FeatureFixture({FEATURE_FLAG_ENABLE_MODULE: ''}))
 
354
        dsp = self.factory.makeDistroSeriesParent()
 
355
        spph = self.factory.makeSourcePackagePublishingHistory(
 
356
            dsp.parent_series, pocket=PackagePublishingPocket.RELEASE)
 
357
        spn = spph.sourcepackagerelease.sourcepackagename
 
358
        self.getJobSource().createForSPPHs([spph])
 
359
        self.assertContentEqual(
 
360
            [], find_waiting_jobs(dsp.derived_series, spn, dsp.parent_series))
 
361
 
 
362
    def test_createForSPPHs_ignores_backports_and_proposed(self):
 
363
        dsp = self.factory.makeDistroSeriesParent()
 
364
        spr = self.factory.makeSourcePackageRelease()
 
365
        spn = spr.sourcepackagename
 
366
        ignored_pockets = [
 
367
            PackagePublishingPocket.BACKPORTS,
 
368
            PackagePublishingPocket.PROPOSED,
 
369
            ]
 
370
        spphs = [
 
371
            self.factory.makeSourcePackagePublishingHistory(
 
372
                distroseries=dsp.parent_series, sourcepackagerelease=spr,
 
373
                pocket=pocket)
 
374
            for pocket in ignored_pockets]
 
375
        self.getJobSource().createForSPPHs(spphs)
 
376
        self.assertContentEqual(
 
377
            [], find_waiting_jobs(dsp.derived_series, spn, dsp.parent_series))
 
378
 
 
379
    def test_createForSPPHs_creates_no_jobs_for_unrelated_series(self):
 
380
        dsp = self.factory.makeDistroSeriesParent()
 
381
        other_series = self.factory.makeDistroSeries(
 
382
            distribution=dsp.derived_series.distribution)
 
383
        spph = self.factory.makeSourcePackagePublishingHistory(
 
384
            dsp.parent_series, pocket=PackagePublishingPocket.RELEASE)
 
385
        spn = spph.sourcepackagerelease.sourcepackagename
 
386
        self.getJobSource().createForSPPHs([spph])
 
387
        self.assertContentEqual(
 
388
            [], find_waiting_jobs(dsp.derived_series, spn, other_series))
 
389
 
 
390
    def test_createForSPPHs_accepts_SPPHs_for_multiple_distroseries(self):
 
391
        derived_distro = self.factory.makeDistribution()
 
392
        spn = self.factory.makeSourcePackageName()
 
393
        series = [
 
394
            self.factory.makeDistroSeries(derived_distro)
 
395
            for counter in xrange(2)]
 
396
        dsps = [
 
397
            self.factory.makeDistroSeriesParent(derived_series=distroseries)
 
398
            for distroseries in series]
 
399
 
 
400
        for distroseries in series:
 
401
            self.factory.makeSourcePackagePublishingHistory(
 
402
                distroseries, pocket=PackagePublishingPocket.RELEASE,
 
403
                sourcepackagerelease=self.factory.makeSourcePackageRelease(
 
404
                    sourcepackagename=spn))
 
405
 
 
406
        job_counts = dict(
 
407
            (dsp.derived_series, len(find_waiting_jobs(
 
408
                dsp.derived_series, spn, dsp.parent_series)))
 
409
            for dsp in dsps)
 
410
        self.assertEqual(
 
411
            dict((distroseries, 1) for distroseries in series),
 
412
            job_counts)
 
413
 
 
414
    def test_createForSPPHs_behaves_sensibly_if_job_already_exists(self):
 
415
        # If a job already existed, createForSPPHs may create a
 
416
        # redundant one but it certainly won't do anything weird like
 
417
        # delete what was there or create too many.
 
418
        dsp = self.factory.makeDistroSeriesParent()
 
419
        spph = self.factory.makeSourcePackagePublishingHistory(
 
420
            dsp.parent_series, pocket=PackagePublishingPocket.RELEASE)
 
421
        spn = spph.sourcepackagerelease.sourcepackagename
 
422
 
 
423
        create_jobs = range(1, 3)
 
424
        for counter in create_jobs:
 
425
            self.getJobSource().createForSPPHs([spph])
 
426
 
 
427
        job_count = len(find_waiting_jobs(
 
428
            dsp.derived_series, spn, dsp.parent_series))
 
429
        self.assertIn(job_count, create_jobs)
 
430
 
 
431
    def test_createForSPPHs_creates_no_jobs_for_ppas(self):
 
432
        dsp = self.factory.makeDistroSeriesParent()
 
433
        series = dsp.parent_series
 
434
        spph = self.factory.makeSourcePackagePublishingHistory(
 
435
            series, pocket=PackagePublishingPocket.RELEASE,
 
436
            archive=self.factory.makeArchive(
 
437
                distribution=series.distribution, purpose=ArchivePurpose.PPA))
 
438
        spn = spph.sourcepackagerelease.sourcepackagename
 
439
        self.getJobSource().createForSPPHs([spph])
 
440
        self.assertContentEqual(
 
441
            [], find_waiting_jobs(dsp.derived_series, spn, dsp.parent_series))
 
442
 
325
443
    def test_massCreateForSeries_obeys_feature_flag(self):
326
444
        self.useFixture(FeatureFixture({FEATURE_FLAG_ENABLE_MODULE: ''}))
327
445
        dsp = self.factory.makeDistroSeriesParent()