Skip to content

Commit

Permalink
Merge pull request EGCETSII#32 from Decide-Part-Rota/Rota3-003
Browse files Browse the repository at this point in the history
Rota3-015
  • Loading branch information
RingoML authored Dec 17, 2022
2 parents e5248fa + 2cefc82 commit 56cd1db
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 6 deletions.
13 changes: 11 additions & 2 deletions decide/authentication/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
2 changes: 1 addition & 1 deletion decide/authentication/templates/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2 class="d-flex justify-content-center" style="margin: 20;">before proceeding<
{{form.as_table}}
</table>
<br>
<button type="submit" class="btn btn-outline-dark">Submit</button>
<button id="id_button" type="submit" class="btn btn-outline-dark">Submit</button>
</form>
</div>

Expand Down
190 changes: 189 additions & 1 deletion decide/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -327,4 +328,191 @@ def test_simpleIncorrectMailRegister(self):

print(self.live_server_url)

self.assertEqual(self.driver.title, 'Register')
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="[email protected]")
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')
2 changes: 1 addition & 1 deletion decide/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 56cd1db

Please sign in to comment.