From 024d4d6122d139a8c228286850e6d78bf1a098d0 Mon Sep 17 00:00:00 2001 From: jesgamlar Date: Sat, 8 Jan 2022 23:25:30 +0100 Subject: [PATCH 1/3] Test: Pruebas de modulo de censo ; #39 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se han añadido tres pruebas del modulo de censo para comprobar que funciona correctamente y se valida su unicidad modificado: decide/census/tests.py --- decide/census/tests.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/decide/census/tests.py b/decide/census/tests.py index e86ff74679..90136ff5ea 100644 --- a/decide/census/tests.py +++ b/decide/census/tests.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import User from django.test import TestCase from rest_framework.test import APIClient +from django.db import utils from .models import Census from base import mods @@ -19,6 +20,28 @@ def tearDown(self): super().tearDown() self.census = None + def test_ExistCensus(self): + c=Census.objects.get(voting_id='1') + self.assertEquals(c.voting_id ,1) + self.assertEquals(c.voter_id ,1) + + def test_NotExistCensus(self): + cs=Census.objects.all() + for c in cs: + self.assertNotEquals(c.voting_id ,10000) + + def test_equalsCensus(self): + self.census = Census(voting_id=1, voter_id=1) + try: + self.census.save() + except utils.IntegrityError: + error = True + self.assertEquals(error ,True) + + + + + def test_check_vote_permissions(self): response = self.client.get('/census/{}/?voter_id={}'.format(1, 2), format='json') self.assertEqual(response.status_code, 401) From 979f6ef690299e9b743f0d9358ea21d30ac3ccb8 Mon Sep 17 00:00:00 2001 From: jesgamlar Date: Sat, 8 Jan 2022 23:48:56 +0100 Subject: [PATCH 2/3] Test:Tests de selenium en github; 40 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se han creado dos tests de autenticación con github que prueban: -una autenticacion correcta -una autenticacion con un usuario erroneo También se ha creado un test de autenticacion de usuario admin como prueba nuevo archivo: tests/selenium/testsAuthentication.py --- tests/selenium/testsAuthentication.py | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/selenium/testsAuthentication.py diff --git a/tests/selenium/testsAuthentication.py b/tests/selenium/testsAuthentication.py new file mode 100644 index 0000000000..8e571f1958 --- /dev/null +++ b/tests/selenium/testsAuthentication.py @@ -0,0 +1,66 @@ +from django.test import TestCase +from django.contrib.staticfiles.testing import StaticLiveServerTestCase + +from selenium import webdriver +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC, wait +from selenium.webdriver.common.keys import Keys + + +from base.tests import BaseTestCase + +class AdminTestCase(StaticLiveServerTestCase): + + + def setUp(self): + #Load base test functionality for decide + self.base = BaseTestCase() + self.base.setUp() + + options = webdriver.ChromeOptions() + options.headless = True + self.driver = webdriver.Chrome(options=options) + self.accept_next_alert = True + + self.githubEmail = 'jquitzonp_j492r@vixej.com' + super().setUp() + + def tearDown(self): + super().tearDown() + self.driver.quit() + + self.base.tearDown() + + def test_loginAdminSuccess(self): + driver = self.driver + driver.get("http://localhost:8000/admin") + driver.find_element_by_id("id_username").clear() + driver.find_element_by_id("id_username").send_keys("jesus") + driver.find_element_by_id("id_password").clear() + driver.find_element_by_id("id_password").send_keys("practica",Keys.ENTER) + self.assertEqual("Django administration", driver.find_element_by_link_text("Django administration").text) + driver.get("http://localhost:8000/admin/logout") + + def test_loginAuthGithubSuccess(self): + driver = self.driver + driver.get("http://localhost:8000/authentication/accounts/github/login/") + driver.find_element_by_id("login_field").clear() + driver.find_element_by_id("login_field").send_keys("penyagolosa-1-decide") + driver.find_element_by_id("password").clear() + driver.find_element_by_id("password").send_keys("Jornada2022") + driver.find_element_by_id("password").send_keys(Keys.ENTER) + WebDriverWait(driver, 15) + self.assertEqual(driver.current_url, "http://localhost:8000/booth/voting" ) + + def test_loginAuthGithubError(self): + driver = self.driver + driver.get("http://localhost:8000/authentication/accounts/github/login/") + driver.find_element_by_id("login_field").clear() + driver.find_element_by_id("login_field").send_keys("penyagolosa-1-decide") + driver.find_element_by_id("password").clear() + driver.find_element_by_id("password").send_keys("123") + driver.find_element_by_name("commit").click() + self.assertEqual("Incorrect username or password.", driver.find_element_by_xpath("//div[@id='js-flash-container']/div/div").text) + + From a604566a37a5f67efa29a7f8a3367fe5776cbb23 Mon Sep 17 00:00:00 2001 From: jesgamlar Date: Sun, 9 Jan 2022 00:17:32 +0100 Subject: [PATCH 3/3] Test: Pruebas de carga GitHub ; 41 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se han hecho una prueba de carga de forma que pruebe la página de redirección de autenticación de GitHub. Se ha asegurado un funcionamiento correcto con mas de 8000 usuarios. modificado: locustfile.py --- loadtest/locustfile.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/loadtest/locustfile.py b/loadtest/locustfile.py index 85cae8ee99..7aa5e2b4e6 100644 --- a/loadtest/locustfile.py +++ b/loadtest/locustfile.py @@ -14,7 +14,12 @@ HOST = "http://localhost:8000" VOTING = 1 +class DefGithubAuthenticationRedirection(TaskSet): + @task + def index(self): + self.client.get("/authentication/accounts/github/login/") + class DefVisualizer(TaskSet): @task @@ -73,3 +78,8 @@ class Voters(HttpUser): host = HOST tasks = [DefVoters] wait_time= between(3,5) + +class GithubAuthenticationRedirection(HttpUser): + host = HOST + tasks = [DefGithubAuthenticationRedirection] + wait_time= between(3,5)