Browse Source

valid number of votes

master
Julio Biason 11 years ago
parent
commit
3b42b68db9
  1. 9
      luncho/blueprints/voting.py
  2. 19
      tests/vote_tests.py

9
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

19
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()

Loading…
Cancel
Save