Merge pull request #1968 from normanjaeckel/FixDefaultVotesError

Fixed error in poll default_votes_validator. Fixed #1967.
This commit is contained in:
Emanuel Schütze 2016-02-11 20:47:35 +01:00
commit ea4d3a2d75
3 changed files with 17 additions and 1 deletions

View File

@ -10,6 +10,8 @@ def default_votes_validator(data):
than or equal to -2.
"""
for key in data:
if key in ('votesvalid', 'votesinvalid', 'votescast') and data[key] < -2:
if (key in ('votesvalid', 'votesinvalid', 'votescast') and
data[key] is not None and
data[key] < -2):
raise ValidationError({'detail': _('Value for {} must not be less than -2').format(key)})
return data

View File

@ -307,3 +307,10 @@ class UpdateAssignmentPoll(TestCase):
{'assignment_id': self.assignment.pk,
'votescast': '-3'})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_empty_value_for_votesvalid(self):
response = self.client.put(
reverse('assignmentpoll-detail', args=[self.poll.pk]),
{'assignment_id': self.assignment.pk,
'votesvalid': ''})
self.assertEqual(response.status_code, status.HTTP_200_OK)

View File

@ -395,3 +395,10 @@ class UpdateMotionPoll(TestCase):
{'motion_id': self.motion.pk,
'votescast': '-3'})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_empty_value_for_votesvalid(self):
response = self.client.put(
reverse('motionpoll-detail', args=[self.poll.pk]),
{'motion_id': self.motion.pk,
'votesvalid': ''})
self.assertEqual(response.status_code, status.HTTP_200_OK)