Skip to content

Commit

Permalink
Merge pull request #32 from egc-sierrezuela1/test/booth-23
Browse files Browse the repository at this point in the history
INTEGRAR LA RAMA EN DEVELOP
  • Loading branch information
javramarr1 authored Dec 27, 2021
2 parents 174da56 + ed27bfa commit c54425b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 8 deletions.
4 changes: 2 additions & 2 deletions decide/booth/templates/booth/booth.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ <h2>[[ voting.question.desc ]]</h2>
</b-form-radio>
</b-form-group>

<b-button type="button" variant="primary" v-on:click="decideSend">
<b-button id="voting_button" type="button" variant="primary" v-on:click="decideSend">
{% trans "Vote" %}
</b-button>
<b-button type="button" variant="primary" href="{% url "pagina-inicio" %}">Volver</b-button>
<b-button id="return_button" type="button" variant="primary" href="{% url "pagina-inicio" %}">Volver</b-button>

<br>
<p class="card-text mt-2">
Expand Down
2 changes: 1 addition & 1 deletion decide/booth/templates/booth/inicio.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1 class="display-2">Bienvenido, {{user}}</h1>
<tbody>
<tr>
<th scope="row"></th>
<td><a href="sugerenciaformulario/">Formulario de sugerencia</a></td>
<td><a id="id_sugerencias" href="sugerenciaformulario/">Formulario de sugerencia</a></td>
<td>
{% for censo in censos %}
<p>ID del voto: {{censo.voting_id}} <a href="{{censo.voting_id}}">Acceder a la cabina del voto</a></p>
Expand Down
2 changes: 1 addition & 1 deletion decide/booth/templates/booth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Remember me
</div>
</div>
<input type='submit' value='Iniciar sesion'>
<input type='submit' id='submit' value='Iniciar sesion'>
</form>
</div>

Expand Down
184 changes: 180 additions & 4 deletions decide/booth/tests.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import datetime
from django.contrib.auth import authenticate
from django.http import request

from django.test import TestCase
from django.test.client import Client, RequestFactory
from .forms import SugerenciaForm
from .models import Sugerencia
from voting.models import Question, QuestionOption, Voting
from census.models import Census
from store.models import Vote
from .views import check_unresolved_post_data, is_future_date, send_suggesting_form
from rest_framework.test import APIClient
from django.contrib.auth.models import User

from django.urls import reverse
from django.conf import settings
from django.utils import timezone
import requests

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 django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.common.exceptions import TimeoutException

from base.tests import BaseTestCase


from mixnet.models import Auth
Expand Down Expand Up @@ -160,4 +171,169 @@ def test_is_future_date_with_now_date(self):

def test_is_future_date_with_future_date(self):
date = timezone.now().date() + datetime.timedelta(weeks=1)
self.assertEqual(is_future_date(date), True)
self.assertEqual(is_future_date(date), True)


#--------------------------------------TEST NAVEGACION---------------------------------------------

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

LoginTest.setUp(self)

super().setUp()

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

def test_navigation_login(self):

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("voter1")
self.driver.find_element_by_name('password').send_keys("1234")
self.driver.find_element_by_id("submit").click()

print('ENTRA AQUI: ' + self.driver.current_url)
self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/')

def test_navigation_login_fail(self):
#Comprobamos que si no se introducen datos de inicio se mantiene en la pagina de login

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("failvoter")
self.driver.find_element_by_name('password').send_keys("fail")
self.driver.find_element_by_id('submit').click()

self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/login/')

def test_navigation_sugerencias_form(self):

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("voter1")
self.driver.find_element_by_name('password').send_keys("1234")
self.driver.find_element_by_id("submit").click()

self.driver.find_element_by_id("id_sugerencias").click()

self.driver.find_element_by_id('suggestingTitle').send_keys("Propuesta tests")
self.driver.find_element_by_id('suggestingDate').send_keys("01-01-2023")
self.driver.find_element_by_id('suggestingContent').send_keys("Propuesta para hacer una nueva votacion como parte de los test de navegacion")
self.driver.find_element_by_id('submitSugForm').click()

self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/')

def test_navegacion_sugerencias_form_empty_title(self):

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("voter1")
self.driver.find_element_by_name('password').send_keys("1234")
self.driver.find_element_by_id("submit").click()

self.driver.find_element_by_id("id_sugerencias").click()

self.driver.find_element_by_id('suggestingTitle').send_keys("")
self.driver.find_element_by_id('suggestingDate').send_keys("01-01-2023")
self.driver.find_element_by_id('suggestingContent').send_keys("Propuesta para hacer una nueva votacion como parte de los test de navegacion")
self.driver.find_element_by_id('submitSugForm').click()

self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/sugerenciaformulario/')

def test_navigation_sugerencias_form_empty_date(self):

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("voter1")
self.driver.find_element_by_name('password').send_keys("1234")
self.driver.find_element_by_id("submit").click()

self.driver.find_element_by_id("id_sugerencias").click()

self.driver.find_element_by_id('suggestingTitle').send_keys("Propuesta tests")
self.driver.find_element_by_id('suggestingDate').send_keys("")
self.driver.find_element_by_id('suggestingContent').send_keys("Propuesta para hacer una nueva votacion como parte de los test de navegacion")
self.driver.find_element_by_id('submitSugForm').click()

self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/sugerenciaformulario/')

def test_navigation_sugerencias_form_empty_content(self):

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("voter1")
self.driver.find_element_by_name('password').send_keys("1234")
self.driver.find_element_by_id("submit").click()

self.driver.find_element_by_id("id_sugerencias").click()

self.driver.find_element_by_id('suggestingTitle').send_keys("Propuesta tests")
self.driver.find_element_by_id('suggestingDate').send_keys("01-01-2023")
self.driver.find_element_by_id('suggestingContent').send_keys("")
self.driver.find_element_by_id('submitSugForm').click()

self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/sugerenciaformulario/')

class NavigationVotingTest(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.client = APIClient()
mods.mock_query(self.client)
u = User(id=1, username='voter1')
u.set_password('1234')
u.save()
token= mods.post('authentication', entry_point='/login/', json={'username':'voter1', 'password': '1234'})
#Add session token
session = self.client.session
session['user_token'] = token
session.save()

q = Question(id=2,desc='Question de prueba')
q.save()
for i in range(3):
opt = QuestionOption(question=q, option='Option {}'.format(i+1))
opt.save()

a, _ = Auth.objects.get_or_create(url=settings.BASEURL,defaults={'me':True,'name':'base'})
a.save()

v = Voting(id=1, name='Votacion de prueba',desc='Votaciones para los test', start_date=timezone.now(), question=q)
v.save()
v.auths.add(a)
Voting.create_pubkey(v)

census = Census(voting_id=v.id, voter_id=u.id)
census.save()

super().setUp()

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

def test_navegacion_voting_form(self):

self.driver.get(f'{self.live_server_url}/booth/login/')
self.driver.find_element_by_name('username').send_keys("voter1")
self.driver.find_element_by_name('password').send_keys("1234")
self.driver.find_element_by_id("submit").click()

self.driver.get(f'{self.live_server_url}/booth/1')

#Comprobamos que nos ha dejado entrar a la cabina de voto, lo que indica que la votacion existe y estamos en el censo
self.assertEquals(self.driver.current_url,f'{self.live_server_url}/booth/1/')

0 comments on commit c54425b

Please sign in to comment.