Example #1
0
 def test_load_1(self):
     v = votation_dao.votation_dto()
     v.votation_description = 'Guar automated test ' + str(random.randint(1,500))
     v.votation_type = 'random'
     v.promoter_user.user_id = 2
     v.begin_date = '2018-01-01'
     v.end_date = '2018-01-15'
     v.votation_status = 1
     votation_dao.insert_votation_dto(v)
     g = guarantor.guarantor_dto()
     g.votation_id = v.votation_id
     g.u.user_id = 1
     g.hash_ok = 1
     g.passphrase_ok = 0
     guarantor.insert_dto(g)
     g = guarantor.guarantor_dto()
     g.votation_id = v.votation_id
     g.u.user_id = 3
     g.hash_ok = 0
     g.passphrase_ok = 0
     guarantor.insert_dto(g)
     g1 = guarantor.load_guarantor(v.votation_id, g.u.user_id)
     self.assertEqual(g.votation_id, g1.votation_id)
     self.assertEqual(g.u.user_id , g1.u.user_id )
     self.assertEqual(g.hash_ok , g1.hash_ok )
     self.assertEqual(g.passphrase_ok , g1.passphrase_ok )
Example #2
0
 def test_insert_duplicate_description(self):
     DESCRIPTION = "Duplicate description test"
     ar = votation_dao.load_votations()
     for old_votation in ar:
         if old_votation.votation_description == DESCRIPTION:
             votation_bo.deltree_votation_by_id(old_votation.votation_id)
     v = Votation( \
         votation_description = DESCRIPTION , \
         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 = votation_dao.STATUS_WAIT_FOR_CAND_AND_GUAR , \
         list_voters = 0)
     self.assertTrue( votation_dao.insert_votation_dto(v) )
     db.session.commit()
     v1 = Votation( \
         votation_description = DESCRIPTION , \
         description_url = 'ciao' , \
         votation_type = votation_dao.TYPE_SIMPLE_MAJORITY , \
         promoter_user_id = 2 , \
         begin_date = datetime(2018,1,2) , \
         end_date = datetime(2018,1,16) , \
         votation_status = votation_dao.STATUS_WAIT_FOR_CAND_AND_GUAR , \
         list_voters = 0)
     self.assertFalse( votation_dao.insert_votation_dto(v1) )
     db.session.rollback()
     votation_dao.delete_votation_by_id(v.votation_id)
     db.session.commit()
Example #3
0
 def test_insert_votation_and_options_3(self):
     """Duplicate description of votation"""
     descr = 'Votation and options duplicate description ' + str(random.randint(0,500))
     v = Votation( \
         votation_description = descr , \
         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 = 0)
     votation_dao.insert_votation_dto(v)
     db.session.commit()
     v = Votation( \
         votation_description = descr , \
         description_url = "hello" , \
         votation_type = votation_dao.TYPE_SIMPLE_MAJORITY , \
         promoter_user_id = 2 , \
         begin_date = datetime(2018,1,2) , \
         end_date = datetime(2018,1,28) , \
         votation_status = 1 , \
         list_voters = 1)
     txt_options = "option_test_X\noption_test_Y\n option_test_Z"
     txt_judgements = "judgment_test_A\njudgment_test_B\n judgment_test_C"
     result = votation_bo.insert_votation_with_options(v,txt_options,txt_judgements)
     self.assertEqual(MSG_KO,result[1])
     ar = votation_dao.load_votations()
     check = False
     for w in ar:
         if w.votation_description == descr and w.promoter_user_id == 2:
             check = True
     self.assertFalse(check)
Example #4
0
def insert_votation_with_options(v, options_text, judgement_text):
    """Save votation and options.
    Options_text is a string like "A\nB\nC"
    Judgement_text is a string like "A\nB\nC" as well
    Returns a couple (string,int) -> ('Saved', MSG_OK) or (error description, MSG_KO) 
    """
    bok, errmsg = votation_dao.validate_dto(v)
    if v.votation_type == votation_dao.TYPE_SIMPLE_MAJORITY:
        judgement_text = "VOTED\nNOT VOTED"
    if bok:
        result = ("Election data saved", MSG_OK)
        if votation_dao.insert_votation_dto(v):
            if option_dao.save_options_from_text(v.votation_id, options_text):
                if judgement_dao.save_judgements_from_text(
                        v.votation_id, judgement_text):
                    pass
                else:
                    result = ('Cannot save judgements', MSG_KO)
            else:
                result = ('Cannot save options', MSG_KO)
        else:
            result = ('Cannot save the election', MSG_KO)
    else:
        result = (errmsg, MSG_KO)
    if result[1] == MSG_OK:
        db.session.commit()
    else:
        db.session.rollback()
    return result
Example #5
0
 def test_insert(self):
     #print("VOTATION TEST")
     v = Votation( \
         votation_description = 'Votation automated test ' + str(random.randint(0,500)) , \
         description_url = "" , \
         votation_type = votation_dao.TYPE_DRAW , \
         promoter_user_id = 1 , \
         begin_date = datetime(2018,1,1) , \
         end_date = datetime(2018,1,15) , \
         votation_status = 2 , \
         list_voters = 0)
     self.assertTrue( votation_dao.insert_votation_dto(v) )
     self.assertGreater(v.votation_id,0)
     v1 = votation_dao.load_votation_by_id(v.votation_id)
     self.assertIsNotNone(v1)
     self.assertIsNotNone(v1.promoter_user)
     self.assertEqual(v.votation_id, v1.votation_id)
     self.assertEqual(v.votation_description, v1.votation_description)
     self.assertEqual(v.votation_type, v1.votation_type)
     self.assertEqual(v.promoter_user.user_id, v1.promoter_user.user_id)
     self.assertEqual(v.begin_date, v1.begin_date)
     self.assertEqual(v.end_date, v1.end_date)
     votation_dao.delete_votation_by_id(v.votation_id)
     v1 = votation_dao.load_votation_by_id(v.votation_id)
     self.assertIsNone(v1)
Example #6
0
 def setUp(self):
     self.__votation__ = Votation( \
         votation_description = 'Votation for option test ' + str(random.randint(0,50000)) , \
         description_url = "" , \
         votation_type = votation_dao.TYPE_DRAW , \
         promoter_user_id = 1 , \
         begin_date = datetime(2018,1,1) , \
         end_date = datetime(2018,1,15) , \
         votation_status = 2 , \
         list_voters = 0)
     self.assertTrue( votation_dao.insert_votation_dto(self.__votation__) )
     db.session.commit()
     return super().setUp()
Example #7
0
 def test_hash_complete_no_2(self):
     v = votation_dao.votation_dto()
     v.votation_description = 'Guar automated test ' + str(random.randint(1,500))
     v.votation_type = 'random'
     v.promoter_user.user_id = 2
     v.begin_date = '2018-01-01'
     v.end_date = '2018-01-15'
     v.votation_status = 1
     votation_dao.insert_votation_dto(v)
     g = guarantor.guarantor_dto()
     g.votation_id = v.votation_id
     g.u.user_id = 1
     g.hash_ok = 1
     g.passphrase_ok = 0
     guarantor.insert_dto(g)
     g = guarantor.guarantor_dto()
     g.votation_id = v.votation_id
     g.u.user_id = 3
     g.hash_ok = 0
     g.passphrase_ok = 0
     guarantor.insert_dto(g)
     self.assertFalse(guarantor.guarantors_hash_complete(v.votation_id))
Example #8
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()
Example #9
0
 def test_update_end_date(self):
     v = Votation( \
         votation_description = 'Update end date test ' + str(random.randint(0,500)) , \
         description_url = '' , \
         votation_type = votation_dao.TYPE_SIMPLE_MAJORITY , \
         promoter_user_id = 1 , \
         begin_date = datetime(2018,1,1) , \
         end_date = datetime(2018,2,1) , \
         votation_status = votation_dao.STATUS_WAIT_FOR_CAND_AND_GUAR , \
         list_voters = 0)
     self.assertTrue( votation_dao.insert_votation_dto(v) )
     new_end_date = datetime(2019,12,31,8,34)
     votation_bo.update_end_date(v.votation_id, new_end_date)
     v2 = votation_dao.load_votation_by_id(v.votation_id)
     self.assertEqual(new_end_date, v2.end_date)
     votation_bo.deltree_votation_by_id(v.votation_id)