diff --git a/decide/authentication/forms.py b/decide/authentication/forms.py
index afa01e100c..05a43fbf01 100644
--- a/decide/authentication/forms.py
+++ b/decide/authentication/forms.py
@@ -45,12 +45,21 @@ class Meta:
class CompleteForm(forms.Form):
- sex = forms.ChoiceField(choices=sexos, required=True)
- age = forms.IntegerField(required=True)
+ 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")
country = CountryField().formfield()
discord_account = forms.CharField(required=False, help_text="Please use the following format: name#XXXX", validators=[discord_validator], max_length=30)
+ def clean_age(self):
+ data = self.cleaned_data["age"]
+
+ if not data:
+ self.add_error("age", "Debes especificar una edad")
+
+ if data == 0:
+ self.add_error("age", "Introduce una edad valida")
+ return data
diff --git a/decide/authentication/templates/complete.html b/decide/authentication/templates/complete.html
index 021e9d0589..3ffdd198eb 100644
--- a/decide/authentication/templates/complete.html
+++ b/decide/authentication/templates/complete.html
@@ -19,7 +19,7 @@
before proceeding<
{{form.as_table}}
- Submit
+ Submit
diff --git a/decide/authentication/tests.py b/decide/authentication/tests.py
index 6a3415abb9..7d82aa7df4 100644
--- a/decide/authentication/tests.py
+++ b/decide/authentication/tests.py
@@ -3,6 +3,7 @@
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
+from authentication.models import Person
from rest_framework.authtoken.models import Token
from base import mods
@@ -327,4 +328,191 @@ def test_simpleIncorrectMailRegister(self):
print(self.live_server_url)
- self.assertEqual(self.driver.title, 'Register')
\ No newline at end of file
+ self.assertEqual(self.driver.title, 'Register')
+
+
+class CompleteTestCase(StaticLiveServerTestCase):
+
+ def setUp(self):
+ self.base = BaseTestCase()
+ self.base.setUp()
+
+ options = webdriver.ChromeOptions()
+ options.headless = True
+ self.driver = webdriver.Chrome(options=options)
+
+ u = User(username='voter1', email="voter1@gmail.com")
+ u.set_password('123')
+ u.save()
+
+ p = Person.objects.filter(user=User.objects.get(username='voter1'))
+ if p.exists():
+ p[0].delete()
+
+ super().setUp()
+
+
+ def tearDown(self):
+ super().tearDown()
+ self.driver.quit()
+ self.base.tearDown()
+
+
+ def test_user_without_person(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ def test_user_with_person(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ self.driver.find_element(By.ID,'id_sex').send_keys("Hombre")
+ self.driver.find_element(By.ID,'id_age').send_keys("20")
+ self.driver.find_element(By.ID,'id_status').send_keys("Soltero")
+ self.driver.find_element(By.ID,'id_country').send_keys("Andorra")
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#0123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Inicio')
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Inicio')
+
+
+ def test_simpleCorrectComplete(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ self.driver.find_element(By.ID,'id_sex').send_keys("Hombre")
+ self.driver.find_element(By.ID,'id_age').send_keys("20")
+ self.driver.find_element(By.ID,'id_status').send_keys("Soltero")
+ self.driver.find_element(By.ID,'id_country').send_keys("Andorra")
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#0123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Inicio')
+
+ def test_simpleIncorrectSexComplete(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+ # Probar un complete con sexo invalido
+ self.driver.find_element(By.ID,'id_sex').send_keys("Helicoptero")
+ self.driver.find_element(By.ID,'id_age').send_keys("0")
+ self.driver.find_element(By.ID,'id_status').send_keys("Soltero")
+ self.driver.find_element(By.ID,'id_country').send_keys("Andorra")
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#0123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ print(self.live_server_url)
+
+ self.assertEqual(self.driver.title, 'Complete')
+
+ def test_simpleIncorrectAgeComplete(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ self.driver.find_element(By.ID,'id_sex').send_keys("Hombre")
+ # Probar un complete con una edad invalida
+ self.driver.find_element(By.ID,'id_age').send_keys("0")
+ self.driver.find_element(By.ID,'id_status').send_keys("Soltero")
+ self.driver.find_element(By.ID,'id_country').send_keys("Andorra")
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#0123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+
+ print(self.live_server_url)
+
+ self.assertEqual(self.driver.title, 'Complete')
+
+ def test_simpleIncorrectStatusComplete(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ self.driver.find_element(By.ID,'id_sex').send_keys("Hombre")
+ self.driver.find_element(By.ID,'id_age').send_keys("0")
+ # Probar un complete con estado invalido
+ self.driver.find_element(By.ID,'id_status').send_keys("A dos velas")
+ self.driver.find_element(By.ID,'id_country').send_keys("Andorra")
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#0123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.assertEqual(self.driver.title, 'Complete')
+
+ def test_simpleIncorrectCountryComplete(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ self.driver.find_element(By.ID,'id_sex').send_keys("Hombre")
+ self.driver.find_element(By.ID,'id_age').send_keys("0")
+ self.driver.find_element(By.ID,'id_status').send_keys("Soltero")
+ # Probar un complete con pais invalido
+ self.driver.find_element(By.ID,'id_country').send_keys("Sevilla")
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#0123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.assertEqual(self.driver.title, 'Complete')
+
+ def test_simpleIncorrectDiscordAccountComplete(self):
+ self.driver.get(f'{self.live_server_url}/authentication/accounts/login/')
+ self.driver.find_element(By.ID,'id_username').send_keys("voter1")
+ self.driver.find_element(By.ID,'id_password').send_keys("123")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.driver.get(f'{self.live_server_url}/authentication/completeForm/')
+ print(self.live_server_url)
+ self.assertEqual(self.driver.title, 'Complete')
+
+ self.driver.find_element(By.ID,'id_sex').send_keys("Hombre")
+ self.driver.find_element(By.ID,'id_age').send_keys("20")
+ self.driver.find_element(By.ID,'id_status').send_keys("Soltero")
+ self.driver.find_element(By.ID,'id_country').send_keys("Andorra")
+ # Probar un complete con cuenta de discord invalida
+ self.driver.find_element(By.ID,'id_discord_account').send_keys("name#012")
+ self.driver.find_element(By.ID,'id_button').send_keys(Keys.ENTER)
+
+ self.assertEqual(self.driver.title, 'Complete')
diff --git a/decide/authentication/views.py b/decide/authentication/views.py
index a546dae21b..cb1e6740d3 100644
--- a/decide/authentication/views.py
+++ b/decide/authentication/views.py
@@ -157,7 +157,7 @@ def complete(request):
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, discord_account = discord_account)
+ person = Person(user = user, sex = sex, age = age, status = status, country = country, discord_account = discord_account)
person.save()
return redirect('/')
diff --git a/requirements.txt b/requirements.txt
index b8c554d348..a2f4484c6a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,5 +13,5 @@ django-allauth==0.51.0
django-verify-email==2.0.3
python-decouple==3.6
django-countries==7.4.2
-selenium==4.7.2
+selenium