Skip to content

Commit

Permalink
Merge pull request #74 from decide-update-4-1/workbranch-migpatgut
Browse files Browse the repository at this point in the history
test: selenium Census y Voting
  • Loading branch information
mpg97 authored Dec 18, 2022
2 parents cbecbca + b4c541d commit ca01211
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 0 deletions.
91 changes: 91 additions & 0 deletions decide/census/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
from django.contrib.auth.models import User
from django.test import TestCase
from rest_framework.test import APIClient
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
from selenium.webdriver.common.keys import Keys

from .models import Census
from base import mods
from base.tests import BaseTestCase
from datetime import datetime


class CensusTestCase(BaseTestCase):
Expand Down Expand Up @@ -73,3 +81,86 @@ def test_destroy_voter(self):
response = self.client.delete('/census/{}/'.format(1), data, format='json')
self.assertEqual(response.status_code, 204)
self.assertEqual(0, Census.objects.count())


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

super().setUp()

def tearDown(self):
super().tearDown()
self.driver.quit()

self.base.tearDown()

def createCensusSuccess(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.cleaner.get(self.live_server_url+"/admin/census/census/add")
now = datetime.now()
self.cleaner.find_element(By.ID, "id_voting_id").click()
self.cleaner.find_element(By.ID, "id_voting_id").send_keys(now.strftime("%m%d%M%S"))
self.cleaner.find_element(By.ID, "id_voter_id").click()
self.cleaner.find_element(By.ID, "id_voter_id").send_keys(now.strftime("%m%d%M%S"))
self.cleaner.find_element(By.NAME, "_save").click()

self.assertTrue(self.cleaner.current_url == self.live_server_url+"/admin/census/census")

def createCensusEmptyError(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.cleaner.get(self.live_server_url+"/admin/census/census/add")

self.cleaner.find_element(By.NAME, "_save").click()

self.assertTrue(self.cleaner.find_element_by_xpath('/html/body/div/div[3]/div/div[1]/div/form/div/p').text == 'Please correct the errors below.')
self.assertTrue(self.cleaner.current_url == self.live_server_url+"/admin/census/census/add")

def createCensusValueError(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.cleaner.get(self.live_server_url+"/admin/census/census/add")
now = datetime.now()
self.cleaner.find_element(By.ID, "id_voting_id").click()
self.cleaner.find_element(By.ID, "id_voting_id").send_keys('64654654654654')
self.cleaner.find_element(By.ID, "id_voter_id").click()
self.cleaner.find_element(By.ID, "id_voter_id").send_keys('64654654654654')
self.cleaner.find_element(By.NAME, "_save").click()

self.assertTrue(self.cleaner.find_element_by_xpath('/html/body/div/div[3]/div/div[1]/div/form/div/p').text == 'Please correct the errors below.')
self.assertTrue(self.cleaner.current_url == self.live_server_url+"/admin/census/census/add")
153 changes: 153 additions & 0 deletions decide/voting/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
from django.utils import timezone
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.test import TestCase
from rest_framework.test import APIClient
from rest_framework.test import APITestCase

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
from selenium.webdriver.common.keys import Keys

from base import mods
from base.tests import BaseTestCase
from census.models import Census
from mixnet.mixcrypt import ElGamal
from mixnet.mixcrypt import MixCrypt
from mixnet.models import Auth
from voting.models import Voting, Question, QuestionOption
from datetime import datetime


class VotingTestCase(BaseTestCase):
Expand Down Expand Up @@ -208,3 +216,148 @@ def test_update_voting(self):
response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json')
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), 'Voting already tallied')

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

super().setUp()

def tearDown(self):
super().tearDown()
self.driver.quit()

self.base.tearDown()

def successLogIn(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")
self.assertTrue(self.cleaner.current_url == self.live_server_url+"/admin/")

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

super().setUp()

def tearDown(self):
super().tearDown()
self.driver.quit()

self.base.tearDown()

def usernameWrongLogIn(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("usuarioNoExistente")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("usuarioNoExistente")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.assertTrue(self.cleaner.find_element_by_xpath('/html/body/div/div[2]/div/div[1]/p').text == 'Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive.')

def passwordWrongLogIn(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("wrongPassword")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.assertTrue(self.cleaner.find_element_by_xpath('/html/body/div/div[2]/div/div[1]/p').text == 'Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive.')

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

super().setUp()

def tearDown(self):
super().tearDown()
self.driver.quit()

self.base.tearDown()

def createQuestionSuccess(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.cleaner.get(self.live_server_url+"/admin/voting/question/add/")

self.cleaner.find_element(By.ID, "id_desc").click()
self.cleaner.find_element(By.ID, "id_desc").send_keys('Test')
self.cleaner.find_element(By.ID, "id_options-0-number").click()
self.cleaner.find_element(By.ID, "id_options-0-number").send_keys('1')
self.cleaner.find_element(By.ID, "id_options-0-option").click()
self.cleaner.find_element(By.ID, "id_options-0-option").send_keys('test1')
self.cleaner.find_element(By.ID, "id_options-1-number").click()
self.cleaner.find_element(By.ID, "id_options-1-number").send_keys('2')
self.cleaner.find_element(By.ID, "id_options-1-option").click()
self.cleaner.find_element(By.ID, "id_options-1-option").send_keys('test2')
self.cleaner.find_element(By.NAME, "_save").click()

self.assertTrue(self.cleaner.current_url == self.live_server_url+"/admin/voting/question/")

def createCensusEmptyError(self):
self.cleaner.get(self.live_server_url+"/admin/login/?next=/admin/")
self.cleaner.set_window_size(1280, 720)

self.cleaner.find_element(By.ID, "id_username").click()
self.cleaner.find_element(By.ID, "id_username").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").click()
self.cleaner.find_element(By.ID, "id_password").send_keys("decide")

self.cleaner.find_element(By.ID, "id_password").send_keys("Keys.ENTER")

self.cleaner.get(self.live_server_url+"/admin/voting/question/add/")

self.cleaner.find_element(By.NAME, "_save").click()

self.assertTrue(self.cleaner.find_element_by_xpath('/html/body/div/div[3]/div/div[1]/div/form/div/p').text == 'Please correct the errors below.')
self.assertTrue(self.cleaner.current_url == self.live_server_url+"/admin/voting/question/add/")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage==6.5.0
jsonnet==0.18.0
django-nose==1.4.6
django-rest-swagger==2.2.0
selenium==4.7.2

0 comments on commit ca01211

Please sign in to comment.