Пример #1
0
 def test_count_voters2(self):
     o = Voter(user_id=1,
               votation_id=self.__votation__.votation_id,
               voted=0)
     voter_dao.insert_dto(o)
     self.assertEqual(0, voter_dao.count_voters(o.votation_id))
     voter_dao.delete_dto(o)
Пример #2
0
 def test_is_voter(self):
     o = Voter(user_id=2,
               votation_id=self.__votation__.votation_id,
               voted=0)
     voter_dao.delete_dto(o)
     voter_dao.insert_dto(o)
     self.assertTrue(voter_dao.is_voter(o.votation_id, o.user_id))
     voter_dao.delete_dto(o)
Пример #3
0
 def test_insert2(self):
     o = Voter(user_id=1,
               votation_id=self.__votation__.votation_id,
               voted=0)
     voter_dao.delete_dto(o)
     self.assertFalse(voter_dao.has_voted(o.user_id, o.votation_id))
     voter_dao.insert_dto(o)
     self.assertFalse(voter_dao.has_voted(o.user_id, o.votation_id))
     voter_dao.delete_dto(o)
     self.assertFalse(voter_dao.has_voted(o.user_id, o.votation_id))
Пример #4
0
 def test_set_voted_with_list(self):
     # insert a voter
     o = Voter(user_id=2,
               votation_id=self.__votation_list__.votation_id,
               voted=0)
     self.assertFalse(voter_dao.is_voter(o.votation_id, o.user_id))
     voter_dao.insert_dto(o)
     self.assertTrue(voter_dao.is_voter(o.votation_id, o.user_id))
     # run set_voted()
     self.assertFalse(voter_dao.has_voted(o.user_id, o.votation_id))
     self.assertTrue(voter_dao.set_voted(o.user_id, o.votation_id))
     self.assertTrue(voter_dao.has_voted(o.user_id, o.votation_id))
Пример #5
0
 def setUp(self):
     self.__votation__ = Votation( \
         votation_description = 'Simple Votation with voters for vote test ' + str(random.randint(0,50000)) , \
         description_url = "" , \
         votation_type = votation_dao.TYPE_SIMPLE_MAJORITY , \
         promoter_user_id = 1 , \
         begin_date = datetime(2018,1,1) , \
         end_date = datetime(2018,1,15) , \
         votation_status = 2 , \
         list_voters = 1)
     self.assertTrue(votation_dao.insert_votation_dto(self.__votation__))
     o1 = Option(votation_id=self.__votation__.votation_id, \
          option_name = 'test.option1')
     self.assertTrue(option_dao.insert_dto(o1))
     o2 = Option(votation_id=self.__votation__.votation_id, \
          option_name = 'test.option2')
     self.assertTrue(option_dao.insert_dto(o2))
     o3 = Option(votation_id=self.__votation__.votation_id, \
          option_name = 'test.option3')
     self.assertTrue(option_dao.insert_dto(o3))
     self.__option1 = o1
     self.__option2 = o2
     self.__option3 = o3
     self.assertIsNotNone(o1.option_id)
     self.assertIsNotNone(o2.option_id)
     self.assertIsNotNone(o3.option_id)
     # set juds
     j1 = Judgement(votation_id = self.__votation__.votation_id, \
         jud_value = 0, jud_name = "bad")
     j2 = Judgement(votation_id = self.__votation__.votation_id, \
         jud_value = 1, jud_name = "medium")
     j3 = Judgement(votation_id = self.__votation__.votation_id, \
         jud_value = 2, jud_name = "good")
     judgement_dao.insert_dto(j1)
     judgement_dao.insert_dto(j2)
     judgement_dao.insert_dto(j3)
     db.session.commit()
     jud_array = judgement_dao.load_judgement_by_votation(
         self.__votation__.votation_id)
     self.__jud1 = jud_array[0]
     self.__jud2 = jud_array[1]
     self.__jud3 = jud_array[2]
     voter1 = Voter(user_id=1,
                    votation_id=self.__votation__.votation_id,
                    voted=0)
     voter_dao.insert_dto(voter1)
     db.session.commit()
     return super().setUp()
Пример #6
0
 def test_insert3(self):
     o1 = Voter(user_id=1,
                votation_id=self.__votation__.votation_id,
                voted=0)
     o2 = Voter(user_id=1,
                votation_id=self.__votation__.votation_id,
                voted=0)
     voter_dao.delete_dto(o1)
     self.assertTrue(voter_dao.insert_dto(o1))
     #self.assertFalse(voter_dao.insert_dto(o2)) this don't thrown errors in sqlalchemy
     voter_dao.delete_dto(o1)
Пример #7
0
def insert_voters_array(votation_id, ar):
    """returns number of inserted rows"""
    count = 0
    for user_name in ar:
        u = user.load_user_by_username(user_name)
        if u:
            n = db.session.query(Voter).filter(
                Voter.user_id == u.user_id,
                Voter.votation_id == votation_id).count()
            if n == 0:
                o = Voter(votation_id=votation_id, user_id=u.user_id, voted=0)
                if voter_dao.insert_dto(o):
                    count += 1
    if count > 0:
        db.session.commit()
    return count