Skip to content

Commit

Permalink
Merge pull request EGCETSII#42 from Decide-Part-Penyagolosa-1/jesgaml…
Browse files Browse the repository at this point in the history
…ar-authentication

Pruebas realizadas por jesgamlar
  • Loading branch information
jesgamlar authored Jan 9, 2022
2 parents de49bf4 + a604566 commit fada8b4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
23 changes: 23 additions & 0 deletions decide/census/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions loadtest/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
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 fada8b4

Please sign in to comment.