Skip to content

Commit

Permalink
Merge branch 'temporal' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jesgamlar authored Jan 6, 2022
2 parents 8f4e919 + d0ceb04 commit de49bf4
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 38 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
matrix:
pyversion: ['3.5','3.8']


services:
postgres:
image: postgres:10.8
Expand Down Expand Up @@ -37,15 +38,13 @@ jobs:
pip install codacy-coverage
- name: Run migrations
run: cd decide;python manage.py migrate
- name: Run tests authentication
run: cd decide;coverage run --branch --source=. ./manage.py test authentication --keepdb; coverage xml;
- name: Run tests census
run: cd decide;coverage run --branch --source=. ./manage.py test census --keepdb; coverage xml;
- name: Run tests voting


- name: Run tests

run: cd decide;coverage run --branch --source=. ./manage.py test voting --keepdb; coverage xml;
- name: Codacy Coverage Reporter
uses: codacy/[email protected]
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}

coverage-reports: decide/coverage.xml
2 changes: 1 addition & 1 deletion decide/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
user_noadmin.set_password('qwerty')
user_noadmin.save()

user_admin = User(username='admin', is_staff=True)
user_admin = User(username='admin', is_staff=True, is_superuser=True)
user_admin.set_password('qwerty')
user_admin.save()

Expand Down
2 changes: 1 addition & 1 deletion decide/decide/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
'voting',
]


BASEURL = 'http://localhost:8000'

APIS = {
Expand All @@ -111,6 +110,7 @@
}



MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down
188 changes: 160 additions & 28 deletions decide/visualizer/tests.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,160 @@
from django.test import TestCase
from voting.tests import VotingTestCase
# Create your tests here.
class VisualizerTestCase(VotingTestCase):

def setUp(self):
super().setUp()

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

def voteTallied(self):
voting = self.create_voting()
self.login()
for action in ['start','stop', 'tally']:
data = {'action': action}
response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json')
return voting.pk

def test_recibir_votos(self):
votingpk = self.voteTallied()

data = {'update_id': 339892899, 'message': {'message_id': 285, 'from': {'id': 2004953283, 'is_bot': False, 'first_name': 'Lui', 'language_code': 'es'}, 'chat': {'id': 0, 'first_name': 'Lui', 'type': 'private'}, 'date': 1640018166, 'text': '/start', 'entities': [{'offset': 0, 'length': 6, 'type': 'bot_command'}]}}
response = self.client.put('/webhooks', data, format='json')
self.assertEqual(response.status_code, 301)
data2 = {'update_id': 339892900, 'message': {'message_id': 287, 'from': {'id': 2004953283, 'is_bot': False, 'first_name': 'Lui', 'language_code': 'es'}, 'chat': {'id': 0, 'first_name': 'Lui', 'type': 'private'}, 'date': 1640018174, 'text': '/visualizer {}'.format(votingpk), 'entities': [{'offset': 0, 'length': 11, 'type': 'bot_command'}]}}
response = self.client.post('/webhooks', data2, format='json')
self.assertEqual(response.status_code, 301)
from voting.tests import VotingTestCase
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
from selenium.webdriver.common.keys import Keys

from base.tests import BaseTestCase
import time

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

super().setUp()

def test_visualizer(self):
self.driver.get(self.live_server_url+'/admin/')
self.driver.find_element_by_id('id_username').send_keys("admin")
self.driver.find_element_by_id('id_password').send_keys("qwerty",Keys.ENTER)
time.sleep(2)
print(self.driver.current_url)
#In case of a correct loging, a element with id 'user-tools' is shown in the upper right part
self.assertTrue(len(self.driver.find_elements_by_id('user-tools'))==1)

#Vamos a crear la votación
self.driver.find_element(by=By.LINK_TEXT, value="Votings").click()
time.sleep(1)
self.driver.find_element(by=By.XPATH, value="/html/body/div/div[3]/div/ul/li/a").click()
self.driver.find_element_by_id('id_name').send_keys("Votacion de prueba")
self.driver.find_element_by_id('id_desc').send_keys("Vamos a probar si funcionan los tests")
time.sleep(1)
#Almaceno la ventana de la votacion
window_before = self.driver.window_handles[0]
#Añadimos las opciones
self.driver.find_element_by_id('add_id_question').click()
#Almaceno la ventana de las opciones
window_after = self.driver.window_handles[1]
time.sleep(1)
#Cambio de ventana
self.driver.switch_to_window(window_after)
self.driver.find_element_by_id('id_desc').send_keys("¿Funcionan las pruebas de decide?")
time.sleep(1)
self.driver.find_element_by_id('id_options-0-number').send_keys("1")
self.driver.find_element_by_id('id_options-0-option').send_keys("Si")
self.driver.find_element_by_id('id_options-1-number').send_keys("2")
self.driver.find_element_by_id('id_options-1-option').send_keys("No")
self.driver.find_element_by_id('id_options-2-number').send_keys("3")
self.driver.find_element_by_id('id_options-2-option').send_keys("Casi")
self.driver.find_element(by=By.XPATH, value="/html/body/div/div[1]/div/form/div/div[2]/input").click()
time.sleep(1)
#Volvemos a la ventana de las votaciones
self.driver.switch_to_window(window_before)
window_before = self.driver.window_handles[0]
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/form/div/fieldset/div[4]/div/div[1]/a/img').click()
window_after = self.driver.window_handles[1]
self.driver.switch_to_window(window_after)
self.driver.find_element_by_id('id_name').send_keys("http://localhost:8000")
self.driver.find_element_by_id('id_url').send_keys("http://localhost:8000")
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div[1]/div/form/div/div/input').click()
self.driver.switch_to_window(window_before)
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/form/div/div/input[1]').click()
time.sleep(1)
self.assertTrue(len(self.driver.find_elements_by_xpath('//*[@id="result_list"]/tbody/tr'))==1)
time.sleep(2)

#Iniciamos la votación
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/div/form/div[2]/table/tbody/tr[1]/td[1]/input').click()
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/div/form/div[1]/label/select/option[3]').click()
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/div/form/div[1]/button').click()
time.sleep(5)

#Añadimos usuario
self.driver.find_element_by_link_text('Home').click()
self.driver.find_element_by_link_text('Users').click()
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/ul/li/a').click()
time.sleep(1)
self.driver.find_element_by_id('id_username').send_keys('User1')
self.driver.find_element_by_id('id_password1').send_keys('contraseña1')
self.driver.find_element_by_id('id_password2').send_keys('contraseña1')
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/form/div/div/input[1]').click()
time.sleep(1)
self.driver.find_element_by_link_text('Home').click()
self.driver.find_element_by_link_text('Users').click()
time.sleep(3)

self.assertTrue(len(self.driver.find_elements_by_xpath('//*[@id="result_list"]/tbody/tr'))==3)
time.sleep(2)

#Añadimos censo
self.driver.find_element_by_link_text('Home').click()
self.driver.find_element_by_link_text('Censuss').click()
time.sleep(1)
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/ul/li/a').click()
time.sleep(1)
self.driver.find_element_by_id('id_voting_id').send_keys("1")
self.driver.find_element_by_id('id_voter_id').send_keys("2")
self.driver.find_element_by_xpath('/html/body/div/div[3]/div/form/div/div/input[1]').click()
time.sleep(2)
self.assertTrue(len(self.driver.find_elements_by_xpath('//*[@id="result_list"]/tbody/tr'))==1)

#Se realiza la votacion
#self.driver.get(self.live_server_url+'/booth/1/')
#self.driver.find_element_by_id('username').send_keys("admin")
#self.driver.find_element_by_id('password').send_keys("qwerty", Keys.ENTER)
#time.sleep(1)
#self.driver.find_element_by_id('q1').click()

#self.driver.find_element_by_xpath('/html/body/div/div/div/button').click()
#time.sleep(2)


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

self.base.tearDown()


class VisualizerTestCase(VotingTestCase):

def setUp(self):
super().setUp()

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

def voteTallied(self):
voting = self.create_voting()
self.login()
for action in ['start','stop', 'tally']:
data = {'action': action}
response = self.client.put('/voting/{}/'.format(voting.pk), data, format='json')
return voting.pk

def test_recibir_votos(self):
votingpk = self.voteTallied()

data = {'update_id': 339892899, 'message': {'message_id': 285, 'from': {'id': 2004953283, 'is_bot': False, 'first_name': 'Lui', 'language_code': 'es'}, 'chat': {'id': 0, 'first_name': 'Lui', 'type': 'private'}, 'date': 1640018166, 'text': '/start', 'entities': [{'offset': 0, 'length': 6, 'type': 'bot_command'}]}}
response = self.client.put('/webhooks', data, format='json')
self.assertEqual(response.status_code, 301)
data2 = {'update_id': 339892900, 'message': {'message_id': 287, 'from': {'id': 2004953283, 'is_bot': False, 'first_name': 'Lui', 'language_code': 'es'}, 'chat': {'id': 0, 'first_name': 'Lui', 'type': 'private'}, 'date': 1640018174, 'text': '/visualizer {}'.format(votingpk), 'entities': [{'offset': 0, 'length': 11, 'type': 'bot_command'}]}}
response = self.client.post('/webhooks', data2, format='json')
self.assertEqual(response.status_code, 301)
2 changes: 0 additions & 2 deletions decide/voting/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


import unicodedata

def lofensivo(value):
Expand All @@ -25,7 +24,6 @@ def lofensivo(value):
value = unicodedata.normalize('NFKC', unicodedata.normalize('NFKD', value).translate(trans_tab))
palabras = value.split()


porcentaje= 20 / 100

cont = 0
Expand Down

0 comments on commit de49bf4

Please sign in to comment.