Esempio n. 1
0
    def test_check_inputFile(self):

        THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
        filePath = THIS_FOLDER + '/docs/CandidatesFiles/Candidatos_Senado.xlsx'
        # my_file = os.path.join(THIS_FOLDER + '/docs/CandidatesFiles/',
        #  'Candidatos_Senado.xlsx')

        # Test positivo
        Voting.checkInputFile(filePath)

        # Test negativo. Un candidato no ha pasado por el proceso de primarias
        filePath = THIS_FOLDER + '/docs/CandidatesFiles/Candidatos_Senado2.xlsx'
        try:
            Voting.checkInputFile(filePath)
        except:
            print('Test negativo de proceso de primarias correcto')

        # Test negativo. Faltan provincias con candidatos
        filePath = THIS_FOLDER + '/docs/CandidatesFiles/Candidatos_Senado3.xlsx'
        try:
            Voting.checkInputFile(filePath)
        except:
            print('Test negativo de provincias correcto')

        # Test negativo. No hay 6 candidatos/provincia/partido político
        # ni relación 1/2 entre hombres y mujeres
        filePath = THIS_FOLDER + '/docs/CandidatesFiles/Candidatos_Senado4.xlsx'
        try:
            Voting.checkInputFile(filePath)
        except:
            print('Test negativo de 6 candidatos/provincia/partido político' +
                  'yrelación 1/2 correcto')
Esempio n. 2
0
    def save(self):
        candidate_file = self.cleaned_data.get('candidate_file', None)
        df = Voting.checkInputFile(candidate_file)
        auth = Auth.objects.get_or_create(url=settings.BASEURL, name='Sys')[0]

        for name, group in df.groupby(['Provincia']):
            count = 2

            quest = Question(desc='Elige un máximo de 2 personas para las '
                             'listas al senado por ' + name)
            quest.save()

            voting_name = 'Votación Senado ' + name
            voting_desc = 'Listas al Senado por ' + name
            voting = Voting(name=voting_name, desc=voting_desc, question=quest)
            voting.save()
            voting.auths.add(auth)

            for row in group.iterrows():
                count += 1
                desc_option = row[1][5] + ': ' + \
                              row[1][0] + ' ' + row[1][1] + ' ' + row[1][2]

                quest_option = QuestionOption(number=count, option=desc_option)
                quest_option.question = quest
                quest_option.save()