Commit 2d1ebb73 by Brian Wilson

Test when querying for a non-existent task

parent 77032067
...@@ -189,13 +189,13 @@ def get_status_from_instructor_task(instructor_task): ...@@ -189,13 +189,13 @@ def get_status_from_instructor_task(instructor_task):
""" """
status = {} status = {}
if instructor_task.task_output is not None: if instructor_task is not None:
status['task_progress'] = json.loads(instructor_task.task_output) # status basic information matching what's stored in InstructorTask:
status['task_id'] = instructor_task.task_id
# status basic information matching what's stored in InstructorTask: status['task_state'] = instructor_task.task_state
status['task_id'] = instructor_task.task_id status['in_progress'] = instructor_task.task_state not in READY_STATES
status['task_state'] = instructor_task.task_state if instructor_task.task_output is not None:
status['in_progress'] = instructor_task.task_state not in READY_STATES status['task_progress'] = json.loads(instructor_task.task_output)
return status return status
......
...@@ -36,6 +36,14 @@ class InstructorTaskReportTest(InstructorTaskTestCase): ...@@ -36,6 +36,14 @@ class InstructorTaskReportTest(InstructorTaskTestCase):
output = json.loads(response.content) output = json.loads(response.content)
self.assertEquals(output['task_id'], task_id) self.assertEquals(output['task_id'], task_id)
def test_missing_instructor_task_status(self):
task_id = "missing_id"
request = Mock()
request.REQUEST = {'task_id': task_id}
response = instructor_task_status(request)
output = json.loads(response.content)
self.assertEquals(output, {})
def test_instructor_task_status_list(self): def test_instructor_task_status_list(self):
# Fetch status for existing tasks by arg list, as if called from ajax. # Fetch status for existing tasks by arg list, as if called from ajax.
# Note that ajax does something funny with the marshalling of # Note that ajax does something funny with the marshalling of
......
...@@ -17,6 +17,23 @@ log = logging.getLogger(__name__) ...@@ -17,6 +17,23 @@ log = logging.getLogger(__name__)
STATES_WITH_STATUS = [state for state in READY_STATES] + [PROGRESS] STATES_WITH_STATUS = [state for state in READY_STATES] + [PROGRESS]
def _get_instructor_task_status(task_id):
"""
Returns status for a specific task.
Written as an internal method here (rather than as a helper)
so that get_task_completion_info() can be called without
causing a circular dependency (since it's also called directly).
"""
instructor_task = get_updated_instructor_task(task_id)
status = get_status_from_instructor_task(instructor_task)
if instructor_task is not None and instructor_task.task_state in STATES_WITH_STATUS:
succeeded, message = get_task_completion_info(instructor_task)
status['message'] = message
status['succeeded'] = succeeded
return status
def instructor_task_status(request): def instructor_task_status(request):
""" """
View method that returns the status of a course-related task or tasks. View method that returns the status of a course-related task or tasks.
...@@ -57,30 +74,15 @@ def instructor_task_status(request): ...@@ -57,30 +74,15 @@ def instructor_task_status(request):
'traceback': optional, returned if task failed and produced a traceback. 'traceback': optional, returned if task failed and produced a traceback.
""" """
def get_instructor_task_status(task_id):
"""
Returns status for a specific task.
Written as an internal method here (rather than as a helper)
so that get_task_completion_info() can be called without
causing a circular dependency (since it's also called directly).
"""
instructor_task = get_updated_instructor_task(task_id)
status = get_status_from_instructor_task(instructor_task)
if instructor_task.task_state in STATES_WITH_STATUS:
succeeded, message = get_task_completion_info(instructor_task)
status['message'] = message
status['succeeded'] = succeeded
return status
output = {} output = {}
if 'task_id' in request.REQUEST: if 'task_id' in request.REQUEST:
task_id = request.REQUEST['task_id'] task_id = request.REQUEST['task_id']
output = get_instructor_task_status(task_id) output = _get_instructor_task_status(task_id)
elif 'task_ids[]' in request.REQUEST: elif 'task_ids[]' in request.REQUEST:
tasks = request.REQUEST.getlist('task_ids[]') tasks = request.REQUEST.getlist('task_ids[]')
for task_id in tasks: for task_id in tasks:
task_output = get_instructor_task_status(task_id) task_output = _get_instructor_task_status(task_id)
if task_output is not None: if task_output is not None:
output[task_id] = task_output output[task_id] = task_output
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment