forked from EGCETSII/decide_django_2
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request EGCETSII#30 from Penyagolosa-3/visualizer-luibelzan
Visualizer luibelzan
- Loading branch information
Showing
20 changed files
with
326 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Title: Summary, imperative, start upper case, don't end with a period | ||
# No more than 50 chars. #### 50 chars is here: # | ||
|
||
# Remember blank line between title and body. | ||
|
||
# Body: Explain *what* and *why* (not *how*). | ||
# Wrap at 72 chars. ################################## which is here: # | ||
|
||
|
||
# At the end: Include Co-authored-by for all contributors. | ||
# Include at least one empty line before it. Format: | ||
# Co-authored-by: name <[email protected]> | ||
# | ||
# How to Write a Git Commit Message: | ||
# https://chris.beams.io/posts/git-commit/ | ||
# | ||
# 1.Separate subject from body with a blank line | ||
# 2. Limit the subject line to 50 characters | ||
# 3. Capitalize the subject line | ||
# 4. Do not end the subject line with a period | ||
# 5. Use the imperative mood in the subject line | ||
# 6. Wrap the body at 72 characters | ||
# 7. Use the body to explain what and why vs. how |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 2.0 on 2022-01-03 18:20 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('voting', '0006_auto_20211220_2225'), | ||
('voting', '0006_alter_voting_postproc_alter_voting_tally'), | ||
] | ||
|
||
operations = [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 2.0 on 2022-01-04 16:53 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('voting', '0006_auto_20211220_2225'), | ||
('voting', '0006_alter_voting_postproc_alter_voting_tally'), | ||
] | ||
|
||
operations = [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.0 on 2022-01-04 16:53 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('voting', '0007_merge_20220104_1653'), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name='Detector', | ||
), | ||
migrations.DeleteModel( | ||
name='Percentage', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.0 on 2022-01-05 12:07 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('voting', '0008_auto_20220104_1653'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='question', | ||
name='YNNS_question', | ||
field=models.BooleanField(default=False, help_text='Check the box to create a question of Yes, No or NS/NC', verbose_name='Answers Yes, No, NS/NC'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 2.0 on 2022-01-05 16:39 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('voting', '0007_merge_20220103_1820'), | ||
('voting', '0009_question_ynns_question'), | ||
] | ||
|
||
operations = [ | ||
] |
Oops, something went wrong.