Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def setUp(self):
        #Create user 1
        self.client = APIClient()
        mods.mock_query(self.client)
        u1 = UserProfile(id=1, username='******', sex='M')
        u1.set_password('123')
        u1.save()
        token1 = mods.post('authentication', entry_point='/login/', json={'username':'******', 'password': '******'})
        #Add session token 1
        session = self.client.session
        session['user_token'] = token1
        session['voter_id'] = u1.id
        session.save()

        #Create voting 1

        #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()

        v1 = Voting(id=1, name='Single question voting',desc='Single question voting...', points=1, start_date=timezone.now())
        v1.save()
        v1.question.add(q1), v1.question.add(q2), v1.question.add(q3)
        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={'me': True, 'name': 'base'})
        a.save()
        v1.auths.add(a)
        Voting.create_pubkey(v1)

        #Create voting 2

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

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

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

        v2 = Voting(id=2, name='Single question voting 2',desc='Single question voting...', points=1, start_date=M_DATE, end_date=E_DATE)
        v2.save()
        v2.question.add(q4), v2.question.add(q5), v2.question.add(q6)
        v2.auths.add(a)
        Voting.create_pubkey(v2)

        #Add user to census
        census1 = Census(voting_id=v1.id, voter_id=u1.id)
        census1.save()
        census2 = Census(voting_id=v2.id, voter_id=u1.id)
        census2.save()

        #Create suggestion 1
        s1 = SuggestingForm(id=1, user_id=u1.id, title="Suggesting title", suggesting_date=S_DATE, content="Suggesting content...", send_date=NOW_DATE, is_approved=True)
        s1.save()
Exemplo n.º 4
0
    def setUp(self):
        self.booth = BoothTests()
        self.booth.setUp()

        options = webdriver.ChromeOptions()
        options.headless = True
        self.driver = webdriver.Chrome(options=options)
        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()

        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()

        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()

        a, _ = Auth.objects.get_or_create(url=settings.BASEURL,
                                          defaults={
                                              'me': True,
                                              'name': 'base'
                                          })
        a.save()
        v2 = Voting(id=2,
                    name='Rank question voting',
                    desc='Rank question voting...',
                    points=1,
                    start_date=timezone.now())
        v2.save()
        v2.question.add(q3)
        v3 = Voting(id=3,
                    name='Multiple question voting',
                    desc='Multiple question voting...',
                    points=1,
                    start_date=timezone.now())
        v3.save()
        v3.question.add(q2)

        v2.auths.add(a)
        Voting.create_pubkey(v2)
        #Add user to census
        census = Census(voting_id=v2.id, voter_id=u.id)
        census.save()

        v3.auths.add(a)
        Voting.create_pubkey(v3)
        #Add user to census
        census = Census(voting_id=v3.id, voter_id=u.id)
        census.save()

        super().setUp()
Exemplo n.º 5
0
class TestGoogle(StaticLiveServerTestCase):
    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()

    def setUp(self):

        self.base = BaseTestCase()
        self.base.setUp()
        self.vars = {}
        self.create_voting()
        options = webdriver.ChromeOptions()
        options.headless = True
        self.driver = webdriver.Chrome(options=options)
        self.wait = WebDriverWait(self.driver, 10)
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

        self.driver = webdriver.Firefox()

        super().setUp()

    def tearDown(self):
        super().tearDown()
        self.driver.quit()
        self.base.tearDown()
        self.v.delete()

    def test_google(self):

        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".voting > h1").text == f"{self.v.pk} - Prueba votación"
        self.driver.find_element(By.LINK_TEXT, "Login con Google").click()

        #introducir un email mal
        self.driver.find_element(By.ID, "identifierId").send_keys("test")
        self.driver.find_element(By.ID, "identifierId").send_keys(Keys.ENTER)
        self.driver.find_element(By.ID,
                                 "identifierId").send_keys(Keys.BACKSPACE)
        self.driver.find_element(By.ID,
                                 "identifierId").send_keys(Keys.BACKSPACE)
        self.driver.find_element(By.ID,
                                 "identifierId").send_keys(Keys.BACKSPACE)
        self.driver.find_element(By.ID,
                                 "identifierId").send_keys(Keys.BACKSPACE)

        # introducir un email que si existe
        self.driver.find_element(
            By.ID, "identifierId").send_keys("*****@*****.**")
        self.driver.find_element(By.ID, "identifierId").send_keys(Keys.ENTER)
Exemplo n.º 6
0
class Github(StaticLiveServerTestCase):
    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()

    def setUp(self):

        self.base = BaseTestCase()
        self.base.setUp()
        self.vars = {}
        self.create_voting()
        options = webdriver.ChromeOptions()
        options.headless = True
        self.driver = webdriver.Chrome(options=options)

        self.driver = webdriver.Firefox()

        super().setUp()

    def tearDown(self):
        super().tearDown()
        self.driver.quit()
        self.base.tearDown()
        self.v.delete()

    ''' 
    #Sólo se ejecuta correctamente en local
    def test_login_correcto_github(self):
        #Redirección a la votación creada
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        assert self.driver.find_element(By.CSS_SELECTOR, ".voting > h1").text == f"{self.v.pk} - Prueba votación"
        #Inicio sesión con github
        self.driver.find_element(By.LINK_TEXT, "Login con GitHub").click()
        self.driver.find_element(By.CSS_SELECTOR, "p:nth-child(2)").click()
        assert self.driver.find_element(By.CSS_SELECTOR, "strong:nth-child(3)").text == "AuthenticationApp"
        self.driver.find_element(By.ID, "login_field").click()
        self.driver.find_element(By.ID, "login_field").send_keys("decideautenticacion")
        self.driver.find_element(By.ID, "password").click()
        self.driver.find_element(By.ID, "password").send_keys("pruebadecide11")
        self.driver.find_element(By.NAME, "commit").click()
        #Esperamos 4 segundos debido a las diferentes redirecciones hasta llegar de nuevo a la página de votación
        time.sleep(3)
        assert self.driver.find_element(By.CSS_SELECTOR, ".btn").text == "Vote"
    '''

    #Usuario introduce una contraseña incorrecta de su cuenta de Github
    def test_login_incorrect_password(self):
        #Redirección a la votación creada
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".voting > h1").text == f"{self.v.pk} - Prueba votación"
        #Inicio sesión con github
        self.driver.find_element(By.LINK_TEXT, "Login con GitHub").click()
        self.driver.find_element(By.CSS_SELECTOR, "p:nth-child(2)").click()
        assert self.driver.find_element(
            By.CSS_SELECTOR, "strong:nth-child(3)").text == "AuthenticationApp"
        self.driver.find_element(By.ID, "login_field").click()
        self.driver.find_element(
            By.ID, "login_field").send_keys("decideautenticacion")
        self.driver.find_element(By.ID, "password").click()
        self.driver.find_element(By.ID, "password").send_keys("1234")
        self.driver.find_element(By.NAME, "commit").click()
        #Mensaje error
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".flash > .container-lg").text == "Incorrect username or password."

    #Usuario introduce un username incorrecto de su cuenta de Github
    def test_login_incorrect_username(self):
        #Redirección a la votación creada
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".voting > h1").text == f"{self.v.pk} - Prueba votación"
        #Inicio sesión con github
        self.driver.find_element(By.LINK_TEXT, "Login con GitHub").click()
        self.driver.find_element(By.CSS_SELECTOR, "p:nth-child(2)").click()
        assert self.driver.find_element(
            By.CSS_SELECTOR, "strong:nth-child(3)").text == "AuthenticationApp"
        self.driver.find_element(By.ID, "login_field").click()
        self.driver.find_element(
            By.ID, "login_field").send_keys("decideautenticacionn")
        self.driver.find_element(By.ID, "password").click()
        self.driver.find_element(By.ID, "password").send_keys("pruebadecide11")
        self.driver.find_element(By.NAME, "commit").click()
        #Mensaje error
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".flash > .container-lg").text == "Incorrect username or password."
Exemplo n.º 7
0
class Login2FA(StaticLiveServerTestCase):

    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()
        
    def createUsers(self):
        self.user_with_2fa = User(username='******')
        self.user_with_2fa.set_password('qwerty')
        self.user_with_2fa.save()

        self.user_no_2fa = User(username="******")
        self.user_no_2fa.set_password('qwerty')
        self.user_no_2fa.save()

        self.extra = Extra(phone='020304050')
        self.extra.totp_code = 'S3K3TPI5MYA2M67V'
        self.extra.user = self.user_with_2fa
        self.extra.save()


    def setUp(self):

        self.base = BaseTestCase()
        self.base.setUp()

        self.vars = {}
        self.create_voting()
        self.createUsers()
        options = webdriver.ChromeOptions()
        options.headless = True
        self.driver = webdriver.Chrome(options=options)

        super().setUp()

    def tearDown(self):
        super().tearDown()
        self.driver.quit()
        self.base.tearDown()
        self.v.delete()

    #Un usuario con 2fa no puede logearse si no lo introduce
    def test_login2faWithoutIt(self):
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        self.driver.set_window_size(1366, 728)
        self.driver.find_element(By.ID, "username").click()
        self.driver.find_element(By.ID, "username").send_keys("user2fa")
        self.driver.find_element(By.ID, "password").click()
        self.driver.find_element(By.ID, "password").send_keys("qwerty")
        self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
        assert self.driver.find_element(By.ID, "__BVID__11__BV_label_").text == "Username"

    #Un usuario sin 2fa puede logearse bien
    def test_logino2fa(self):
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        self.driver.set_window_size(1366, 728)
        # self.driver.find_element(By.ID, "__BVID__19__BV_label_").click()
        self.driver.find_element(By.ID, "username").click()
        self.driver.find_element(By.ID, "username").send_keys("usernofa")
        self.driver.find_element(By.ID, "password").send_keys("qwerty")
        self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
        elements = self.driver.find_elements(By.CSS_SELECTOR, ".btn")
        assert len(elements) > 0

    #Un usuario sin 2fa no puede logearse en el formulario para 2fa
    def test_loginno2fain2fa(self):
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        self.driver.set_window_size(1366, 728)
        self.driver.find_element(By.CSS_SELECTOR, ".custom-control:nth-child(2) > .custom-control-label").click()
        self.driver.find_element(By.ID, "username").click()
        self.driver.find_element(By.ID, "username").send_keys("usuarionofa")
        self.driver.find_element(By.ID, "password").send_keys("qwerty")
        self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
        assert self.driver.find_element(By.ID, "__BVID__11__BV_label_").text == "Username"
Exemplo n.º 8
0
    def test(self):
        #Create and save question
        q = Question(desc='Question1')
        q.save()

        #Create and save question options
        for i in range(2):
            opt = QuestionOption(question=q, option='option {}'.format(i+1))
            opt.save()

        #Create and save votation with question
        v = Voting(name='Votation1')
        v.save()

        v.questions.add(q)

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

        #Create and save multiple voters for votation
        for i in range(2):
            u, _ = User.objects.get_or_create(username='******'.format(i+1))
            u.is_active = True
            u.save()
            c = Census(voter_id=u.id, voting_id=v.id)
            c.save()

        #...
        #Votation created
        #...

        #Start votation
        v.create_pubkey()
        v.start_date = timezone.now()
        v.save()

        #...
        #Votation started
        #...

        #Method copy from voting/test.py
        #Create and add votes
        voters = list(Census.objects.filter(voting_id=v.id))
        voter = voters.pop()
        clear = {}
        for opt in v.questions.first().options.all():
            clear[opt.number] = 0
            for i in range(2):
                a, b = self.encrypt_msg(opt.number, v)
                data = {
                    'voting': v.id,
                    'voter': voter.voter_id,
                    'vote': { 'a': a, 'b': b },
                }
                clear[opt.number] += 1
                user = self.get_or_create_user(voter.voter_id)
                self.login(user=user.username)
                #voter = voters.pop()
                mods.post('store', json=data)


        #Login with admin
        self.login()

        #Tally Done
        v.tally_votes()
        
        #...
        #Votation ended
        #...
        
        #Method for test views's method
        response = self.client.get('/visualizer/{}/'.format(v.pk))
        self.assertEqual(response.status_code, 200)

        #Check 1
        self.assertEqual(response.context['voting_id'], v.pk)

        #Check 2
        self.assertEqual('Votation1' in response.context['voting'].values() , True)

        #Check 3
        varTemp = response.context['voting']
        self.assertEqual('Question1' in varTemp['questions'][0].values() , True)
Exemplo n.º 9
0
class Facebook(StaticLiveServerTestCase):
    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()

    def setUp(self):

        self.base = BaseTestCase()
        self.base.setUp()

        self.vars = {}
        self.create_voting()
        options = webdriver.ChromeOptions()
        options.headless = True
        self.driver = webdriver.Chrome(options=options)

        self.wait = WebDriverWait(self.driver, 10)
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

        self.driver = webdriver.Firefox()

        super().setUp()

    def tearDown(self):
        super().tearDown()
        self.driver.quit()
        self.base.tearDown()
        self.v.delete()

    def test_emailincorrecto(self):
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".voting > h1").text == f"{self.v.pk} - Prueba votación"

        self.driver.find_element(By.LINK_TEXT, "Login con Facebook").click()
        self.driver.find_element(By.ID, "email").send_keys("*****@*****.**")
        self.driver.find_element(By.ID, "email").send_keys(Keys.ENTER)
        assert self.driver.find_element(By.ID, "email").text == ""
        assert self.driver.find_element(By.ID, "pass").text == ""

    def test_contraseaincorrecta(self):
        self.driver.get(f'{self.live_server_url}/booth/{self.v.pk}')
        assert self.driver.find_element(
            By.CSS_SELECTOR,
            ".voting > h1").text == f"{self.v.pk} - Prueba votación"
        self.driver.set_window_size(824, 824)
        self.driver.find_element(By.LINK_TEXT, "Login con Facebook").click()
        self.driver.find_element(By.ID,
                                 "email").send_keys("*****@*****.**")
        self.driver.find_element(By.ID, "pass").send_keys("fdasffa")
        self.driver.find_element(By.ID, "pass").send_keys(Keys.ENTER)
        assert self.driver.find_element(By.ID, "pass").text == ""