Fixed error in poll default_votes_validator. Fixed #1967.

This commit is contained in:
Norman Jäckel 2016-02-11 18:02:57 +01:00
parent ad7653fb76
commit 198f09801c
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. than or equal to -2.
""" """
for key in data: 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)}) raise ValidationError({'detail': _('Value for {} must not be less than -2').format(key)})
return data return data

View File

@ -307,3 +307,10 @@ class UpdateAssignmentPoll(TestCase):
{'assignment_id': self.assignment.pk, {'assignment_id': self.assignment.pk,
'votescast': '-3'}) 'votescast': '-3'})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) 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, {'motion_id': self.motion.pk,
'votescast': '-3'}) 'votescast': '-3'})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) 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)