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()
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)
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)
def test_insert_votation_and_options_1(self): descr = 'Votation and options 1 automated test ' + str(random.randint(0,500)) v = Votation( \ votation_description = descr , \ description_url = "" , \ votation_type = votation_dao.TYPE_MAJORITY_JUDGMENT , \ promoter_user_id = 1 , \ begin_date = datetime(2018,1,1) , \ end_date = datetime(2018,1,15) , \ votation_status = 2 , \ list_voters = 0) txt_options = "option_test_A\noption_test_B\n option_test_C" 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_OK,result[1]) ar = votation_dao.load_votations() check = False for w in ar: if w.votation_description == descr: check = True break self.assertTrue(check) opt_ar = option_dao.load_options_by_votation(w.votation_id) self.assertEqual(3,len(opt_ar)) jud_ar = judgement_dao.load_judgement_by_votation(w.votation_id) self.assertEqual(3,len(jud_ar)) votation_bo.deltree_votation_by_id(w.votation_id)
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()
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()
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)
def test_insert_votation_and_options_2(self): """Begin an end dates are in the wrong order""" descr = 'Votation and options 2 automated test ' + 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,2,1) , \ end_date = datetime(2018,1,15) , \ votation_status = 2 , \ list_voters = 0) txt_options = "option_test_A\noption_test_B\n option_test_C" 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: check = True self.assertFalse(check)
def votation_propose(): v = Votation() message = (_("Please, insert data"), MSG_INFO) if request.method == 'POST': #v.votation_id = request.form['votation_id'] v.votation_description = request.form['votation_description'] v.description_url = request.form['description_url'] v.begin_date = request.form['begin_date'] + " " + request.form[ 'begin_time'] v.end_date = request.form['end_date'] + " " + request.form['end_time'] v.votation_type = request.form['votation_type'] v.list_voters = 0 if 'list_voters' in request.form.keys(): v.list_voters = request.form['list_voters'] v.promoter_user_id = current_user.u.user_id if v.votation_type == votation_dao.TYPE_DRAW: v.votation_status = votation_dao.STATUS_WAIT_FOR_CAND_AND_GUAR else: v.votation_status = votation_dao.STATUS_VOTING message = votation_bo.insert_votation_with_options( v, request.form['votation_options'], request.form['votation_juds']) return render_template('votation_propose_template.html', pagetitle=_("New election"), \ votation_obj=v, message=message,utcnow=str(datetime.datetime.utcnow()) )