From 198f09801c69a6daaaf15b9b4ce6ae98076bdec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Thu, 11 Feb 2016 18:02:57 +0100 Subject: [PATCH] Fixed error in poll default_votes_validator. Fixed #1967. --- openslides/poll/serializers.py | 4 +++- tests/integration/assignments/test_viewset.py | 7 +++++++ tests/integration/motions/test_viewset.py | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/openslides/poll/serializers.py b/openslides/poll/serializers.py index 82d4a6a6f..e9432537a 100644 --- a/openslides/poll/serializers.py +++ b/openslides/poll/serializers.py @@ -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 diff --git a/tests/integration/assignments/test_viewset.py b/tests/integration/assignments/test_viewset.py index 5c3ff649c..e209a23fe 100644 --- a/tests/integration/assignments/test_viewset.py +++ b/tests/integration/assignments/test_viewset.py @@ -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) diff --git a/tests/integration/motions/test_viewset.py b/tests/integration/motions/test_viewset.py index 81c14df24..aa02f9163 100644 --- a/tests/integration/motions/test_viewset.py +++ b/tests/integration/motions/test_viewset.py @@ -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)