Skip to content

Commit

Permalink
Merge pull request EGCETSII#27 from Decide-Part-Rota/Rota3-005
Browse files Browse the repository at this point in the history
feat: added discord_account field on Person model, it has a regex val…
  • Loading branch information
Abrcobgal authored Dec 14, 2022
2 parents 16cd9d2 + 3fc77b4 commit 4f31690
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
9 changes: 5 additions & 4 deletions decide/authentication/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -32,15 +33,15 @@ 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):
sex = forms.ChoiceField(choices=sexos, required=True)
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)



Expand Down
18 changes: 18 additions & 0 deletions decide/authentication/migrations/0007_person_discord_account.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 2 additions & 0 deletions decide/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
42 changes: 42 additions & 0 deletions decide/authentication/test_registro.py
Original file line number Diff line number Diff line change
@@ -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("[email protected]")
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 == '[email protected]'
6 changes: 4 additions & 2 deletions decide/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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('/')
Expand Down

0 comments on commit 4f31690

Please sign in to comment.