forked from EGCETSII/decide_django_2
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #45 from egc-sierrezuela-2/develop
Actualización de rama store-03
- Loading branch information
Showing
10 changed files
with
453 additions
and
13 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 |
---|---|---|
|
@@ -101,3 +101,4 @@ ENV/ | |
.mypy_cache/ | ||
|
||
.vagrant | ||
.vscode/settings.json |
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,9 +1,20 @@ | ||
# -*- encoding: utf-8 -*- | ||
from django import forms | ||
from django.contrib.auth.models import User | ||
from django.core.exceptions import ValidationError | ||
sexos=[("mujer","Mujer"),("hombre","Hombre"),("otro","Otro")] | ||
|
||
class RegisterForm(forms.Form): | ||
username = forms.CharField(label='Usuario',widget=forms.TextInput,required=True) | ||
email = forms.CharField(label='Email',widget=forms.EmailInput,required=True) | ||
password = forms.CharField(label='Contraseña',widget=forms.PasswordInput,required=True) | ||
sexo = forms.ChoiceField(choices=sexos, required=True, label="Seleccione su sexo") | ||
sexo = forms.ChoiceField(choices=sexos, required=True, label="Seleccione su sexo") | ||
edad = forms.IntegerField(required=True) | ||
|
||
|
||
|
||
def clean(self): | ||
email = self.cleaned_data.get('email') | ||
if User.objects.filter(email=email).exists(): | ||
raise ValidationError("Email exists") | ||
return self.cleaned_data |
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-05 17:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0002_auto_20211221_1947'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='persona', | ||
name='edad', | ||
field=models.PositiveSmallIntegerField(default=18), | ||
preserve_default=False, | ||
), | ||
] |
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,276 @@ | ||
from django.test import TestCase | ||
from rest_framework.test import APIClient | ||
from rest_framework.test import APITestCase | ||
from http import HTTPStatus | ||
from django.contrib.auth.models import User | ||
from rest_framework.authtoken.models import Token | ||
|
||
from .forms import RegisterForm | ||
from django.contrib.auth.forms import AuthenticationForm | ||
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 django.test import LiveServerTestCase | ||
from base.tests import BaseTestCase | ||
from selenium.webdriver.support.ui import Select | ||
|
||
from base import mods | ||
|
||
|
||
class AuthTestSelenium(LiveServerTestCase): | ||
|
||
def setUp(self): | ||
#Load base test functionality for decide | ||
self.base = BaseTestCase() | ||
self.base.setUp() | ||
|
||
options = webdriver.ChromeOptions() | ||
options.headless = False | ||
self.driver = webdriver.Chrome(options=options) | ||
|
||
u2 = User(username='pepe') | ||
u2.set_password('pepe') | ||
u2.email="[email protected]" | ||
u2.save() | ||
|
||
super().setUp() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self.driver.quit() | ||
|
||
self.base.tearDown() | ||
|
||
|
||
def test_simpleCorrectLogin(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/login-alt/') | ||
self.driver.find_element_by_id('id_username').send_keys("pepe") | ||
self.driver.find_element_by_id('id_password').send_keys("pepe",Keys.ENTER) | ||
|
||
|
||
print(self.driver.current_url) | ||
#Comprueba si redirige a la url correcta al loguearse correctamente | ||
self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/login-success/') | ||
|
||
def test_incorrectLoginUserNotExist(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/login-alt/') | ||
self.driver.find_element_by_id('id_username').send_keys("UsuarioNoExistente") | ||
self.driver.find_element_by_id('id_password').send_keys("UsuarioNoExistente",Keys.ENTER) | ||
|
||
text = "Error: Usuario o contraseña incorrectas." | ||
assert (text in self.driver.page_source) | ||
|
||
def test_incorrectLoginPassIncorrect(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/login-alt/') | ||
self.driver.find_element_by_id('id_username').send_keys("pepe") | ||
self.driver.find_element_by_id('id_password').send_keys("ContraseñaIncorrecta",Keys.ENTER) | ||
|
||
text = "Error: Usuario o contraseña incorrectas." | ||
assert (text in self.driver.page_source) | ||
|
||
def test_register(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
|
||
|
||
self.driver.find_element_by_id('id_username').send_keys("pepe1") | ||
self.driver.find_element_by_id('id_email').send_keys("[email protected]") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
#self.driver.find_element_by_class_name('btn').click() | ||
|
||
# Comprueba si redirige a la url correcta al loguearse correctamente | ||
self.driver.implicitly_wait(2) | ||
self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/login-success/') | ||
|
||
# Comprueba que el mensaje es el correcto | ||
text = "Has iniciado sesion con exito. Bienvenido, pepe1." | ||
assert (text in self.driver.page_source) | ||
|
||
|
||
def test_incorretRegisterUserAlreadyRegistered(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("admin") # Ya existente en la base de datos | ||
self.driver.find_element_by_id('id_email').send_keys("[email protected]") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
text = "Error: Usuario ya existente." | ||
assert (text in self.driver.page_source) | ||
|
||
def test_incorretRegisterEmailAlreadyRegistered(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("[email protected]") # Ya existente en la base de datos | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
text = "Email exists" | ||
assert (text in self.driver.page_source) | ||
|
||
def test_incorretRegisterEmailBadFormat1(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("a") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
email_input = self.driver.find_element_by_id('id_email') | ||
validation_message = email_input.get_attribute("validationMessage") | ||
|
||
alert = 'Incluye un signo "@" en la dirección de correo electrónico. La dirección "a" no incluye el signo "@".' | ||
assert (alert==validation_message) | ||
|
||
def test_incorretRegisterEmailBadFormat2(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("a@") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
email_input = self.driver.find_element_by_id('id_email') | ||
validation_message = email_input.get_attribute("validationMessage") | ||
|
||
alert = 'Introduce texto detrás del signo "a". La dirección "a@" está incompleta.' | ||
assert (alert==validation_message) | ||
|
||
def test_incorretRegisterEmailBadFormat2(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("a@.") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
email_input = self.driver.find_element_by_id('id_email') | ||
validation_message = email_input.get_attribute("validationMessage") | ||
|
||
alert = 'El signo "." está colocado en una posición incorrecta en la dirección ".".' | ||
assert (alert==validation_message) | ||
|
||
def test_incorretRegisterUserEmpty(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("") | ||
self.driver.find_element_by_id('id_email').send_keys("a") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
user_input = self.driver.find_element_by_id('id_username') | ||
validation_message = user_input.get_attribute("validationMessage") | ||
|
||
alert = 'Completa este campo' | ||
assert (alert==validation_message) | ||
|
||
def test_incorretRegisterEmailEmpty(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
email_input = self.driver.find_element_by_id('id_email') | ||
validation_message = email_input.get_attribute("validationMessage") | ||
|
||
alert = 'Completa este campo' | ||
assert (alert==validation_message) | ||
|
||
|
||
def test_incorretRegisterPasswordEmpty(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("[email protected]") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("12") | ||
self.driver.find_element_by_id('id_password').send_keys("",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
pass_input = self.driver.find_element_by_id('id_password') | ||
validation_message = pass_input.get_attribute("validationMessage") | ||
|
||
alert = 'Completa este campo' | ||
assert (alert==validation_message) | ||
|
||
def test_incorretRegisterAgeEmpty(self): | ||
self.driver.get(f'{self.live_server_url}/authentication/logout-alt/') | ||
self.driver.get(f'{self.live_server_url}/authentication/register-alt/') | ||
|
||
self.driver.find_element_by_id('id_username').send_keys("antonio") | ||
self.driver.find_element_by_id('id_email').send_keys("[email protected]") | ||
Select(self.driver.find_element_by_id('id_sexo')).select_by_visible_text('Hombre') | ||
self.driver.find_element_by_id('id_edad').send_keys("") | ||
self.driver.find_element_by_id('id_password').send_keys("contraseña",Keys.ENTER) | ||
|
||
|
||
# Comprueba que el mensaje es el correcto | ||
|
||
self.driver.implicitly_wait(10) | ||
|
||
edad_input = self.driver.find_element_by_id('id_edad') | ||
validation_message = edad_input.get_attribute("validationMessage") | ||
|
||
alert = 'Completa este campo' | ||
assert (alert==validation_message) |
Oops, something went wrong.