Merge pull request #2275 from edx/usman/lms1494-progress-page-value-errors
For capa modules if weight is 0 don't try to create Progress objects.
This commit is contained in:
@@ -328,6 +328,10 @@ class CapaMixin(CapaFields):
|
||||
|
||||
if total > 0:
|
||||
if self.weight is not None:
|
||||
# Progress objects expect total > 0
|
||||
if self.weight == 0:
|
||||
return None
|
||||
|
||||
# scale score and total by weight/total:
|
||||
score = score * self.weight / total
|
||||
total = self.weight
|
||||
|
||||
@@ -1349,6 +1349,18 @@ class CapaModuleTest(unittest.TestCase):
|
||||
mock_log.exception.assert_called_once_with('Got bad progress')
|
||||
mock_log.reset_mock()
|
||||
|
||||
@patch('xmodule.capa_base.Progress')
|
||||
def test_get_progress_no_error_if_weight_zero(self, mock_progress):
|
||||
"""
|
||||
Check that if the weight is 0 get_progress does not try to create a Progress object.
|
||||
"""
|
||||
mock_progress.return_value = True
|
||||
module = CapaFactory.create()
|
||||
module.weight = 0
|
||||
progress = module.get_progress()
|
||||
self.assertIsNone(progress)
|
||||
self.assertFalse(mock_progress.called)
|
||||
|
||||
@patch('xmodule.capa_base.Progress')
|
||||
def test_get_progress_calculate_progress_fraction(self, mock_progress):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user