diff --git a/decide/authentication/forms.py b/decide/authentication/forms.py index b996d19afa..c6d9a5e6c8 100644 --- a/decide/authentication/forms.py +++ b/decide/authentication/forms.py @@ -3,19 +3,20 @@ from django.forms import ModelForm from django.contrib.auth.models import User from django.core.exceptions import ValidationError +from django.core.validators import RegexValidator from .models import Person from django.contrib.auth.forms import UserCreationForm from django_countries.fields import CountryField sexos=[("mujer","Mujer"),("hombre","Hombre"),("otro","Otro")] status=[("soltero","Soltero"),("conviviente","Conviviente"),("casado","Casado"),("divorciado","Divorciado"),("viudo","Viudo")] - - +discord_validator = RegexValidator('[a-zA-Z]#[1-9]{4}') class PersonForm(UserCreationForm): sex = forms.ChoiceField(choices=sexos, required=True, label="Seleccione su sexo") age = forms.IntegerField(required=False) status = forms.ChoiceField(choices=status, required=True, label="Seleccione su estado civil") + discord_account = forms.CharField(required=False, help_text="Please use the following format: name#XXXX", validators=[discord_validator], max_length=30) country = CountryField().formfield() def clean_age(self): @@ -32,8 +33,7 @@ def clean_age(self): class Meta: model=User - fields=["username","password1","password2","email","sex","age","status","country"] - + fields=["username","password1","password2","email","sex","age","status","country","discord_account"] class CompleteForm(forms.Form): @@ -41,6 +41,7 @@ class CompleteForm(forms.Form): age = forms.IntegerField(required=True) status = forms.ChoiceField(choices=status, required=True, label="Seleccione su estado civil") country = CountryField().formfield() + discord_account = forms.CharField(required=False, help_text="Please use the following format: name#XXXX", validators=[discord_validator], max_length=30) diff --git a/decide/authentication/migrations/0007_person_discord_account.py b/decide/authentication/migrations/0007_person_discord_account.py new file mode 100644 index 0000000000..dc2bdbbf10 --- /dev/null +++ b/decide/authentication/migrations/0007_person_discord_account.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0 on 2022-12-14 22:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0006_auto_20221202_0115'), + ] + + operations = [ + migrations.AddField( + model_name='person', + name='discord_account', + field=models.CharField(blank=True, max_length=30), + ), + ] diff --git a/decide/authentication/models.py b/decide/authentication/models.py index e48ace4f61..13043c9a13 100644 --- a/decide/authentication/models.py +++ b/decide/authentication/models.py @@ -10,6 +10,8 @@ class Person(models.Model): sex = models.CharField(max_length=30, blank=False) age = models.PositiveIntegerField() status = models.CharField(max_length=30, blank=False) + discord_account = models.CharField(max_length=30, blank=True) + country=CountryField() def __str__(self): diff --git a/decide/authentication/test_registro.py b/decide/authentication/test_registro.py new file mode 100644 index 0000000000..8c5f6c0734 --- /dev/null +++ b/decide/authentication/test_registro.py @@ -0,0 +1,42 @@ +from django.test import TestCase +from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from selenium import webdriver +from base.tests import BaseTestCase +from selenium.webdriver.common.by import By +from django.contrib.auth.models import User + +class testRegistro(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) + + def tearDown(self): + super().tearDown() + self.driver.quit() + self.base.tearDown() + + def testRegistroCorrecto(self): + #Crear server + self.driver.get(f'{self.live_server_url}') + self.driver.set_window_size(1366, 728) + + #Clickar en registrarse + self.driver.find_element(By.LINK_TEXT, "Registrarse").click() + + #Rellenar los campos + self.driver.find_element(By.ID, "id_username").send_keys("Voter1") + self.driver.find_element(By.ID, "id_password1").send_keys("Password 1") + self.driver.find_element(By.ID, "id_password2").send_keys("Password 1") + self.driver.find_element(By.ID, "id_email").send_keys("voter1@gmail.com") + self.driver.find_element(By.ID, "id_age").send_keys("18") + self.driver.find_element(By.ID, "id_country").send_keys("Spain") + self.driver.find_element(By.XPATH, "/html/body/div/form/button").click() + + #Comprobar redireccion y existencia del perfil + assert self.driver.find_element(By.LINK_TEXT, "Registrarse").text == 'Registrarse' + assert User.objects.get(username='Voter1').email == 'voter1@gmail.com' diff --git a/decide/authentication/views.py b/decide/authentication/views.py index e87426e2e3..493d28e560 100644 --- a/decide/authentication/views.py +++ b/decide/authentication/views.py @@ -116,9 +116,10 @@ def register(request): age = form.cleaned_data.get('age') status = form.cleaned_data.get('status') country = form.cleaned_data.get('country') + discord_account = form.cleaned_data.get('discord_account') inactive_user = send_verification_email(request, form) - person1=Person(user=inactive_user,sex=sex,age=age,status=status,country=country) + person1=Person(user=inactive_user,sex=sex,age=age,status=status,country=country,discord_account=discord_account) person1.save() @@ -154,8 +155,9 @@ def complete(request): age = form.cleaned_data.get('age') status = form.cleaned_data.get('status') country = form.cleaned_data.get('country') + discord_account = form.cleaned_data.get('discord_account') - person = Person(user = user, sex = sex, age = age,status=status,country=country) + person = Person(user = user, sex = sex, age = age,status=status,country=country, discord_account = discord_account) person.save() return redirect('/')