From 3d377cd8ea61035658d81e9b99901c9ff4daa9cc Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 14 Apr 2014 20:55:23 -0300 Subject: [PATCH] cannot vote in the same day even in different groups --- tests/vote_tests.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/vote_tests.py b/tests/vote_tests.py index a569767..dda91b2 100644 --- a/tests/vote_tests.py +++ b/tests/vote_tests.py @@ -93,5 +93,36 @@ class TestVote(LunchoTests): self.assertJsonError(rv, 406, 'User already voted today') return + def test_already_vote_other_group(self): + """Try to vote in two different groups in the same day.""" + group1 = self._group() + place1 = self._place() + group1.places.append(place1) + self.user.groups.append(group1) + + group2 = self._group() + place2 = self._place() + group2.places.append(place2) + self.user.groups.append(group2) + server.db.session.commit() + + group1_id = group1.id + group2_id = group2.id + place1_id = place1.id + place2_id = place2.id + token = self.user.token + + request = {'choices': [place1_id]} + rv = self.post('/vote/{group_id}/'.format(group_id=group1_id), + request, + token=token) + self.assertJsonOk(rv) # first vote for the day + + request = {'choices': [place2_id]} + rv = self.post('/vote/{group_id}/'.format(group_id=group2_id), + request, + token=token) + self.assertJsonError(rv, 406, 'User already voted today') + if __name__ == '__main__': unittest.main()