Commit 8660c9a7 by Brian Wilson

Check descriptor to identify problems that don't support regrading.

parent 73b25e1f
...@@ -823,7 +823,7 @@ class CapaModule(CapaFields, XModule): ...@@ -823,7 +823,7 @@ class CapaModule(CapaFields, XModule):
{'success' : 'correct' | 'incorrect' | AJAX alert msg string } {'success' : 'correct' | 'incorrect' | AJAX alert msg string }
Raises NotFoundError if called on a problem that has not yet been Raises NotFoundError if called on a problem that has not yet been
answered, or if it's a problem that cannot be regraded. answered, or NotImplementedError if it's a problem that cannot be regraded.
Returns the error messages for exceptions occurring while performing Returns the error messages for exceptions occurring while performing
the regrading, rather than throwing them. the regrading, rather than throwing them.
...@@ -835,7 +835,7 @@ class CapaModule(CapaFields, XModule): ...@@ -835,7 +835,7 @@ class CapaModule(CapaFields, XModule):
if not self.lcp.supports_regrading(): if not self.lcp.supports_regrading():
event_info['failure'] = 'unsupported' event_info['failure'] = 'unsupported'
self.system.track_function('problem_regrade_fail', event_info) self.system.track_function('problem_regrade_fail', event_info)
raise NotFoundError('Problem does not support regrading') raise NotImplementedError("Problem's definition does not support regrading")
if not self.done: if not self.done:
event_info['failure'] = 'unanswered' event_info['failure'] = 'unanswered'
......
...@@ -642,13 +642,12 @@ class CapaModuleTest(unittest.TestCase): ...@@ -642,13 +642,12 @@ class CapaModuleTest(unittest.TestCase):
module.regrade_problem() module.regrade_problem()
def test_regrade_problem_not_supported(self): def test_regrade_problem_not_supported(self):
# Simulate that the problem is NOT done
module = CapaFactory.create(done=True) module = CapaFactory.create(done=True)
# Try to regrade the problem, and get exception # Try to regrade the problem, and get exception
with patch('capa.capa_problem.LoncapaProblem.supports_regrading') as mock_supports_regrading: with patch('capa.capa_problem.LoncapaProblem.supports_regrading') as mock_supports_regrading:
mock_supports_regrading.return_value = False mock_supports_regrading.return_value = False
with self.assertRaises(xmodule.exceptions.NotFoundError): with self.assertRaises(NotImplementedError):
module.regrade_problem() module.regrade_problem()
def test_regrade_problem_error(self): def test_regrade_problem_error(self):
...@@ -668,7 +667,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -668,7 +667,7 @@ class CapaModuleTest(unittest.TestCase):
# Expect an AJAX alert message in 'success' # Expect an AJAX alert message in 'success'
expected_msg = 'Error: test error' expected_msg = 'Error: test error'
self.assertEqual(expected_msg, result['success']) self.assertEqual(result['success'], expected_msg)
# Expect that the number of attempts is NOT incremented # Expect that the number of attempts is NOT incremented
self.assertEqual(module.attempts, 1) self.assertEqual(module.attempts, 1)
......
...@@ -297,6 +297,26 @@ def _get_task_completion_message(course_task_log_entry): ...@@ -297,6 +297,26 @@ def _get_task_completion_message(course_task_log_entry):
########### Add task-submission methods here: ########### Add task-submission methods here:
def _check_arguments_for_regrading(course_id, problem_url):
"""
Do simple checks on the descriptor to confirm that it supports regrading.
Confirms first that the problem_url is defined (since that's currently typed
in). An ItemNotFoundException is raised if the corresponding module
descriptor doesn't exist. NotImplementedError is returned if the
corresponding module doesn't support regrading calls.
"""
descriptor = modulestore().get_instance(course_id, problem_url)
supports_regrade = False
if hasattr(descriptor,'module_class'):
module_class = descriptor.module_class
if hasattr(module_class, 'regrade_problem'):
supports_regrade = True
if not supports_regrade:
msg = "Specified module does not support regrading."
raise NotImplementedError(msg)
def submit_regrade_problem_for_student(request, course_id, problem_url, student): def submit_regrade_problem_for_student(request, course_id, problem_url, student):
""" """
...@@ -309,10 +329,8 @@ def submit_regrade_problem_for_student(request, course_id, problem_url, student) ...@@ -309,10 +329,8 @@ def submit_regrade_problem_for_student(request, course_id, problem_url, student)
An exception is thrown if the problem doesn't exist, or if the particular An exception is thrown if the problem doesn't exist, or if the particular
problem is already being regraded for this student. problem is already being regraded for this student.
""" """
# check arguments: make sure that the problem_url is defined # check arguments: let exceptions return up to the caller.
# (since that's currently typed in). If the corresponding module descriptor doesn't exist, _check_arguments_for_regrading(course_id, problem_url)
# an exception will be raised. Let it pass up to the caller.
modulestore().get_instance(course_id, problem_url)
task_name = 'regrade_problem' task_name = 'regrade_problem'
...@@ -341,14 +359,11 @@ def submit_regrade_problem_for_all_students(request, course_id, problem_url): ...@@ -341,14 +359,11 @@ def submit_regrade_problem_for_all_students(request, course_id, problem_url):
An exception is thrown if the problem doesn't exist, or if the particular An exception is thrown if the problem doesn't exist, or if the particular
problem is already being regraded. problem is already being regraded.
""" """
# check arguments: make sure that the problem_url is defined # check arguments: let exceptions return up to the caller.
# (since that's currently typed in). If the corresponding module descriptor doesn't exist, _check_arguments_for_regrading(course_id, problem_url)
# an exception will be raised. Let it pass up to the caller.
modulestore().get_instance(course_id, problem_url)
task_name = 'regrade_problem'
# check to see if task is already running, and reserve it otherwise # check to see if task is already running, and reserve it otherwise
task_name = 'regrade_problem'
course_task_log = _reserve_task(course_id, task_name, problem_url, request.user) course_task_log = _reserve_task(course_id, task_name, problem_url, request.user)
# Submit task: # Submit task:
......
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