~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-15 02:41:34 UTC
  • mfrom: (13211.2.5 bug-791204)
  • Revision ID: launchpad@pqm.canonical.com-20110615024134-qp73i2q6lo58be2u
[r=gmb][bug=791204] Prepare PackageUpload for handling copy-job
 uploads in queue script and on +queue page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from lp.services.job.interfaces.job import JobStatus
24
24
from lp.services.log.logger import BufferLogger
25
25
from lp.services.mail import stub
 
26
from lp.soyuz.adapters.overrides import SourceOverride
26
27
from lp.soyuz.enums import (
27
28
    ArchivePurpose,
28
29
    PackagePublishingStatus,
352
353
        pub = package_upload.realiseUpload()[0]
353
354
        self.assertEqual("partner", pub.archive.name)
354
355
 
 
356
    def test_package_name_and_version(self):
 
357
        # The PackageUpload knows the name and version of the package
 
358
        # being uploaded.  Internally, it gets this information from the
 
359
        # SourcePackageRelease.
 
360
        upload = self.factory.makePackageUpload()
 
361
        spr = self.factory.makeSourcePackageRelease()
 
362
        upload.addSource(spr)
 
363
        self.assertEqual(spr.sourcepackagename.name, upload.package_name)
 
364
        self.assertEqual(spr.version, upload.package_version)
 
365
 
 
366
 
 
367
class TestPackageUploadWithPackageCopyJob(TestCaseWithFactory):
 
368
 
 
369
    layer = LaunchpadZopelessLayer
 
370
    dbuser = config.uploadqueue.dbuser
 
371
 
 
372
    def makeUploadWithPackageCopyJob(self, sourcepackagename=None):
 
373
        """Create a `PackageUpload` plus attached `PlainPackageCopyJob`."""
 
374
        job_factory_args = {}
 
375
        if sourcepackagename is not None:
 
376
            job_factory_args['package_name'] = sourcepackagename.name
 
377
            job_factory_args['package_version'] = '1.0'
 
378
        job = self.factory.makePlainPackageCopyJob(**job_factory_args)
 
379
        naked_job = removeSecurityProxy(job).context
 
380
        upload = self.factory.makePackageUpload(package_copy_job=naked_job)
 
381
        return upload, job
 
382
 
 
383
    def test_package_copy_job_property(self):
 
384
        # Test that we can set and get package_copy_job.
 
385
        pu, pcj = self.makeUploadWithPackageCopyJob()
 
386
        self.assertEqual(
 
387
            removeSecurityProxy(pcj).context, pu.package_copy_job)
 
388
 
 
389
    def test_getByPackageCopyJobIDs(self):
 
390
        # getByPackageCopyJobIDs retrieves the right PackageCopyJob.
 
391
        pu, pcj = self.makeUploadWithPackageCopyJob()
 
392
        result = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
 
393
            [pcj.id])
 
394
        self.assertEqual(pu, result.one())
 
395
 
 
396
    def test_overrideSource_with_copy_job(self):
 
397
        # The overrides should be stored in the job's metadata.
 
398
        pu, pcj = self.makeUploadWithPackageCopyJob()
 
399
        component = getUtility(IComponentSet)['restricted']
 
400
        section = getUtility(ISectionSet)['games']
 
401
 
 
402
        expected_metadata = {
 
403
            'component_override': component.name,
 
404
            'section_override': section.name,
 
405
        }
 
406
        expected_metadata.update(pcj.metadata)
 
407
 
 
408
        pu.overrideSource(component, section, allowed_components=[component])
 
409
 
 
410
        self.assertEqual(expected_metadata, pcj.metadata)
 
411
 
 
412
    def test_acceptFromQueue_with_copy_job(self):
 
413
        # acceptFromQueue should accept the upload and resume the copy
 
414
        # job.
 
415
        pu, pcj = self.makeUploadWithPackageCopyJob()
 
416
        self.assertEqual(PackageUploadStatus.NEW, pu.status)
 
417
        pcj.suspend()
 
418
 
 
419
        pu.acceptFromQueue()
 
420
 
 
421
        self.assertEqual(PackageUploadStatus.ACCEPTED, pu.status)
 
422
        self.assertEqual(JobStatus.WAITING, pcj.status)
 
423
 
 
424
    def test_rejectFromQueue_with_copy_job(self):
 
425
        # rejectFromQueue will reject the upload and fail the copy job.
 
426
        pu, pcj = self.makeUploadWithPackageCopyJob()
 
427
        pcj.suspend()
 
428
 
 
429
        pu.rejectFromQueue()
 
430
 
 
431
        self.assertEqual(PackageUploadStatus.REJECTED, pu.status)
 
432
        self.assertEqual(JobStatus.FAILED, pcj.status)
 
433
 
 
434
        # It cannot be resurrected after rejection.
 
435
        self.assertRaises(
 
436
            QueueInconsistentStateError, pu.acceptFromQueue, None)
 
437
 
 
438
    def test_package_name_and_version_are_as_in_job(self):
 
439
        # The PackageUpload knows the name and version of the package
 
440
        # being uploaded.  It gets this information from the
 
441
        # PlainPackageCopyJob.
 
442
        upload, job = self.makeUploadWithPackageCopyJob()
 
443
        self.assertEqual(job.package_name, upload.package_name)
 
444
        self.assertEqual(job.package_version, upload.package_version)
 
445
 
 
446
    def test_displayarchs_for_copy_job_is_source(self):
 
447
        # For copy jobs, displayarchs is "source."
 
448
        upload, job = self.makeUploadWithPackageCopyJob()
 
449
        self.assertEqual('source', upload.displayarchs)
 
450
 
 
451
    def test_component_and_section_name(self):
 
452
        # An upload with a copy job takes its component and section
 
453
        # names from the job.
 
454
        spn = self.factory.makeSourcePackageName()
 
455
        upload, job = self.makeUploadWithPackageCopyJob(sourcepackagename=spn)
 
456
        component = self.factory.makeComponent()
 
457
        section = self.factory.makeSection()
 
458
        job.addSourceOverride(SourceOverride(
 
459
            source_package_name=spn, component=component, section=section))
 
460
        self.assertEqual(component.name, upload.component_name)
 
461
 
 
462
    def test_displayname_is_package_name(self):
 
463
        # An upload with a copy job uses the package name for its
 
464
        # display name.
 
465
        spn = self.factory.makeSourcePackageName()
 
466
        upload, job = self.makeUploadWithPackageCopyJob(sourcepackagename=spn)
 
467
        self.assertEqual(spn.name, upload.displayname)
 
468
 
 
469
    def test_upload_with_copy_job_has_no_source_package_release(self):
 
470
        # A copy job does not provide the upload with a
 
471
        # SourcePackageRelease.
 
472
        pu, pcj = self.makeUploadWithPackageCopyJob()
 
473
        self.assertIs(None, pu.sourcepackagerelease)
 
474
 
355
475
 
356
476
class TestPackageUploadSet(TestCaseWithFactory):
357
477
    """Unit tests for `PackageUploadSet`."""