Skip to content

Commit

Permalink
Merge pull request #45 from egc-sierrezuela-2/develop
Browse files Browse the repository at this point in the history
Actualización de rama store-03
  • Loading branch information
Alesancab1 authored Jan 6, 2022
2 parents 40301dd + 34731d9 commit 6ee122b
Show file tree
Hide file tree
Showing 10 changed files with 453 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ ENV/
.mypy_cache/

.vagrant
.vscode/settings.json
13 changes: 12 additions & 1 deletion decide/authentication/forms.py
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
19 changes: 19 additions & 0 deletions decide/authentication/migrations/0003_persona_edad.py
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,
),
]
1 change: 1 addition & 0 deletions decide/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class Persona(models.Model):
usuario = models.OneToOneField(User, on_delete=models.CASCADE)
sexo = models.CharField(max_length=30, blank=False)
ip = models.CharField(max_length=200)
edad = models.PositiveSmallIntegerField()
region = models.CharField(max_length=200)
276 changes: 276 additions & 0 deletions decide/authentication/testNavegation.py
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)
Loading

0 comments on commit 6ee122b

Please sign in to comment.