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
Beispiel #2
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)
Beispiel #3
0
    def setUp(self):
        q = Question(desc='multiple test question')
        q2 = Question(desc='multiple test question 2')
        q3 = Question(desc='multiple test question 3')
        q.save()
        q2.save()
        q3.save()
        for i in range(3):
            opt = QuestionOption(question=q, option='option {}'.format(i + 1))
            opt.save()
        for i in range(4):
            opt = QuestionOption(question=q2, option='option {}'.format(i + 1))
            opt.save()
        for i in range(5):
            opt = QuestionOption(question=q3, option='option {}'.format(i + 1))
            opt.save()

        self.v = MultipleVoting(name="Votacion", desc="example")
        self.v.save()
        self.v.question.add(q)
        self.v.question.add(q2)
        self.v.save()

        self.v = MultipleVoting(name="Votacion2", desc="example2")
        self.v.save()
        self.v.question.add(q)
        self.v.save()

        super().setUp()
Beispiel #4
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
Beispiel #5
0
    def setUp(self):

        self.client = APIClient()
        mods.mock_query(self.client)

        voter1 = User(username='******', id="2")
        voter1.set_password('voter')
        voter1.save()

        admin = User(username='******', is_staff=True)
        admin.set_password('admin')
        admin.is_superuser = True
        admin.save()

        q = Question(desc='Preferences question', preferences=True)
        q.save()
        for i in range(3):
            optPref = QuestionOption(question=q, option='option {}'.format(i+1))
            optPref.save()

        q1 = Question(desc='Simple question')
        q1.save()
        for i in range(3):
            optPref = QuestionOption(question=q1, option='option {}'.format(i+1))
            optPref.save()

        q2 = Question(desc='yes/no question', si_no=True)
        q2.save()

        v = Voting(name='test voting', id="2")
        v.save()

        v2= Voting(name='test voting yes no', id="3")
        v2.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)
        v2.auths.add(a)
        v2.question.add(q2)
        v.save()
        v2.save()

        census = Census(voting_id=2, voter_id=2)
        census.save()
        census2 = Census(voting_id=3, voter_id=2)
        census2.save()

        options = webdriver.ChromeOptions()
        options.add_argument('--no-sandbox')
        options.headless = True
        self.driver = webdriver.Chrome(options=options)

        super().setUp()
Beispiel #6
0
    def setUp(self):
        q1 = Question(desc='Elige un máximo de 2 personas para las listas del '
                           'senado por Ávila')
        q1.save()
        opt11 = QuestionOption(question=q1, option='PSOE: García Mata, Jaime',
                               gender='H')
        opt11.save()
        opt12 = QuestionOption(question=q1, option='PP: López Ugarte, Mohamed',
                               gender='H')
        opt12.save()
        opt13 = QuestionOption(question=q1, option='PP: Samaniego Nolé, María',
                               gender='M')
        opt13.save()
        opt14 = QuestionOption(question=q1, option='PP: Llanos  Plana, Josefa',
                               gender='M')
        opt14.save()
        opt15 = QuestionOption(question=q1, option='PP: Encinas Cuervo, Gonzo',
                               gender='H')
        opt15.save()

        q2 = Question(desc='Elige un máximo de 2 personas para las listas del '
                           'senado por Sevilla')
        q2.save()
        opt21 = QuestionOption(question=q2, option='PSOE: Núñez Mata, Mohamed',
                               gender='H')
        opt21.save()
        opt22 = QuestionOption(question=q2, option='PP: López Ugarte, Mohamed',
                               gender='H')
        opt22.save()
        opt23 = QuestionOption(question=q2, option='PP: Anguita Ruiz, María',
                               gender='M')
        opt23.save()
        opt24 = QuestionOption(question=q2, option='PP: Girón Plana, Jaime',
                               gender='H')
        opt24.save()
        opt25 = QuestionOption(question=q2, option='PP: Encinas Cuevas, Gonzo',
                               gender='H')
        opt25.save()

        v1 = Voting(name='Votación Senado Ávila', question=q1,
                    desc='Listas al Senado por Ávila')
        v1.save()

        v2 = Voting(name='Votación Senado Sevilla', question=q2,
                    desc='Listas al Senado por Sevilla')
        v2.save()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True,
                                                    'name': 'test auth'})
        a.save()
        v1.auths.add(a)
        v2.auths.add(a)
        super().setUp()
Beispiel #7
0
 def setUp(self):
     q = Question(desc='question')
     q.save()
     opt1 = QuestionOption(question=q, option='uno')
     opt1.save()
     opt2 = QuestionOption(question=q, option='dos')
     opt2.save()
     v = Voting(name='VotingTest', desc='Description', question=q)
     self.v = v
     self.v.save()
     super().setUp()
Beispiel #8
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)
Beispiel #9
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()
Beispiel #10
0
    def setUp(self):
        q = Question(desc="Descripcion")
        q.save()

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

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

        self.v = ReadonlyVoting(name="Votacion", question=q, desc="example")
        self.v.save()
        super().setUp()
Beispiel #11
0
 def setUp(self):
     super().setUp()
     self.newObject = Question(desc='test')
     self.newObject.save()
     self.opt = QuestionOption(question=self.newObject,
                               option='1',
                               yes=True,
                               no=False)
     self.opt.save()
     self.opt2 = QuestionOption(question=self.newObject,
                                option='2',
                                yes=False,
                                no=True)
     self.opt2.save()
Beispiel #12
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()
Beispiel #13
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()
Beispiel #14
0
 def create_question(self):
     q = Question(desc='test question', si_no='False', preferences='False')
     q.save()
     for i in range(5):
         opt = QuestionOption(question=q, option='option {}'.format(i + 1))
         opt.save()
     return q
Beispiel #15
0
def createAnswers(q):
    answers = []
    for i in range(5):
        opt = QuestionOption(question=q, option='opción {}'.format(i + 1))
        opt.save()
        answers.append(opt)
    return answers
Beispiel #16
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)
Beispiel #17
0
    def setUp(self):
        # Create user
        self.client = APIClient()
        mods.mock_query(self.client)
        u = UserProfile(id=1, username='******', sex='M')
        u.set_password('123')
        u.save()
        token= mods.post('authentication', entry_point='/login/', json={'username':'******', 'password': '******'})
        # Add session token
        session = self.client.session
        session['user_token'] = token
        session.save()

        #Create voting

        #Create question 1
        q1 = Question(id=1,desc='Unique option question', option_types=1)
        q1.save()
        for i in range(3):
            opt = QuestionOption(question=q1, option='option {}'.format(i+1))
            opt.save()

        #Create question 2
        q2 = Question(id=2,desc='Multiple option question', option_types=2)
        q2.save()
        for i in range(4):
            opt = QuestionOption(question=q2, option='option {}'.format(i+1))
            opt.save()

        #Create question 3
        q3 = Question(id=3,desc='Rank order scale question', option_types=3)
        q3.save()
        for i in range(5):
            opt = QuestionOption(question=q3, option='option {}'.format(i+1))
            opt.save()

        v = Voting(id=1, name='Single question voting',desc='Single question voting...', points=1, start_date=timezone.now())
        v.save()
        v.question.add(q1), v.question.add(q2), v.question.add(q3)
        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'base'})
        a.save()
        v.auths.add(a)
        Voting.create_pubkey(v)
        #Add user to census
        census = Census(voting_id=v.id, voter_id=u.id)
        census.save()
Beispiel #18
0
 def test_transform_question_with_one_option_to_yes_no(self):
     q = Question(desc='si_no question', si_no=False)
     q.save()
     opt = QuestionOption(question=q, number='3', option='option 3')
     opt.save()
     self.assertTrue(q.si_no == False)
     q.si_no = True
     self.assertTrue(q.si_no == True)
     self.assertRaises(ValidationError, opt.clean)
Beispiel #19
0
 def testExistQuestionWithOption(self):
     q = Question.objects.get(desc="Descripcion")
     opt1 = QuestionOption(question=q, option="option1")
     opt1.save()
     v = Voting.objects.get(name="Votacion")
     v.question = q
     v.question_opt = opt1
     v.save()
     self.assertEquals(v.question.options.all()[0].option, "option1")
Beispiel #20
0
    def create_binary_voting(self):
        q = Question(desc='binary question')
        q.save()
        opt = QuestionOption(question=q, option='', yes=True, no=False)
        opt.save()
        opt2 = QuestionOption(question=q, option='', yes=False, no=True)
        opt2.save()
        v = Voting(name='test voting', question=q)
        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
Beispiel #21
0
 def test_adding_question_to_voting_multiquestion(self):
     q1 = Question(desc="test question1")
     q1.save()
     q2 = Question(desc="test question2")
     q2.save()
     QuestionOption(question=q1, option="option1")
     QuestionOption(question=q1, option="option2")
     QuestionOption(question=q2, option="option3")
     QuestionOption(question=q2, option="option4")
     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)
     self.assertEquals(v.question.all().count(), 1)
     v.question.add(q2)
     self.assertEquals(v.question.all().count(), 2)
Beispiel #22
0
    def testAddOption(self):
        v = Voting.objects.get(name="Votacion")
        q = v.question

        self.assertEqual(v.question.options.all().count(), 0)

        opt = QuestionOption(question=q, option="opcionTest")
        opt.save()
        v.save()

        self.assertEqual(v.question.options.all()[0].option, "opcionTest")
        self.assertEqual(v.question.options.all().count(), 1)
Beispiel #23
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()
Beispiel #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()
Beispiel #25
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
Beispiel #26
0
 def test_edit_yes_no_question_in_voting_add_opt(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.assertTrue(q.si_no == True)
     opt = QuestionOption(question=q, option='option 3', number='3')
     self.assertRaises(ValidationError, opt.clean)
Beispiel #27
0
 def test_create_onequestion_voting(self):
     q1 = Question(desc='question1')
     q1.save()
     for i in range(5):
         opt = QuestionOption(question=q1, 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)
     self.assertEqual(v.question.all().count(), 1)
Beispiel #28
0
    def test_no_political_party_voting_senate(self):

        u = User(username='******')
        u.set_password('senator')
        u.save()

        q = Question(desc='Choose')
        q.save()

        opt = QuestionOption(question=q, option='senator')
        opt.save()

        political_party = PoliticalParty(name='Partido Popular',
                                         acronym='PP',
                                         description='test',
                                         headquarters='test')
        political_party.save()

        birthdate = date(2000, 2, 28)
        userProfile = UserProfile(related_political_party=political_party,
                                  birthdate=birthdate,
                                  sex='F',
                                  related_user=u,
                                  province='S',
                                  employment='S')
        userProfile.save()

        v = Voting(name='test voting',
                   question=q,
                   tipe='S',
                   province='S',
                   political_party=political_party)
        v.save()

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

        self.assertRaises(ValidationError, v.clean)
Beispiel #29
0
    def create_voting_senate_primaries(self):

        u = User(username='******')
        u.set_password('123')
        u.save()

        q = Question(desc='test question')
        q.save()

        opt = QuestionOption(question=q, option='senator')
        opt.save()

        political_party = PoliticalParty(name='for senator',
                                         acronym='test',
                                         description='test',
                                         headquarters='test')
        political_party.save()

        birthdate = date(2000, 2, 28)
        userProfile = UserProfile(related_political_party=political_party,
                                  birthdate=birthdate,
                                  sex='F',
                                  related_user=u,
                                  province='S',
                                  employment='B')
        userProfile.save()

        v = Voting(name='test voting',
                   question=q,
                   tipe='SP',
                   political_party=political_party)
        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
Beispiel #30
0
    def setUp(self):
        super().setUp()
        self.question = Question(id=1, desc='test question', option_types=2)
        self.question.save()
        for i in range(5):
            opt = QuestionOption(question=self.question,
                                 option='option {}'.format(i + 1))
            opt.save()

        self.voting = Voting(id=5001, name='test voting')

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