def test_canceled_job(self, mock_njs, mock_auth): self._cleanup(self.jobid) mlog = MockLogger() os.environ['KB_AUTH_TOKEN'] = 'bogus' jr = JobRunner(self.config, self.njs_url, self.jobid, self.token, self.admin_token) jr.logger = mlog jr.njs.check_job_canceled.return_value = {'finished': True} with self.assertRaises(OSError): jr.run() self.assertEquals(mlog.errors[0], 'Job already run or canceled')
def test_error_update(self, mock_njs, mock_auth): self._cleanup(self.jobid) mlog = MockLogger() os.environ['KB_AUTH_TOKEN'] = 'bogus' jr = JobRunner(self.config, self.njs_url, self.jobid, self.token, self.admin_token) jr.logger = mlog jr.njs.check_job_canceled.return_value = {'finished': False} jr.njs.update_job.side_effect = ConnectionError() jr.njs.get_job_params.side_effect = ConnectionError() with self.assertRaises(ConnectionError): jr.run() emsg = 'Failed to get job parameters. Exiting.' self.assertEquals(mlog.errors[0], emsg)
def test_token_lifetime(self, mock_req, mock_auth, mock_njs): # Test get token lifetime config = NJS_JOB_PARAMS[1] resp = AUTH_V2_TOKEN mock_req.get.return_value = MockAuth(resp) jr = JobRunner(self.config, self.njs_url, self.jobid, self.token, self.admin_token) mlog = MockLogger() jr.logger = mlog exp = jr._get_token_lifetime(config) self.assertGreater(exp, 0) mock_req.get.side_effect = OSError("bad request") with self.assertRaises(OSError): jr._get_token_lifetime(config)