Example #1
0
    def test_fail(self):
        """Job.fail should update the Job appropriately.

        It should set date_finished and set the job status to FAILED.
        """
        job = Job(_status=JobStatus.RUNNING)
        self.assertEqual(None, job.date_finished)
        job.fail()
        self.assertNotEqual(None, job.date_finished)
        self.assertEqual(job.status, JobStatus.FAILED)
Example #2
0
    def test_fail_manages_transactions(self):
        # Job.fail() does not commit the transaction by default.
        job = Job()
        job.start()
        with TransactionRecorder() as recorder:
            job.fail()
            self.assertEqual([], recorder.transaction_calls)

        # If explicitly specified, Job.fail() commits the transaction.
        # Note that there is an additional commit to update the job status.
        job = Job()
        job.start()
        with TransactionRecorder() as recorder:
            job.fail(manage_transaction=True)
            self.assertEqual(['abort', 'commit'], recorder.transaction_calls)