926
930
self.assertEqual(
927
931
policy, naked_job.getPolicyImplementation().enum_value)
933
def test_rejects_PackageUpload_when_job_fails(self):
934
# If a PCJ with a PU fails when running then we need to ensure the
936
target_archive = self.factory.makeArchive(
937
purpose=ArchivePurpose.PRIMARY)
938
source_archive = self.factory.makeArchive()
939
source_pub = self.factory.makeSourcePackagePublishingHistory(
940
sourcepackagename="copyme",
942
archive=source_archive,
943
status=PackagePublishingStatus.PUBLISHED)
944
job_source = getUtility(IPlainPackageCopyJobSource)
945
requester = self.factory.makePerson()
946
job = job_source.create(
947
package_name="copyme",
948
package_version="1.0",
949
source_archive=source_archive,
950
target_archive=target_archive,
951
target_distroseries=source_pub.distroseries,
952
target_pocket=PackagePublishingPocket.RELEASE,
953
include_binaries=False,
956
# Run the job so it gains a PackageUpload.
957
self.assertRaises(SuspendJobException, self.runJob, job)
958
# Simulate the job runner suspending after getting a
959
# SuspendJobException
961
self.layer.txn.commit()
962
self.layer.switchDbUser("launchpad_main")
964
# Accept the upload to release the job then run it.
965
pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
966
[removeSecurityProxy(job).context.id]).one()
970
# The copy will have failed because the requester has no permission
971
# to upload to the archive we created. The job should have set the
972
# PU status to REJECTED.
973
self.assertEqual(PackageUploadStatus.REJECTED, pu.status)
930
976
class TestPlainPackageCopyJobPermissions(TestCaseWithFactory):