예제 #1
0
    def test_task_success_canceling(self, refreshStatus, request, is_revoked):
        task = mock.MagicMock()
        task.request.jobInfoSpec = self.headers['jobInfoSpec']
        task.request.parent_id = None

        validation_error = {'field': 'status', 'message': 'invalid'}
        r = request.return_value
        r.raise_for_status.side_effect = [
            None, MockHTTPError(400, validation_error)
        ]
        refreshStatus.return_value = JobStatus.CANCELING
        is_revoked.return_value = True

        gw_task_prerun(task)
        gw_task_success(sender=task)

        # We where in the canceling state so we should move into CANCELED
        refreshStatus.assert_called_once()
        self.assertEqual(request.call_args_list[1][1]['data']['status'],
                         JobStatus.CANCELED)

        # Now try with RUNNING
        request.reset_mock()
        is_revoked.return_value = False
        refreshStatus.reset_mock()
        r.raise_for_status.side_effect = [None, None]

        gw_task_prerun(task)
        gw_task_success(sender=task)

        # We should move into SUCCESS
        refreshStatus.assert_not_called()
        self.assertEqual(request.call_args_list[1][1]['data']['status'],
                         JobStatus.SUCCESS)
    def test_task_success(self, jm):
        task = mock.MagicMock()
        task.request.parent_id = None
        task.job_manager = jm(**self.headers)

        gw_task_success(sender=task)

        task.job_manager.updateStatus.assert_called_once_with(
            JobStatus.SUCCESS)
예제 #3
0
    def test_task_success(self, jm, is_revoked):
        task = mock.MagicMock()
        task.request.parent_id = None
        task.job_manager = jm(**self.headers)
        is_revoked.return_value = False

        gw_task_success(sender=task)

        task.job_manager.updateStatus.assert_called_once_with(
            JobStatus.SUCCESS)
예제 #4
0
    def test_task_success_canceling(self, refreshStatus, is_revoked):
        task = mock.MagicMock()
        task.name = 'example.task'
        task.request.jobInfoSpec = self.headers['jobInfoSpec']
        task.request.parent_id = None

        validation_error = {
            'field': 'status',
            'message': 'invalid'
        }

        class SessionMock(requests.Session):

            def __init__(self, *args, **kwargs):
                self.request = mock.MagicMock()
                self.response = self.request.return_value
                self.response.raise_for_status.side_effect = [
                    None, MockHTTPError(400, validation_error)]
                self.adapters = {}

        with unittest.mock.patch(
            'girder_worker.utils.requests.Session'
        ) as session:
            sessionMock = SessionMock()
            session.return_value = sessionMock

            refreshStatus.return_value = JobStatus.CANCELING
            is_revoked.return_value = True

            gw_task_prerun(task=task, sender=task)
            gw_task_success(sender=task)

            # We where in the canceling state so we should move into CANCELED
            refreshStatus.assert_called_once()
            self.assertEqual(
                sessionMock.request.call_args_list[1][1]['data']['status'], JobStatus.CANCELED)

            # Now try with RUNNING
            sessionMock.request.reset_mock()
            is_revoked.return_value = False
            refreshStatus.reset_mock()
            sessionMock.response.raise_for_status.side_effect = [None, None]

            gw_task_prerun(task=task, sender=task)
            gw_task_success(sender=task)

            # We should move into SUCCESS
            refreshStatus.assert_not_called()
            self.assertEqual(
                sessionMock.request.call_args_list[1][1]['data']['status'], JobStatus.SUCCESS)
예제 #5
0
def test_gw_task_success_with_builtin_tasks_should_noop(name):
    with mock.patch('girder_worker.app._update_status') as us:
        task = mock.MagicMock()
        task.name = name
        gw_task_success(sender=task)
        us.assert_not_called()