def test_save_wrong_array(self): vote_key = 'vote_key' + str(random.randint(0, 50000)) self.assertFalse( vote_bo.save_votes(user_id = 1, \ vote_key=vote_key, \ votation_id=self.__votation__.votation_id, \ vote_array=[1,2]) ) self.assertFalse( vote_bo.save_votes(user_id = 1, \ vote_key=vote_key, \ votation_id=self.__votation__.votation_id, \ vote_array=[1,2,3,4]) )
def test_save_wrong_key(self): vote_key = 'vote_key' + str(random.randint(0, 50000)) # first vote self.assertTrue( vote_bo.save_votes(user_id = 1, \ vote_key=vote_key, \ votation_id=self.__votation__.votation_id, \ vote_array=[1,1,1]) ) ar = vote_dao.load_vote_by_key(vote_key) self.assertEqual(3, len(ar)) self.assertTrue(voter_dao.has_voted(1, self.__votation__.votation_id)) # second vote self.assertFalse( vote_bo.save_votes(user_id = 1, \ vote_key="WRONG KEY", \ votation_id=self.__votation__.votation_id, \ vote_array=[1,3,1]) )
def save_votes(user_id, vote_key,votation_id,vote_array): """ vote_array is an array of judgement values, integers. vote_array is like [4,5,6] where option 1 has 4 as judgment, option 2 has 4 and option 3 has 6. """ return vote_bo.save_votes(user_id, vote_key, votation_id, vote_array)
def test_save_ok(self): vote_key = 'vote_key' + str(random.randint(0, 50000)) self.assertTrue( vote_bo.save_votes(user_id = 1, \ vote_key=vote_key, \ votation_id=self.__votation__.votation_id, \ vote_array=[0,1,2]) ) ar = vote_dao.load_vote_by_key(vote_key) self.assertEqual(3, len(ar)) self.assertTrue(voter_dao.has_voted(1, self.__votation__.votation_id))
def save_vote(user_id, vote_key, votation_id, option_id): """ User choose only one option The jud is always 1 Insert an array of zeros with only one 1. """ option_list = option_dao.load_options_by_votation(votation_id) ar = [] for o in option_list: if o.option_id == option_id: ar.append(1) else: ar.append(0) return vote_bo.save_votes(user_id, vote_key, votation_id, ar)