From 3b42b68db920904a283777461508c030e59e6460 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 14 Apr 2014 09:54:55 -0300 Subject: [PATCH] valid number of votes --- luncho/blueprints/voting.py | 9 +++++---- tests/vote_tests.py | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/luncho/blueprints/voting.py b/luncho/blueprints/voting.py index 52758fe..3894ad6 100644 --- a/luncho/blueprints/voting.py +++ b/luncho/blueprints/voting.py @@ -61,7 +61,8 @@ class InvalidNumberOfPlacesCastedException(LunchoException): def __init__(self, places): super(InvalidNumberOfPlacesCastedException, self).__init__() self.status = 406 - self.message = 'The must register {places} places'.format(places) + self.message = 'The vote must register {places} places'.format( + places=places) class PlaceDoesntBelongToGroupException(LunchoException): @@ -181,9 +182,9 @@ def _check_place_count(choices, group_places): max_places = min(current_app.config['PLACES_IN_VOTE'], len(group_places)) if len(choices) != max_places: - LOG.debug('Max places = {max_places}, voted for {choices}', - max_places=max_places, choices=len(choices)) - raise InvalidNumberOfPlacesCastedException() + LOG.debug('Max places = {max_places}, voted for {choices}'.format( + max_places=max_places, choices=len(choices))) + raise InvalidNumberOfPlacesCastedException(max_places) return diff --git a/tests/vote_tests.py b/tests/vote_tests.py index 8f7c936..89a73d8 100644 --- a/tests/vote_tests.py +++ b/tests/vote_tests.py @@ -50,8 +50,25 @@ class TestVote(LunchoTests): rv = self.post('/vote/{group_id}/'.format(group_id=group.id), request, token=self.user.token) - print rv.data self.assertJsonOk(rv) + return + + def test_cast_less_votes(self): + """Try to cast a vote with not enough places.""" + group = self._group() + place1 = self._place() + place2 = self._place() + group.places.append(place1) + group.places.append(place2) + self.user.groups.append(group) + server.db.session.commit() + + request = {'choices': [place1.id]} + rv = self.post('/vote/{group_id}/'.format(group_id=group.id), + request, + token=self.user.token) + self.assertJsonError(rv, 406, 'The vote must register 2 places') + return if __name__ == '__main__': unittest.main()