Skip to content

Commit

Permalink
Merge pull request EGCETSII#30 from Penyagolosa-3/visualizer-luibelzan
Browse files Browse the repository at this point in the history
Visualizer luibelzan
  • Loading branch information
luibelzan authored Jan 6, 2022
2 parents 61cee82 + 8a4d0eb commit 431554c
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 122 deletions.
23 changes: 23 additions & 0 deletions .github/issue_template.md
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
2 changes: 1 addition & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}

coverage-reports: decide/coverage.xml
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
5 changes: 1 addition & 4 deletions decide/decide/settings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""
Django settings for decide project.
Generated by 'django-admin startproject' using Django 2.0.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
Expand Down Expand Up @@ -218,4 +215,4 @@
]

import django_heroku
django_heroku.settings(locals(),test_runner=False)
django_heroku.settings(locals(),test_runner=False)
2 changes: 2 additions & 0 deletions decide/decide/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.urls import path, include
from django.views.decorators.csrf import csrf_exempt
from rest_framework_swagger.views import get_swagger_view
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from visualizer.views import TelegramBot
from django.views.generic import TemplateView
Expand All @@ -36,3 +37,4 @@
urlpatterns += [
path('{}/'.format(module), include('{}.urls'.format(module)))
]
urlpatterns+= staticfiles_urlpatterns()
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)
13 changes: 2 additions & 11 deletions decide/voting/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils import timezone


from .models import Detector, Percentage, QuestionOption
from .models import QuestionOption
from .models import Question
from .models import Voting

Expand Down Expand Up @@ -37,14 +37,6 @@ class QuestionOptionInline(admin.TabularInline):
class QuestionAdmin(admin.ModelAdmin):
inlines = [QuestionOptionInline]


class DetectorAdmin(admin.ModelAdmin):
model = Detector

class PercentageAdmin(admin.ModelAdmin):
model = Percentage


class VotingAdmin(admin.ModelAdmin):
list_display = ('name', 'start_date', 'end_date')
readonly_fields = ('start_date', 'end_date', 'pub_key',
Expand All @@ -56,7 +48,6 @@ class VotingAdmin(admin.ModelAdmin):
actions = [ start, stop, tally ]



admin.site.register(Voting, VotingAdmin)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Detector, DetectorAdmin)
admin.site.register(Percentage, PercentageAdmin)
14 changes: 14 additions & 0 deletions decide/voting/migrations/0007_merge_20220103_1820.py
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 = [
]
14 changes: 14 additions & 0 deletions decide/voting/migrations/0007_merge_20220104_1653.py
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 = [
]
19 changes: 19 additions & 0 deletions decide/voting/migrations/0008_auto_20220104_1653.py
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',
),
]
18 changes: 18 additions & 0 deletions decide/voting/migrations/0009_question_ynns_question.py
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'),
),
]
14 changes: 14 additions & 0 deletions decide/voting/migrations/0010_merge_20220105_1639.py
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 = [
]
Loading

0 comments on commit 431554c

Please sign in to comment.