Skip to content

Commit

Permalink
Test:Tests de selenium en github; 40
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jesgamlar committed Jan 8, 2022
1 parent 024d4d6 commit 979f6ef
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/selenium/testsAuthentication.py
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'
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)


0 comments on commit 979f6ef

Please sign in to comment.