Fix problematic mock in instructor_task tests BOM-403 (#22007)

This commit is contained in:
Jeremy Bowman
2019-10-11 15:44:42 -04:00
committed by GitHub
parent 55c0151cc8
commit b939791fe0
2 changed files with 9 additions and 2 deletions

View File

@@ -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

View File

@@ -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'))