Ejemplo n.º 1
0
    def testExistQuestionWithFailureOrdering(self):
        q = Question.objects.get(desc="Descripcion")
        q.save()

        q_order1 = QuestionOrdering(question=q,
                                    option="esta va a salir segunda",
                                    ordering=1)
        q_order1.save()
        q_order2 = QuestionOrdering(question=q,
                                    option="esta va a salir primera",
                                    ordering=2)
        q_order2.save()

        v = Voting(name="Prueba votacion ordenada", question=q)
        v.save()

        q_order1_postgres = Voting.objects.get(
            name="Prueba votacion ordenada").question.options_ordering.filter(
                option="esta va a salir segunda").get()
        q_order2_postgres = Voting.objects.get(
            name="Prueba votacion ordenada").question.options_ordering.filter(
                option="esta va a salir primera").get()

        self.assertNotEquals(q_order1_postgres.ordering, 2)
        self.assertNotEquals(q_order2_postgres.ordering, 1)
Ejemplo n.º 2
0
    def setUp(self):
        q = Question(desc="Descripcion")
        q.save()

        self.v = Voting(name="Votacion", question=q)
        self.v.save()
        super().setUp()
class VotingModelTC(BaseTestCase):
    def setUp(self):
        q = Question(desc="Descripcion", scopes="Geography")
        q.save()

        opt1 = QuestionOption(question=q, option="option1")
        opt1.save()

        opt2 = QuestionOption(question=q, option="option2")
        opt2.save()

        self.v = Voting(name="Votacion", question=q)
        self.v.save()
        super().setUp()

    def tearDown(self):
        super().tearDown()
        self.v = None

    def testExist(self):
        v = Voting.objects.get(name="Votacion")
        self.assertEquals(v.question.options.all()[0].option, "option1")
        self.assertEquals(v.question.options.all()[1].option, "option2")
        self.assertEquals(len(v.question.options.all()), 2)
        self.assertEquals(v.question.scopes, "Geography")

    def testCreateVotingAPI(self):
        self.login()
        data = {
            'name': 'Example',
            'themeVotation': 'Knowledge',
            'preference': 'High',
            'desc': 'Descripcion',
            'question': 'I wanna',
            'question_scopes': 'Geography',
            'question_opt': ['car', 'house', 'party']
        }

        response = self.client.post('/voting/', data, format='json')
        self.assertEqual(response.status_code, 201)

        v = Voting.objects.get(name="Example")
        self.assertEqual(v.desc, 'Descripcion')
        self.assertEqual(v.themeVotation, 'Knowledge')
        self.assertEqual(v.preference, 'High')
        self.assertEqual(v.question.scopes, 'Geography')

    def testCreateVotingUrlErroneaAPI(self):
        self.login()
        data = {
            'name': 'Example',
            'preference': 'High',
            'desc': 'Descripcion',
            'question': 'I wanna',
            'question_scopes': 'Geography',
            'question_opt': ['car', 'house', 'party']
        }

        response = self.client.post('/voting/edit/', data, format='json')
        self.assertEqual(response.status_code, 404)
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        self.permission_classes = (UserIsStaff, )
        self.check_permissions(request)
        for data in ['name', 'desc', 'question', 'question_opt']:
            if not data in request.data:
                return Response({}, status=status.HTTP_400_BAD_REQUEST)

        question = Question(desc=request.data.get('question'))
        question.save()
        for idx, q_opt in enumerate(request.data.get('question_opt')):
            opt = QuestionOption(question=question, option=q_opt, number=idx)
            opt.save()
        voting = Voting(name=request.data.get('name'),
                        desc=request.data.get('desc'),
                        question=question)
        voting.save()

        auth, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                             defaults={
                                                 'me': True,
                                                 'name': 'test auth'
                                             })
        auth.save()
        voting.auths.add(auth)
        return Response({}, status=status.HTTP_201_CREATED)
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
 def test_create_multiquestion_preferences_voting(self):
     q1 = Question(desc='question1')
     q1.save()
     for i in range(5):
         opt = QuestionOption(question=q1, option='option {}'.format(i + 1))
         opt.save()
     q2 = Question(desc='preferences', preferences=True)
     q2.save()
     for i in range(5):
         opt = QuestionOption(question=q2, option='option {}'.format(i + 1))
         opt.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q1)
     v.question.add(q2)
     a = v.question.all().count() == 2
     b = v.question.all()[1].preferences == True
     self.assertTrue(a, b)
Ejemplo n.º 7
0
 def test_delete_yes_no_question_relacionada_stopped(self):
     q = Question(desc='si/no question', si_no=True)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertEqual(v.question.all().count(), 1)
     self.login()
     data = {'action': 'start'}
     response = self.client.put('/voting/{}/'.format(v.pk),
                                data,
                                format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.json(), 'Voting started')
     data2 = {'action': 'stop'}
     response2 = self.client.put('/voting/{}/'.format(v.pk),
                                 data2,
                                 format='json')
     self.assertEqual(response2.status_code, 200)
     self.assertEqual(response2.json(), 'Voting stopped')
     q.delete()
     self.assertEqual(v.question.all().count(), 0)
Ejemplo n.º 8
0
    def create_voting(self):
        v = Voting(name='test voting', postproc_type=PostProcType.IDENTITY)
        v.save()

        q1 = Question(desc='test question 1', voting=v)
        q1.save()
        for i in range(5):
            opt = QuestionOption(question=q1, option='option {}'.format(i + 1))
            opt.save()

        q2 = Question(desc='test question 2', voting=v)
        q2.save()
        for i in range(5):
            opt = QuestionOption(question=q2, option='option {}'.format(i + 1))
            opt.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={
                                              'me': True,
                                              'name': 'test auth'
                                          })
        a.save()
        v.auths.add(a)

        return v, q1, q2
Ejemplo n.º 9
0
    def test_get_voting_per_user(self):

        for i in range(2):
            q = Question(desc='test question')
            q.save()
            for j in range(5):
                opt = QuestionOption(question=q,
                                     option='option {}'.format(j + 1))
                opt.save()
            v = Voting(name='test voting', question=q, tipe='testType')
            v.save()

            a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                              defaults={
                                                  'me': True,
                                                  'name': 'test auth'
                                              })
            a.save()
            v.auths.add(a)

        u, _ = User.objects.get_or_create(username='******')
        u.is_active = True
        u.save()

        for v in Voting.objects.all():
            c = Census(voter_id=u.id, voting_id=v.id)
            c.save()

        response = self.client.get('/voting/user/?id={}'.format(u.id))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 2)
Ejemplo n.º 10
0
    def create_voting(self):
        # Creation of questions test for the voting
        q = Question(desc='test question')
        q2 = Question(desc='test question 2')

        # Saving the questions before adding them to the voting
        q.save()
        q2.save()

        # Creation of question options per each question previouly created
        for i in range(5):
            opt = QuestionOption(question=q, option='option {}'.format(i + 1))
            opt.save()

        for n in range(5):
            opt2 = QuestionOption(question=q2, option='option {}'.format(n + 1))
            opt2.save()

        # Creation and storage of voting
        v = Voting(name='test voting', desc='testeo de voting')
        v.save()

        # Addition of the questions created to the voting
        v.questions.add(q)

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'test auth'})
        a.save()
        v.auths.add(a)

        return v
Ejemplo n.º 11
0
 def setUp(self):
     q1 = Question(desc="test question1")
     q1.save()
     q2 = Question(desc="test question2")
     q2.save()
     q3 = Question(desc="test question3")
     q3.save()
     QuestionOption(question=q1, option="option1")
     QuestionOption(question=q1, option="option2")
     QuestionOption(question=q2, option="option3")
     QuestionOption(question=q2, option="option4")
     QuestionOption(question=q3, option="option5")
     QuestionOption(question=q3, option="option6")
     v = Voting(name="Votacion")
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     v.auths.add(a)
     v.question.add(q1)
     v.question.add(q2)
     v.question.add(q3)
     super().setUp()
Ejemplo n.º 12
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     name='v1',
                     question=self.question,
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
Ejemplo n.º 13
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     name='v' + str(pk),
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
     voting.question.add(self.question)
     return voting
Ejemplo n.º 14
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     name='v1',
                     postproc_type=PostProcType.IDENTITY,
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
     q = Question(desc='qwerty', voting=voting)
     q.save()
Ejemplo n.º 15
0
 def gen_voting(self, pk):
     voting = Voting(pk=pk,
                     blank_vote=1,
                     name='v1',
                     start_date=timezone.now(),
                     end_date=timezone.now() + datetime.timedelta(days=1))
     voting.save()
     politicalParty = PoliticalParty(name='Test Political Party',
                                     voting=voting)
     politicalParty.save()
Ejemplo n.º 16
0
 def setUp(self):
     super().setUp()
     self.voting = Voting(pk=5001,
                          name='voting example',
                          postproc_type=PostProcType.IDENTITY,
                          start_date=timezone.now(),
                          )
     self.voting.save()
     self.question = Question(desc='qwerty', voting=self.voting)
     self.question.save()
Ejemplo n.º 17
0
 def setUp(self):
     super().setUp()
     self.question = Question(desc='qwerty')
     self.question.save()
     self.voting = Voting(pk=5001,
                          name='voting example',
                          question=self.question,
                          start_date=timezone.now(),
     )
     self.voting.save()
Ejemplo n.º 18
0
 def test_identity_view(self):
     voting = Voting(name='test 1', desc='r')
     voting.save()
     self.driver.get(f'{self.live_server_url}/admin/login/?next=/admin/')
     self.driver.set_window_size(1920, 1000)
     self.driver.find_element(By.ID, "id_username").click()
     self.driver.find_element(By.ID, "id_username").send_keys("admin")
     self.driver.find_element(By.ID, "id_password").send_keys("qwerty")
     self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
     self.driver.get(f'{self.live_server_url}/visualizer/100/')
Ejemplo n.º 19
0
def start_votings():
    from voting.models import Voting
    now = timezone.now()

    findAllByNowDateSelected = Voting.objects.filter(
        start_date_selected__lte=now, pub_key=None)

    if findAllByNowDateSelected.count() > 0:
        for v in findAllByNowDateSelected:
            v.start_date = now
            Voting.create_pubkey(v)
Ejemplo n.º 20
0
 def test_statisticsWithLogin(self):
     voting = Voting(name='test 1', desc='r')
     voting.save()
     self.driver.get(f'{self.live_server_url}/admin/login/?next=/admin/')
     self.driver.set_window_size(1920, 1000)
     self.driver.find_element(By.ID, "id_username").click()
     self.driver.find_element(By.ID, "id_username").send_keys("decide")
     self.driver.find_element(By.ID,
                              "id_password").send_keys("practica1234")
     self.driver.find_element(By.ID, "id_password").send_keys(Keys.ENTER)
     self.driver.get(f'{self.live_server_url}/visualizer/1/statistics')
Ejemplo n.º 21
0
 def setUp(self):
     super().setUp()
     self.voting = Voting(
         pk=5001,
         name='voting example',
         blank_vote=1,
         start_date=timezone.now(),
     )
     self.voting.save()
     self.politicalParty = PoliticalParty(name='Test Political Party',
                                          voting=self.voting)
     self.politicalParty.save()
Ejemplo n.º 22
0
 def test_model_ejercicio1(self):
     q = Question(desc='Pregunta ejercicio 1')
     q.save()
     opt = QuestionOption(question=q, option='option 1')
     opt.save()
     opt2 = QuestionOption(question=q, option= 'option 2')
     opt2.save()
     v = Voting(name='Votacion ejercicio 1', question=q)
     v.save()
     vTest=Voting.objects.get(name='Votacion ejercicio 1')
     self.assertEqual(vTest.question,v.question)
     self.assertEqual(vTest.name,v.name)
Ejemplo n.º 23
0
    def setUp(self):
        q = Question(desc="Descripción")
        q.save()

        opt1 = QuestionOption(question=q, option="option1")
        opt1.save()

        opt2 = QuestionOption(question=q, option="option2")
        opt2.save()

        self.v = Voting(name="Votación", question=q)
        self.v.save()
        super().setUp()
Ejemplo n.º 24
0
 def create_voting(self):
     self.q = Question(desc='Prueba votación')
     self.q.save()
     for i in range(2):
         opt = QuestionOption(question=self.q, option='Opción {}'.format(i+1))
         opt.save()
     self.v= Voting(name='Prueba votación', question=self.q, slug="prueba")
     self.v.save()
     self.a, _ = Auth.objects.get_or_create(url=settings.BASEURL,defaults={'me': True, 'name': 'test auth'})
     self.a.save()
     self.v.auths.add(self.a)
     self.v.create_pubkey()
     self.v.start_date = timezone.now()
     self.v.save()
Ejemplo n.º 25
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')
Ejemplo n.º 26
0
    def test_yes_no_question(self):
        v = Voting(name='test voting', postproc_type=PostProcType.IDENTITY)
        v.save()

        q = Question(voting=v,
                     desc='yes/no test question',
                     yes_no_question=True)
        q.save()

        opts = list(q.options.all())

        self.assertEqual(len(opts), 2)
        self.assertEqual(opts[0].option, 'Si')
        self.assertEqual(opts[1].option, 'No')
Ejemplo n.º 27
0
    def setUp(self):
        q = Question(desc="Descripcion")
        q.save()

        que1 = Question(desc="Descripcion1")
        que1.save()
        que2 = Question(desc="Descripcion2")
        que2.save()

        opt1 = QuestionOption(question=q, option="option1")
        opt1.save()

        opt2 = QuestionOption(question=q, option="option2")
        opt2.save()

        q_prefer = QuestionPrefer(question=q,
                                  prefer="YES",
                                  number=4,
                                  option="option1")
        q_prefer.save()

        q_ordering = QuestionOrdering(question=q,
                                      number=5,
                                      option="prueba de ordenacion",
                                      ordering=1)
        q_ordering.save()

        party1 = Party(abreviatura="PC")
        party1.save()

        self.candidate1 = Candidate(name="test",
                                    age=21,
                                    number=1,
                                    auto_community="AN",
                                    sex="H",
                                    political_party=party1)
        self.candidate1.save()

        self.v1 = ReadonlyVoting(name="VotacionRO",
                                 question=que1,
                                 desc="example")
        self.v2 = MultipleVoting(name="VotacionM", desc="example")
        self.v2.save()
        self.v2.question.add(que1)
        self.v2.question.add(que2)
        self.v = Voting(name="Votacion", question=q)
        self.v.save()
        self.v1.save()
        self.v2.save()
        super().setUp()
Ejemplo n.º 28
0
 def test_create_voting_with_yes_no_question(self):
     q = Question(desc='si/no question', si_no=True)
     q.save()
     v = Voting(name='test voting')
     v.save()
     a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                       defaults={
                                           'me': True,
                                           'name': 'test auth'
                                       })
     a.save()
     v.auths.add(a)
     v.question.add(q)
     self.assertEqual(v.question.all().count(), 1)
Ejemplo n.º 29
0
    def create_voting(self):
        q = Question(desc='test question')
        q.save()
        for i in range(5):
            opt = QuestionOption(question=q, option='option {}'.format(i+1))
            opt.save()
        v = Voting(name='test voting', question=q, tipe='testType')
        v.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'test auth'})
        a.save()
        v.auths.add(a)

        return v
Ejemplo n.º 30
0
 def setUp(self):
     super().setUp()
     self.usuario = Auth(name='Manuel',
                         url='http://localhost:8000/',
                         me=True)
     self.usuario.save()
     self.pregunta = Question(desc='¿Crees que funcionara?')
     self.pregunta.save()
     self.voting = Voting(name='Votacion de Modelo',
                          desc='Test 1 de modelo',
                          public=True,
                          question=self.pregunta)
     self.voting.save()
     self.voting.auths.add(self.usuario)
     self.voting.save()
Ejemplo n.º 31
0
def new_counter(request):
    row_add = Voting(total_votes=0, score=0)
    row_add.save()
    return render(request, "voting/done.html")