Commit fd206a41 by Brian Wilson

Make sure InstructorTask is committed.

parent 5389bba4
...@@ -658,11 +658,11 @@ class CapaModuleTest(unittest.TestCase): ...@@ -658,11 +658,11 @@ class CapaModuleTest(unittest.TestCase):
# Simulate answering a problem that raises the exception # Simulate answering a problem that raises the exception
with patch('capa.capa_problem.LoncapaProblem.rescore_existing_answers') as mock_rescore: with patch('capa.capa_problem.LoncapaProblem.rescore_existing_answers') as mock_rescore:
mock_rescore.side_effect = exception_class(u'test error u\03a9') mock_rescore.side_effect = exception_class(u'test error \u03a9')
result = module.rescore_problem() result = module.rescore_problem()
# Expect an AJAX alert message in 'success' # Expect an AJAX alert message in 'success'
expected_msg = u'Error: test error u\03a9' expected_msg = u'Error: test error \u03a9'
self.assertEqual(result['success'], expected_msg) self.assertEqual(result['success'], expected_msg)
# Expect that the number of attempts is NOT incremented # Expect that the number of attempts is NOT incremented
......
...@@ -91,7 +91,7 @@ class InstructorTask(models.Model): ...@@ -91,7 +91,7 @@ class InstructorTask(models.Model):
task_input=json_task_input, task_input=json_task_input,
task_state=QUEUING, task_state=QUEUING,
requester=requester) requester=requester)
instructor_task.save() instructor_task.save_now()
return instructor_task return instructor_task
...@@ -125,6 +125,7 @@ class InstructorTask(models.Model): ...@@ -125,6 +125,7 @@ class InstructorTask(models.Model):
Truncation is indicated by adding "..." to the end of the value. Truncation is indicated by adding "..." to the end of the value.
""" """
tag = '...'
task_progress = {'exception': type(exception).__name__, 'message': str(exception.message)} task_progress = {'exception': type(exception).__name__, 'message': str(exception.message)}
if traceback_string is not None: if traceback_string is not None:
# truncate any traceback that goes into the InstructorTask model: # truncate any traceback that goes into the InstructorTask model:
...@@ -135,17 +136,17 @@ class InstructorTask(models.Model): ...@@ -135,17 +136,17 @@ class InstructorTask(models.Model):
too_long = len(json_output) - 1023 too_long = len(json_output) - 1023
if too_long > 0: if too_long > 0:
if traceback_string is not None: if traceback_string is not None:
if too_long >= len(traceback_string) - len('...'): if too_long >= len(traceback_string) - len(tag):
# remove the traceback entry entirely (so no key or value) # remove the traceback entry entirely (so no key or value)
del task_progress['traceback'] del task_progress['traceback']
too_long -= (len(traceback_string) + len('traceback')) too_long -= (len(traceback_string) + len('traceback'))
else: else:
# truncate the traceback: # truncate the traceback:
task_progress['traceback'] = traceback_string[:-(too_long + 3)] + "..." task_progress['traceback'] = traceback_string[:-(too_long + len(tag))] + tag
too_long = -1 too_long = 0
if too_long > 0: if too_long > 0:
# we need to shorten the message: # we need to shorten the message:
task_progress['message'] = task_progress['message'][:-(too_long + 3)] + "..." task_progress['message'] = task_progress['message'][:-(too_long + len(tag))] + tag
json_output = json.dumps(task_progress) json_output = json.dumps(task_progress)
return json_output return json_output
......
...@@ -109,10 +109,10 @@ class InstructorTaskSubmitTest(InstructorTaskModuleTestCase): ...@@ -109,10 +109,10 @@ class InstructorTaskSubmitTest(InstructorTaskModuleTestCase):
location = InstructorTaskModuleTestCase.problem_location(problem_url_name) location = InstructorTaskModuleTestCase.problem_location(problem_url_name)
if student is not None: if student is not None:
instructor_task = task_function(self.create_task_request(self.instructor), instructor_task = task_function(self.create_task_request(self.instructor),
self.course.id, location, student) self.course.id, location, student)
else: else:
instructor_task = task_function(self.create_task_request(self.instructor), instructor_task = task_function(self.create_task_request(self.instructor),
self.course.id, location) self.course.id, location)
# test resubmitting, by updating the existing record: # test resubmitting, by updating the existing record:
instructor_task = InstructorTask.objects.get(id=instructor_task.id) instructor_task = InstructorTask.objects.get(id=instructor_task.id)
......
...@@ -205,8 +205,8 @@ function goto( mode) ...@@ -205,8 +205,8 @@ function goto( mode)
</p> </p>
<p> <p>
You may use just the "urlname" if a problem, or "modulename/urlname" if not. You may use just the "urlname" if a problem, or "modulename/urlname" if not.
(For example, if the location is <tt>i4x://university/course/problem/problemname</tt>, (For example, if the location is <tt>i4x://university/course/problem/problemname</tt>,
then just provide the <tt>problemname</tt>. then just provide the <tt>problemname</tt>.
If the location is <tt>i4x://university/course/notaproblem/someothername</tt>, then If the location is <tt>i4x://university/course/notaproblem/someothername</tt>, then
provide <tt>notaproblem/someothername</tt>.) provide <tt>notaproblem/someothername</tt>.)
</p> </p>
...@@ -241,8 +241,8 @@ function goto( mode) ...@@ -241,8 +241,8 @@ function goto( mode)
</p> </p>
<p> <p>
You may use just the "urlname" if a problem, or "modulename/urlname" if not. You may use just the "urlname" if a problem, or "modulename/urlname" if not.
(For example, if the location is <tt>i4x://university/course/problem/problemname</tt>, (For example, if the location is <tt>i4x://university/course/problem/problemname</tt>,
then just provide the <tt>problemname</tt>. then just provide the <tt>problemname</tt>.
If the location is <tt>i4x://university/course/notaproblem/someothername</tt>, then If the location is <tt>i4x://university/course/notaproblem/someothername</tt>, then
provide <tt>notaproblem/someothername</tt>.) provide <tt>notaproblem/someothername</tt>.)
</p> </p>
......
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