Skip to content

Commit

Permalink
scores must be positive (#29)
Browse files Browse the repository at this point in the history
* scores must be positive
  • Loading branch information
jansenk authored Sep 6, 2019
1 parent 9513b47 commit 86bf985
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Unreleased

*

[0.5.10] - 2019-09-06
~~~~~~~~~~~~~~~~~~~~~
* Prevent user from setting negative grades

[0.5.9] - 2019-08-28
~~~~~~~~~~~~~~~~~~~~
* Make intervention report display either grade override if exists or original grade.
Expand Down
2 changes: 1 addition & 1 deletion bulk_grades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = '0.5.9'
__version__ = '0.5.10'

default_app_config = 'bulk_grades.apps.BulkGradesConfig' # pylint: disable=invalid-name
4 changes: 4 additions & 0 deletions bulk_grades/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def preprocess_row(self, row):
operation['new_grade'] = float(value)
except ValueError:
raise ValidationError(_('Grade must be a number'))
if operation['new_grade'] < 0:
raise ValidationError(_('Grade must be positive'))
self._users_seen.add(row['user_id'])
return operation

Expand Down Expand Up @@ -479,6 +481,8 @@ def set_score(usage_key, student_id, score, max_points, override_user_id=None, *
if not isinstance(usage_key, UsageKey):
usage_key = UsageKey.from_string(usage_key)
defaults['module_type'] = 'problem'
if score < 0:
raise ValueError(_('score must be positive'))
defaults['grade'] = score
defaults['max_grade'] = max_points
module = apps.get_model('courseware', 'StudentModule').objects.update_or_create(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def test_set_score(self):
score = api.get_score(self.block_id, 11)
assert score is None

def test_negative_score(self):
with self.assertRaisesMessage(ValueError, 'score must be positive'):
api.set_score(self.block_id, self.learner.id, -2, 22, override_user_id=self.staff.id)


class TestScoreProcessor(BaseTests):
"""
Expand Down Expand Up @@ -163,6 +167,23 @@ def test_course_grade_filters(self, course_grade_factory_mock):
rows = list(processor.get_iterator())
self.assertEqual(len(rows), self.NUM_USERS+1)

@patch('lms.djangoapps.grades.api.CourseGradeFactory.read')
def test_less_than_zero(self, course_grade_factory_mock):
self._make_enrollments()

course_grade_factory_mock.return_value = Mock(percent=0.50)
processor = api.GradeCSVProcessor(course_id=self.course_id)

row = {
'block_id': self.block_id,
'new_grade-block-v1': '-1',
'user_id': self.learner.id,
'csum': '07ec',
'Previous Points': '',
}
with self.assertRaisesMessage(ValidationError, 'Grade must be positive'):
processor.preprocess_row(row)


class TestInterventionProcessor(BaseTests):
"""
Expand Down

0 comments on commit 86bf985

Please sign in to comment.