~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=julian-edwards][bug=815965,
        816330] Stop is_auto_sync_upload() blowing up when it is passed None
        as a changed_by_email. Also make sure that PackageCopyJobs
        reject the PackageUpload if the job fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
 
102
102
    def runJob(self, job):
103
103
        """Helper to switch to the right DB user and run the job."""
 
104
        # We are basically mimicking the job runner here.
104
105
        self.layer.txn.commit()
105
106
        self.layer.switchDbUser(self.dbuser)
106
107
        # Set the state to RUNNING.
107
108
        job.start()
108
109
        # Commit the RUNNING state.
109
110
        self.layer.txn.commit()
110
 
        job.run()
 
111
        try:
 
112
            job.run()
 
113
        except SuspendJobException:
 
114
            # Re-raise this one as many tests check for its presence.
 
115
            raise
 
116
        except:
 
117
            transaction.abort()
 
118
            job.fail()
111
119
 
112
120
 
113
121
class PlainPackageCopyJobTests(TestCaseWithFactory, LocalTestHelper):
961
969
        self.layer.txn.commit()
962
970
        self.layer.switchDbUser("launchpad_main")
963
971
 
 
972
        # Patch the job's attemptCopy() method so it just raises an
 
973
        # exception.
 
974
        def blow_up():
 
975
            raise Exception("I blew up")
 
976
        naked_job = removeSecurityProxy(job)
 
977
        self.patch(naked_job, "attemptCopy", blow_up)
 
978
 
964
979
        # Accept the upload to release the job then run it.
965
980
        pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
966
981
            [removeSecurityProxy(job).context.id]).one()
967
982
        pu.acceptFromQueue()
968
983
        self.runJob(job)
969
984
 
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.
 
985
        # The job should have set the PU status to REJECTED.
973
986
        self.assertEqual(PackageUploadStatus.REJECTED, pu.status)
974
987
 
975
988