diff --git a/lms/djangoapps/instructor_task/api_helper.py b/lms/djangoapps/instructor_task/api_helper.py index bf49deda9d..59fa29dd36 100644 --- a/lms/djangoapps/instructor_task/api_helper.py +++ b/lms/djangoapps/instructor_task/api_helper.py @@ -265,6 +265,13 @@ def _handle_instructor_task_failure(instructor_task, error): raise QueueConnectionError() +def _get_async_result(task_id): + """ + Use this minor indirection to facilitate mocking the AsyncResult in tests. + """ + return AsyncResult(task_id) + + def get_updated_instructor_task(task_id): """ Returns InstructorTask object corresponding to a given `task_id`. @@ -282,7 +289,7 @@ def get_updated_instructor_task(task_id): # if the task is not already known to be done, then we need to query # the underlying task's result object: if instructor_task.task_state not in READY_STATES: - result = AsyncResult(task_id) + result = _get_async_result(task_id) _update_instructor_task(instructor_task, result) return instructor_task diff --git a/lms/djangoapps/instructor_task/tests/test_views.py b/lms/djangoapps/instructor_task/tests/test_views.py index 4f96458a1d..cb404b9811 100644 --- a/lms/djangoapps/instructor_task/tests/test_views.py +++ b/lms/djangoapps/instructor_task/tests/test_views.py @@ -158,7 +158,7 @@ class InstructorTaskReportTest(InstructorTaskTestCase): """ Provides mock result to caller of instructor_task_status, and returns resulting output. """ - with patch('celery.result.AsyncResult.__new__') as mock_result_ctor: + with patch('lms.djangoapps.instructor_task.api_helper._get_async_result') as mock_result_ctor: mock_result_ctor.return_value = mock_result response = self._get_instructor_task_status(task_id) output = json.loads(response.content.decode('utf-8'))