~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-23 06:49:43 UTC
  • mfrom: (13277.2.2 bug-799680)
  • Revision ID: launchpad@pqm.canonical.com-20110623064943-cuquwlhnwoa0xhj4
[r=julian-edwards][bug=799680] Show architecture for copy-job uploads
        as "sync."

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import os
9
9
import shutil
10
10
 
11
 
from storm.store import Store
12
11
from zope.component import getUtility
13
12
from zope.security.proxy import removeSecurityProxy
14
13
 
443
442
        self.assertEqual(job.package_name, upload.package_name)
444
443
        self.assertEqual(job.package_version, upload.package_version)
445
444
 
446
 
    def test_displayarchs_for_copy_job_is_source(self):
 
445
    def test_displayarchs_for_copy_job_is_sync(self):
447
446
        # For copy jobs, displayarchs is "source."
448
447
        upload, job = self.makeUploadWithPackageCopyJob()
449
 
        self.assertEqual('source', upload.displayarchs)
 
448
        self.assertEqual('sync', upload.displayarchs)
450
449
 
451
450
    def test_component_and_section_name(self):
452
451
        # An upload with a copy job takes its component and section
788
787
            [upload],
789
788
            upload_set.getAll(
790
789
                distroseries, name=spn.name, version=upload.displayversion))
791
 
 
792
 
 
793
 
class TestPackageUploadWithPackageCopyJob(TestCaseWithFactory):
794
 
 
795
 
    layer = LaunchpadZopelessLayer
796
 
    dbuser = config.uploadqueue.dbuser
797
 
 
798
 
    def test_package_copy_job_property(self):
799
 
        # Test that we can set and get package_copy_job.
800
 
        pcj = removeSecurityProxy(
801
 
            self.factory.makePlainPackageCopyJob()).context
802
 
        pu = self.factory.makePackageUpload(package_copy_job=pcj)
803
 
        Store.of(pu).flush()
804
 
 
805
 
        self.assertEqual(pcj, pu.package_copy_job)
806
 
 
807
 
    def test_getByPackageCopyJobIDs(self):
808
 
        pcj = removeSecurityProxy(
809
 
            self.factory.makePlainPackageCopyJob()).context
810
 
        pu = self.factory.makePackageUpload(package_copy_job=pcj)
811
 
        result = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
812
 
            [pcj.id])
813
 
        self.assertEqual(pu, result.one())
814
 
 
815
 
    def test_overrideSource_with_copy_job(self):
816
 
        # The overrides should be stored in the job's metadata.
817
 
        plain_copy_job = self.factory.makePlainPackageCopyJob()
818
 
        pcj = removeSecurityProxy(plain_copy_job).context
819
 
        pu = self.factory.makePackageUpload(package_copy_job=pcj)
820
 
        component = getUtility(IComponentSet)['restricted']
821
 
        section = getUtility(ISectionSet)['games']
822
 
 
823
 
        expected_metadata = {
824
 
            'component_override': component.name,
825
 
            'section_override': section.name
826
 
        }
827
 
        expected_metadata.update(plain_copy_job.metadata)
828
 
 
829
 
        pu.overrideSource(component, section, allowed_components=[component])
830
 
 
831
 
        self.assertEqual(
832
 
            expected_metadata, plain_copy_job.metadata)
833
 
 
834
 
    def test_acceptFromQueue_with_copy_job(self):
835
 
        # acceptFromQueue should accept the upload and resume the copy
836
 
        # job.
837
 
        plain_copy_job = self.factory.makePlainPackageCopyJob()
838
 
        pcj = removeSecurityProxy(plain_copy_job).context
839
 
        pu = self.factory.makePackageUpload(package_copy_job=pcj)
840
 
        self.assertEqual(PackageUploadStatus.NEW, pu.status)
841
 
        plain_copy_job.suspend()
842
 
 
843
 
        pu.acceptFromQueue()
844
 
 
845
 
        self.assertEqual(PackageUploadStatus.ACCEPTED, pu.status)
846
 
        self.assertEqual(JobStatus.WAITING, plain_copy_job.status)
847
 
 
848
 
    def test_rejectFromQueue_with_copy_job(self):
849
 
        # rejectFromQueue will reject the upload and fail the copy job.
850
 
        plain_copy_job = self.factory.makePlainPackageCopyJob()
851
 
        pcj = removeSecurityProxy(plain_copy_job).context
852
 
        pu = self.factory.makePackageUpload(package_copy_job=pcj)
853
 
        plain_copy_job.suspend()
854
 
 
855
 
        pu.rejectFromQueue()
856
 
 
857
 
        self.assertEqual(PackageUploadStatus.REJECTED, pu.status)
858
 
        self.assertEqual(JobStatus.FAILED, plain_copy_job.status)
859
 
 
860
 
        # It cannot be resurrected after rejection.
861
 
        self.assertRaises(
862
 
            QueueInconsistentStateError, pu.acceptFromQueue, None)