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_insert(self): votation_id = self.__votation__.votation_id u = Option(votation_id=votation_id,option_name = 'test.option') self.assertTrue( option_dao.insert_dto(u)) self.assertGreater(u.option_id, 0) ar = option_dao.load_options_by_votation(votation_id) self.assertEqual(1,len(ar)) u1 = ar[0] self.assertIsNotNone(u1) self.assertEqual(u.votation_id, u1.votation_id) self.assertEqual(u.option_name, u1.option_name) self.assertTrue(option_dao.delete_dto(u1)) ar = option_dao.load_options_by_votation(votation_id) self.assertEqual(0,len(ar))