352
353
pub = package_upload.realiseUpload()[0]
353
354
self.assertEqual("partner", pub.archive.name)
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)
367
class TestPackageUploadWithPackageCopyJob(TestCaseWithFactory):
369
layer = LaunchpadZopelessLayer
370
dbuser = config.uploadqueue.dbuser
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)
383
def test_package_copy_job_property(self):
384
# Test that we can set and get package_copy_job.
385
pu, pcj = self.makeUploadWithPackageCopyJob()
387
removeSecurityProxy(pcj).context, pu.package_copy_job)
389
def test_getByPackageCopyJobIDs(self):
390
# getByPackageCopyJobIDs retrieves the right PackageCopyJob.
391
pu, pcj = self.makeUploadWithPackageCopyJob()
392
result = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
394
self.assertEqual(pu, result.one())
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']
402
expected_metadata = {
403
'component_override': component.name,
404
'section_override': section.name,
406
expected_metadata.update(pcj.metadata)
408
pu.overrideSource(component, section, allowed_components=[component])
410
self.assertEqual(expected_metadata, pcj.metadata)
412
def test_acceptFromQueue_with_copy_job(self):
413
# acceptFromQueue should accept the upload and resume the copy
415
pu, pcj = self.makeUploadWithPackageCopyJob()
416
self.assertEqual(PackageUploadStatus.NEW, pu.status)
421
self.assertEqual(PackageUploadStatus.ACCEPTED, pu.status)
422
self.assertEqual(JobStatus.WAITING, pcj.status)
424
def test_rejectFromQueue_with_copy_job(self):
425
# rejectFromQueue will reject the upload and fail the copy job.
426
pu, pcj = self.makeUploadWithPackageCopyJob()
431
self.assertEqual(PackageUploadStatus.REJECTED, pu.status)
432
self.assertEqual(JobStatus.FAILED, pcj.status)
434
# It cannot be resurrected after rejection.
436
QueueInconsistentStateError, pu.acceptFromQueue, None)
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)
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)
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)
462
def test_displayname_is_package_name(self):
463
# An upload with a copy job uses the package name for its
465
spn = self.factory.makeSourcePackageName()
466
upload, job = self.makeUploadWithPackageCopyJob(sourcepackagename=spn)
467
self.assertEqual(spn.name, upload.displayname)
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)
356
476
class TestPackageUploadSet(TestCaseWithFactory):
357
477
"""Unit tests for `PackageUploadSet`."""