def test_cancel_job(self, mock_requests, MockLandoWorkerClient, MockJobSettings): job_id = 2 mock_settings, report = make_mock_settings_and_report(job_id) MockJobSettings.return_value = mock_settings lando = Lando(MagicMock()) lando.cancel_job(MagicMock(job_id=job_id)) expected_report = """ Set job step to EMPTY. Set job state to C. Send progress notification. Job:1 State:C Step:EMPTY Terminated vm worker_x. Deleted volume volume_x. Delete my worker's queue. """ self.assertMultiLineEqual(expected_report.strip(), report.text.strip())
def test_cancel_job_with_no_vm_name(self, mock_requests, MockLandoWorkerClient, MockJobSettings): """ When canceling a job that doesn't have a VM yet just set the state to canceled. There is no need to try to delete a VM or queue that doesn't exist. """ job_id = 2 mock_settings, report = make_mock_settings_and_report(job_id) report.vm_instance_name = '' MockJobSettings.return_value = mock_settings lando = Lando(MagicMock()) lando.cancel_job(MagicMock(job_id=job_id)) expected_report = """ Set job step to EMPTY. Set job state to C. Send progress notification. Job:1 State:C Step:EMPTY """ self.assertMultiLineEqual(expected_report.strip(), report.text.strip())