Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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()
Esempio n. 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
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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")
Esempio n. 9
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)
Esempio n. 10
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()
Esempio n. 11
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()
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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()
Esempio n. 15
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()
Esempio n. 16
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()
Esempio n. 17
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()
Esempio n. 18
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
Esempio n. 19
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)
Esempio n. 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
Esempio n. 21
0
 def test_transform_question_in_voting_with_one_option_to_yes_no(self):
     q = Question(desc='si_no question', si_no=False)
     q.save()
     opt = QuestionOption(question=q, option='option 3', number='3')
     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(q)
     self.assertTrue(q.si_no == False)
     q.si_no = True
     self.assertTrue(q.si_no == True)
     self.assertRaises(ValidationError, opt.clean)
Esempio n. 22
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)
Esempio n. 23
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
Esempio n. 24
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)
Esempio n. 25
0
 def test_delete_preferences_question(self):
     q = Question(desc='Preferences question', preferences=True)
     q.save()
     for i in range(2):
         optPref = QuestionOption(question=q,
                                  option='option {}'.format(i + 1))
         optPref.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)
     v.save()
     self.assertTrue(v.question.count() == 1)
     v.question.remove(q)
     self.assertTrue(v.question.count() == 0)
    def create_voting(self):
        q = Question(desc='test question', scopes='Geography')
        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,
                   themeVotation='Survey',
                   preference='Low')
        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
Esempio n. 27
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()
Esempio n. 28
0
    def test_automatic_number_assignment_of_question_and_questionoption(self):
        v = Voting(name='test voting', postproc_type=PostProcType.IDENTITY)
        v.save()

        for q in range(3):

            quest = Question(voting=v, desc='question {}'.format(q))
            quest.save()

            for o in range(3):

                opt = QuestionOption(question=quest,
                                     option='option {}'.format(o))
                opt.save()

        questions = list(v.questions.all())

        q1 = questions[0]
        q1opts = list(q1.options.all())

        self.assertEqual(q1.number, 1)
        self.assertEqual(q1opts[0].number, 1)
        self.assertEqual(q1opts[1].number, 2)
        self.assertEqual(q1opts[2].number, 3)

        q2 = questions[1]
        q2opts = list(q2.options.all())

        self.assertEqual(q2.number, 2)
        self.assertEqual(q2opts[0].number, 4)
        self.assertEqual(q2opts[1].number, 5)
        self.assertEqual(q2opts[2].number, 6)

        q3 = questions[2]
        q3opts = list(q3.options.all())

        self.assertEqual(q3.number, 3)
        self.assertEqual(q3opts[0].number, 7)
        self.assertEqual(q3opts[1].number, 8)
        self.assertEqual(q3opts[2].number, 9)
Esempio n. 29
0
class QuestionOptionTest(TestCase):

        def setUp(self):
            self.test_question = Question(desc = "Descripción de prueba", escaños = 360)
            self.test_question.save()
            self.test_questionOption = QuestionOption(question = self.test_question, number = 2, option="Prueba option", sexo = 'MUJER')
            self.test_questionOption.save()
            

        def test_quiestionoption_creation(self):
            self.assertEquals(self.test_questionOption.question, self.test_question)
            self.assertEquals(self.test_questionOption.number, 2 )
            self.assertEquals(self.test_questionOption.option, "Prueba option")
            self.assertEquals(self.test_questionOption.sexo, "MUJER")

        def test_str_question(self):
            self.assertEquals(str(self.test_questionOption), "Prueba option (2)")    

        
        def tearDown(self):
            self.test_question.delete()
            self.test_questionOption.delete()
Esempio n. 30
0
 def test_unique_voting_preference(self):
     q = Question(desc='Preferences question', preferences=True)
     q.save()
     for i in range(2):
         optPref = QuestionOption(question=q,
                                  option='option {}'.format(i + 1))
         optPref.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)
     v.save()
     self.assertTrue(v.question.all()[0].preferences == True)
     self.assertEquals(v.question.all()[0].options.all()[0].option,
                       "option 1")
     self.assertEquals(v.question.all()[0].options.all()[1].option,
                       "option 2")