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:
Usman Khalid
2014-01-31 02:18:16 -08:00
2 changed files with 16 additions and 0 deletions

View File

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

View File

@@ -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):
"""