diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a0a3f9..6f7ea90 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,11 +2,11 @@ name: Innosoft eventos GA on: push: - branches: + branches: - main - feature/** pull_request: - branches: + branches: - main env: @@ -30,7 +30,7 @@ jobs: ports: - 3307:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - + steps: - uses: actions/checkout@v2 - name: Verify and configure MySQL connection @@ -49,13 +49,13 @@ jobs: pip install codacy-coverage sudo apt-get install chromium-browser chromium-chromedriver - name: Make Migrations and Migrate - run: | + run: | python ./manage.py makemigrations python ./manage.py migrate - name: Run Tests - run: | - coverage run --branch --source=. ./manage.py test --keepdb - coverage xml + run: | + coverage run --branch --source=. ./manage.py test --keepdb + coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1 with: diff --git a/.gitignore b/.gitignore index 0391a33..6568192 100644 --- a/.gitignore +++ b/.gitignore @@ -7,10 +7,10 @@ __pycache__ media /**/migrations/** -# Backup files # -*.bak +# Backup files # +*.bak -# If you are using PyCharm # +# If you are using PyCharm # # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml @@ -46,93 +46,93 @@ out/ # JIRA plugin atlassian-ide-plugin.xml -# Python # -*.py[cod] -*$py.class - -# Distribution / packaging -.Python build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -.pytest_cache/ -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery -celerybeat-schedule.* - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# Sublime Text # -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache -*.sublime-workspace -*.sublime-project - -# sftp configuration file -sftp-config.json - -# Package control specific files Package -Control.last-run -Control.ca-list -Control.ca-bundle -Control.system-ca-bundle -GitHub.sublime-settings - -# Visual Studio Code # -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -.vscode/launch.json -!.vscode/extensions.json +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Sublime Text # +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +.vscode/launch.json +!.vscode/extensions.json .history \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 447f735..fd4f3cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,7 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer + types: [python, javascript, html, css] - repo: https://github.com/psf/black rev: 22.12.0 hooks: diff --git a/accounts/apps.py b/accounts/apps.py index 3e3c765..0cb51e6 100644 --- a/accounts/apps.py +++ b/accounts/apps.py @@ -2,5 +2,5 @@ class AccountsConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'accounts' + default_auto_field = "django.db.models.BigAutoField" + name = "accounts" diff --git a/accounts/forms.py b/accounts/forms.py index cff8e60..cd11492 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -5,10 +5,18 @@ from participant.models import Participant + class RegisterForm(UserCreationForm): email = forms.EmailField() class Meta: model = Participant - fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2', 'photo'] - + fields = [ + "username", + "first_name", + "last_name", + "email", + "password1", + "password2", + "photo", + ] diff --git a/accounts/templates/register.html b/accounts/templates/register.html index 5d1aea8..0100939 100644 --- a/accounts/templates/register.html +++ b/accounts/templates/register.html @@ -10,7 +10,7 @@ {% block content %}
- +
diff --git a/accounts/urls.py b/accounts/urls.py index 5562fc0..ad0864a 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -2,5 +2,5 @@ from accounts.views import * urlpatterns = [ - path('', register, name="register"), -] \ No newline at end of file + path("", register, name="register"), +] diff --git a/accounts/views.py b/accounts/views.py index abed32c..be0e7c7 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -4,12 +4,13 @@ # Create your views here. + def register(request): - if request.method == 'POST': + if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): form.save() - return redirect('/') + return redirect("/") else: form = RegisterForm() - return render(request, 'register.html', {'form': form}) + return render(request, "register.html", {"form": form}) diff --git a/docker-compose.yml b/docker-compose.yml index a18d245..f7130e9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: "3" -services: +services: db: image: mysql:8 environment: @@ -12,12 +12,12 @@ services: MYSQL_TCP_PORT: "3307" ports: - "3306:3307" - + web: build: . command: > - sh -c "python manage.py makemigrations && - python manage.py migrate && + sh -c "python manage.py makemigrations && + python manage.py migrate && python manage.py runserver 0.0.0.0:8000" volumes: - .:/code @@ -28,4 +28,4 @@ services: deploy: restart_policy: condition: on-failure - + diff --git a/event/admin.py b/event/admin.py index 2a1c12f..70ed94b 100644 --- a/event/admin.py +++ b/event/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from .models import Event + # Register your models here. -admin.site.register(Event) \ No newline at end of file +admin.site.register(Event) diff --git a/event/apps.py b/event/apps.py index 49fdd6a..52dbc82 100644 --- a/event/apps.py +++ b/event/apps.py @@ -2,5 +2,5 @@ class EventConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'event' + default_auto_field = "django.db.models.BigAutoField" + name = "event" diff --git a/event/models.py b/event/models.py index f75d5db..0f2ee9f 100644 --- a/event/models.py +++ b/event/models.py @@ -3,26 +3,37 @@ # Create your models here. + class Event(models.Model): name = models.CharField(max_length=100, help_text="Nombre del evento") description = models.TextField() date = models.DateTimeField() place = models.CharField(max_length=100, help_text="Lugar del evento") - photo = models.URLField(max_length=10000, help_text="Url de la imagen del evento", blank=True) - status = models.CharField(choices=[('Abierto','Abierto'),('En proceso','En proceso'), ('Finalizado', 'Finalizado')], default='Abierto', max_length=100) - + photo = models.URLField( + max_length=10000, help_text="Url de la imagen del evento", blank=True + ) + status = models.CharField( + choices=[ + ("Abierto", "Abierto"), + ("En proceso", "En proceso"), + ("Finalizado", "Finalizado"), + ], + default="Abierto", + max_length=100, + ) + def save(self, *args, **kwargs): - if self.status not in ['Abierto', 'En proceso', 'Finalizado']: - raise ValueError('Status no válido') + if self.status not in ["Abierto", "En proceso", "Finalizado"]: + raise ValueError("Status no válido") val = URLValidator() val(self.photo) if self.name == "": - raise ValueError('Name is blank') + raise ValueError("Name is blank") if self.description == "": - raise ValueError('Description is blank') + raise ValueError("Description is blank") if self.place == "": - raise ValueError('Place is blank') + raise ValueError("Place is blank") super(Event, self).save(*args, **kwargs) def __str__(self): - return self.name \ No newline at end of file + return self.name diff --git a/event/tests.py b/event/tests.py index 217ef59..da9a37e 100644 --- a/event/tests.py +++ b/event/tests.py @@ -9,22 +9,38 @@ # Create your tests here. class EventTestCase(TestCase): def setUp(self): - Event.objects.create(name="EventName", description="EventDescription is this", date=datetime.datetime.now(), place="Etsii", photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Abierto") - Event.objects.create(name="EventUpdate", description="EventUpdateDescription is this", date=datetime.datetime.now(), place="UpdateEtsii2", photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Abierto") - + Event.objects.create( + name="EventName", + description="EventDescription is this", + date=datetime.datetime.now(), + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) + Event.objects.create( + name="EventUpdate", + description="EventUpdateDescription is this", + date=datetime.datetime.now(), + place="UpdateEtsii2", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) def test_event_create(self): event = Event.objects.get(name="EventName") self.assertEqual(event.description, "EventDescription is this") self.assertEqual(event.place, "Etsii") - self.assertEqual(event.photo, "https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000") + self.assertEqual( + event.photo, + "https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + ) self.assertEqual(event.status, "Abierto") - + def test_event_delete(self): event = Event.objects.get(name="EventName") event.delete() self.assertEqual(Event.objects.count(), 1) - + def test_event_update(self): event = Event.objects.get(name="EventName") event.name = "NewEventName" @@ -38,80 +54,122 @@ def test_event_update(self): self.assertEqual(event_nuevo.name, "NewEventName") self.assertEqual(event_nuevo.description, "NewDescription") self.assertEqual(event_nuevo.place, "NewPlace") - self.assertEqual(event_nuevo.photo, "https://cdn.portalfruticola.com/2020/01/8dc0c7b7-maquinaria-campo-adobestock_188819540.jpeg") + self.assertEqual( + event_nuevo.photo, + "https://cdn.portalfruticola.com/2020/01/8dc0c7b7-maquinaria-campo-adobestock_188819540.jpeg", + ) self.assertEqual(event_nuevo.status, "En proceso") - - #Create tests + + # Create tests def test_event_create_photo_incorrect(self): - with self.assertRaises(Exception): - event = Event(name="EventName", description="EventDescription is this", date=datetime.datetime.now(), place="Etsii", photo="Han Solo", status="Abierto") + with self.assertRaises(Exception): + event = Event( + name="EventName", + description="EventDescription is this", + date=datetime.datetime.now(), + place="Etsii", + photo="Han Solo", + status="Abierto", + ) event.save() def test_event_create_status_incorrect(self): - with self.assertRaises(Exception): - event = Event(name="EventName", description="EventDescription is this", date=datetime.datetime.now(), place="Etsii", photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Han Solo") + with self.assertRaises(Exception): + event = Event( + name="EventName", + description="EventDescription is this", + date=datetime.datetime.now(), + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Han Solo", + ) event.save() - + def test_event_create_name_blank(self): - with self.assertRaises(Exception): - event = Event(description="EventDescription is this", date=datetime.datetime.now(), place="Etsii", photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Abierto") + with self.assertRaises(Exception): + event = Event( + description="EventDescription is this", + date=datetime.datetime.now(), + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) event.save() - + def test_event_create_description_blank(self): - with self.assertRaises(Exception): - event = Event(name="EventName", date=datetime.datetime.now(), place="Etsii", photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Abierto") + with self.assertRaises(Exception): + event = Event( + name="EventName", + date=datetime.datetime.now(), + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) event.save() def test_event_create_date_blank(self): - with self.assertRaises(Exception): - event = Event(name="EventName", description="EventDescription is this", place="Etsii", photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Abierto") + with self.assertRaises(Exception): + event = Event( + name="EventName", + description="EventDescription is this", + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) event.save() def test_event_create_place_blank(self): - with self.assertRaises(Exception): - event = Event(name="EventName", description="EventDescription is this", date=datetime.datetime.now(), photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", status="Abierto") + with self.assertRaises(Exception): + event = Event( + name="EventName", + description="EventDescription is this", + date=datetime.datetime.now(), + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) event.save() # #Update tests def test_event_update_photo_incorrect(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): event = Event.objects.get(name="EventUpdate") event.photo = "Han Solo" event.save() - + def test_event_update_status_incorrect(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): event = Event.objects.get(name="EventUpdate") event.status = "Han Solo" event.save() - + def test_event_update_name_blank(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): event = Event.objects.get(name="EventUpdate") event.name = "" event.save() - + def test_event_update_description_blank(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): event = Event.objects.get(name="EventUpdate") event.description = "" event.save() - + def test_event_update_date_blank(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): event = Event.objects.get(name="EventUpdate") event.date = "" event.save() - + def test_event_update_place_blank(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): event = Event.objects.get(name="EventUpdate") event.place = "" event.save() - + + class EventDetailViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] @classmethod def setUpClass(cls): @@ -125,26 +183,24 @@ def tearDownClass(cls): cls.browser.quit() super(EventDetailViewTest, cls).tearDownClass() - def test_title(self): events = Event.objects.all() - + titles = ["Innoweb - " + event.name for event in events] for i in range(len(titles)): - self.browser.get(self.live_server_url +'/evento/' + str(events[i].id)) - + self.browser.get(self.live_server_url + "/evento/" + str(events[i].id)) + assert self.browser.title == titles[i] - def test_event_detail(self): events = Event.objects.all() for event in events: - self.browser.get(self.live_server_url +'/evento/' + str(event.id)) - #find element by class name - name = self.browser.find_element(By.CLASS_NAME, 'title-event') - image = self.browser.find_element(By.CLASS_NAME, 'event-image') - description = self.browser.find_element(By.CLASS_NAME, 'event-description') + self.browser.get(self.live_server_url + "/evento/" + str(event.id)) + # find element by class name + name = self.browser.find_element(By.CLASS_NAME, "title-event") + image = self.browser.find_element(By.CLASS_NAME, "event-image") + description = self.browser.find_element(By.CLASS_NAME, "event-description") self.assertEqual(name.text, event.name) self.assertEqual(image.get_attribute("src"), event.photo) @@ -152,33 +208,33 @@ def test_event_detail(self): self.assertIn(event.place, description.text) self.assertIn(event.date.strftime("%d/%m/%Y a las %H:%M"), description.text) - status = self.browser.find_element(By.ID, 'status') + status = self.browser.find_element(By.ID, "status") self.assertEqual(status.text, event.status) def test_count_participants_in_event(self): events = Event.objects.all() for event in events: - scores = Score.objects.filter(event=event).order_by('-value') - self.browser.get(self.live_server_url +'/evento/' + str(event.id)) - rows = self.browser.find_elements(By.XPATH, '//table/tbody/tr') + scores = Score.objects.filter(event=event).order_by("-value") + self.browser.get(self.live_server_url + "/evento/" + str(event.id)) + rows = self.browser.find_elements(By.XPATH, "//table/tbody/tr") self.assertEqual(len(rows), len(scores)) def test_participants_in_event(self): - + events = Event.objects.all() for event in events: - scores = Score.objects.filter(event=event).order_by('-value') - self.browser.get(self.live_server_url +'/evento/' + str(event.id)) - rows = self.browser.find_elements(By.XPATH, '//table/tbody/tr') - for i in range(len(rows)-1): - TABLE_ROW = '//table/tbody/tr['+str(i+1)+']' - position = self.browser.find_element(By.XPATH, TABLE_ROW +'/td[1]') - name = self.browser.find_element(By.XPATH, TABLE_ROW +'/td[2]') - - surnames = self.browser.find_element(By.XPATH, TABLE_ROW +'/td[3]') - score = self.browser.find_element(By.XPATH, TABLE_ROW + '/td[4]') - - self.assertEqual(position.text, str(i+1)) + scores = Score.objects.filter(event=event).order_by("-value") + self.browser.get(self.live_server_url + "/evento/" + str(event.id)) + rows = self.browser.find_elements(By.XPATH, "//table/tbody/tr") + for i in range(len(rows) - 1): + TABLE_ROW = "//table/tbody/tr[" + str(i + 1) + "]" + position = self.browser.find_element(By.XPATH, TABLE_ROW + "/td[1]") + name = self.browser.find_element(By.XPATH, TABLE_ROW + "/td[2]") + + surnames = self.browser.find_element(By.XPATH, TABLE_ROW + "/td[3]") + score = self.browser.find_element(By.XPATH, TABLE_ROW + "/td[4]") + + self.assertEqual(position.text, str(i + 1)) self.assertEqual(name.text, scores[i].participant.first_name) self.assertEqual(surnames.text, scores[i].participant.last_name) self.assertEqual(score.text, str(scores[i].value)) @@ -186,13 +242,29 @@ def test_participants_in_event(self): def test_participants_in_podium(self): events = Event.objects.all() for event in events: - scores = Score.objects.filter(event=event).order_by('-value') - self.browser.get(self.live_server_url +'/evento/' + str(event.id)) - if(len(scores) > 0): + scores = Score.objects.filter(event=event).order_by("-value") + self.browser.get(self.live_server_url + "/evento/" + str(event.id)) + if len(scores) > 0: for i in range(3): - username = self.browser.find_elements(By.CLASS_NAME, 'podium-item')[i].find_element(By.CLASS_NAME, 'podium-winner-wrapper').find_element(By.CLASS_NAME, 'podium-winner').text - photo = self.browser.find_elements(By.CLASS_NAME, 'podium-item')[i].find_element(By.CLASS_NAME, 'podium-winner-wrapper').find_element(By.CLASS_NAME, 'podium-photo').get_attribute("src") - position = self.browser.find_elements(By.CLASS_NAME, 'podium-item')[i].find_element(By.CLASS_NAME, 'podium-position').text - - self.assertEqual(username, scores[int(position)-1].participant.get_username()) - self.assertEqual(photo, scores[int(position)-1].participant.photo) + username = ( + self.browser.find_elements(By.CLASS_NAME, "podium-item")[i] + .find_element(By.CLASS_NAME, "podium-winner-wrapper") + .find_element(By.CLASS_NAME, "podium-winner") + .text + ) + photo = ( + self.browser.find_elements(By.CLASS_NAME, "podium-item")[i] + .find_element(By.CLASS_NAME, "podium-winner-wrapper") + .find_element(By.CLASS_NAME, "podium-photo") + .get_attribute("src") + ) + position = ( + self.browser.find_elements(By.CLASS_NAME, "podium-item")[i] + .find_element(By.CLASS_NAME, "podium-position") + .text + ) + + self.assertEqual( + username, scores[int(position) - 1].participant.get_username() + ) + self.assertEqual(photo, scores[int(position) - 1].participant.photo) diff --git a/event/urls.py b/event/urls.py index 45e3c6e..bb38baa 100644 --- a/event/urls.py +++ b/event/urls.py @@ -2,6 +2,6 @@ from . import views urlpatterns = [ - path('', views.event_view, name='event'), - path('join/', views.join_event, name='join_event'), + path("", views.event_view, name="event"), + path("join/", views.join_event, name="join_event"), ] diff --git a/event/views.py b/event/views.py index 681b47f..08848c1 100644 --- a/event/views.py +++ b/event/views.py @@ -3,11 +3,12 @@ from score.models import Score from django.contrib import messages + def event_view(request, id): e = Event.objects.get(id=id) - scores = Score.objects.filter(event=e).order_by('-value').exclude(value=None) + scores = Score.objects.filter(event=e).order_by("-value").exclude(value=None) first = None second = None @@ -26,13 +27,12 @@ def event_view(request, id): e.date = e.date.strftime("%d/%m/%Y a las %H:%M") - return render(request, "base_EVENT.html", { - "e": e, - "scores": scores, - "first": first, - "second": second, - "third": third - }) + return render( + request, + "base_EVENT.html", + {"e": e, "scores": scores, "first": first, "second": second, "third": third}, + ) + def join_event(request, id): if request.user.is_authenticated: @@ -40,15 +40,16 @@ def join_event(request, id): scores = Score.objects.filter(event=event) # if the user is not in the scores if not scores.filter(participant=request.user).exists(): - score = Score(participant=request.user, event=event, value=None) # create a new score with value null + score = Score( + participant=request.user, event=event, value=None + ) # create a new score with value null score.save() - messages.success(request, 'Te has unido al evento correctamente') - + messages.success(request, "Te has unido al evento correctamente") + else: - messages.warning(request, 'Ya estás inscrito en el evento') - - + messages.warning(request, "Ya estás inscrito en el evento") + else: - messages.error(request, 'Debes iniciar sesión para unirte a un evento') - - return redirect('event', id=id) \ No newline at end of file + messages.error(request, "Debes iniciar sesión para unirte a un evento") + + return redirect("event", id=id) diff --git a/git-message.txt b/git-message.txt index 86013af..d4a8f3d 100644 --- a/git-message.txt +++ b/git-message.txt @@ -4,7 +4,7 @@
################################################################################### -# Allowed values: +# Allowed values: # feat (new feature) # fix (bug fix) # docs (changes to documentation) diff --git a/innoweb/asgi.py b/innoweb/asgi.py index 11bcc08..6b19c5b 100644 --- a/innoweb/asgi.py +++ b/innoweb/asgi.py @@ -11,6 +11,6 @@ from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'innoweb.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "innoweb.settings") application = get_asgi_application() diff --git a/innoweb/deployment_settings.py b/innoweb/deployment_settings.py index 1f2b64e..fb9cb4a 100644 --- a/innoweb/deployment_settings.py +++ b/innoweb/deployment_settings.py @@ -21,72 +21,74 @@ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = config('DJANGO_SECRET_KEY', default="_Z~I/9Vb8l#+~PtD>;PJPgW?eh^+_x#xyZ3x~D%%I<0mo-&Jq-") +SECRET_KEY = config( + "DJANGO_SECRET_KEY", default="_Z~I/9Vb8l#+~PtD>;PJPgW?eh^+_x#xyZ3x~D%%I<0mo-&Jq-" +) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [ - '127.0.0.1', - 'localhost', + "127.0.0.1", + "localhost", ] # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'participant.apps.ParticipantConfig', - 'event.apps.EventConfig', - 'score.apps.ScoreConfig', - 'accounts.apps.AccountsConfig', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "participant.apps.ParticipantConfig", + "event.apps.EventConfig", + "score.apps.ScoreConfig", + "accounts.apps.AccountsConfig", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'innoweb.urls' +ROOT_URLCONF = "innoweb.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - BASE_DIR / 'templates', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [ + BASE_DIR / "templates", ], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, }, ] -WSGI_APPLICATION = 'innoweb.wsgi.application' +WSGI_APPLICATION = "innoweb.wsgi.application" # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", } } @@ -96,16 +98,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] @@ -113,9 +115,9 @@ # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ -LANGUAGE_CODE = 'es' +LANGUAGE_CODE = "es" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -125,7 +127,7 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = "static/" STATICFILES_DIRS = [ BASE_DIR / "static", @@ -134,8 +136,8 @@ # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -AUTH_USER_MODEL = 'participant.Participant' +AUTH_USER_MODEL = "participant.Participant" -LOGIN_REDIRECT_URL = '/' +LOGIN_REDIRECT_URL = "/" diff --git a/innoweb/development_settings.py b/innoweb/development_settings.py index 6eccdf1..9c99c0e 100644 --- a/innoweb/development_settings.py +++ b/innoweb/development_settings.py @@ -23,76 +23,76 @@ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = config('DJANGO_SECRET_KEY') +SECRET_KEY = config("DJANGO_SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [ - '127.0.0.1', - 'localhost', + "127.0.0.1", + "localhost", ] # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'participant.apps.ParticipantConfig', - 'event.apps.EventConfig', - 'score.apps.ScoreConfig', - 'accounts.apps.AccountsConfig', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "participant.apps.ParticipantConfig", + "event.apps.EventConfig", + "score.apps.ScoreConfig", + "accounts.apps.AccountsConfig", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'innoweb.urls' +ROOT_URLCONF = "innoweb.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - BASE_DIR / 'templates', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [ + BASE_DIR / "templates", ], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, }, ] -WSGI_APPLICATION = 'innoweb.wsgi.application' +WSGI_APPLICATION = "innoweb.wsgi.application" # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE' : 'django.db.backends.mysql', - 'NAME' : 'innowebdb', - 'USER' : 'innosoft', - 'PASSWORD': 'innosoft-2022', - 'HOST' : os.environ.get('HOST_URL', '127.0.0.1'), - 'PORT' : '3307', + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": "innowebdb", + "USER": "innosoft", + "PASSWORD": "innosoft-2022", + "HOST": os.environ.get("HOST_URL", "127.0.0.1"), + "PORT": "3307", } } @@ -102,16 +102,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] @@ -119,9 +119,9 @@ # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ -LANGUAGE_CODE = 'es' +LANGUAGE_CODE = "es" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -131,7 +131,7 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = "static/" STATICFILES_DIRS = [ BASE_DIR / "static", @@ -142,16 +142,16 @@ # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -AUTH_USER_MODEL = 'participant.Participant' +AUTH_USER_MODEL = "participant.Participant" -LOGIN_REDIRECT_URL = '/' +LOGIN_REDIRECT_URL = "/" MESSAGE_TAGS = { - messages.DEBUG: 'alert-secondary', - messages.INFO: 'alert-info', - messages.SUCCESS: 'alert-success', - messages.WARNING: 'alert-warning', - messages.ERROR: 'alert-danger', - } \ No newline at end of file + messages.DEBUG: "alert-secondary", + messages.INFO: "alert-info", + messages.SUCCESS: "alert-success", + messages.WARNING: "alert-warning", + messages.ERROR: "alert-danger", +} diff --git a/innoweb/production_settings.py b/innoweb/production_settings.py index 5010044..ea28a24 100644 --- a/innoweb/production_settings.py +++ b/innoweb/production_settings.py @@ -22,74 +22,74 @@ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = config('DJANGO_SECRET_KEY') +SECRET_KEY = config("DJANGO_SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False ALLOWED_HOSTS = [ - 'innosoftinnoweb.pythonanywhere.com', + "innosoftinnoweb.pythonanywhere.com", ] # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'participant.apps.ParticipantConfig', - 'event.apps.EventConfig', - 'score.apps.ScoreConfig', - 'accounts.apps.AccountsConfig', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "participant.apps.ParticipantConfig", + "event.apps.EventConfig", + "score.apps.ScoreConfig", + "accounts.apps.AccountsConfig", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'innoweb.urls' +ROOT_URLCONF = "innoweb.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - BASE_DIR / 'templates', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [ + BASE_DIR / "templates", ], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, }, ] -WSGI_APPLICATION = 'innoweb.wsgi.application' +WSGI_APPLICATION = "innoweb.wsgi.application" # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE' : 'django.db.backends.mysql', - 'NAME' : 'innosoftinnoweb$innowebdb', - 'USER' : config('PRODUCTION_DB_USER'), - 'PASSWORD': config('PRODUCTION_DB_PASSWORD'), - 'HOST' : 'innosoftinnoweb.mysql.pythonanywhere-services.com', + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": "innosoftinnoweb$innowebdb", + "USER": config("PRODUCTION_DB_USER"), + "PASSWORD": config("PRODUCTION_DB_PASSWORD"), + "HOST": "innosoftinnoweb.mysql.pythonanywhere-services.com", } } @@ -99,16 +99,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] @@ -116,9 +116,9 @@ # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ -LANGUAGE_CODE = 'es' +LANGUAGE_CODE = "es" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -128,7 +128,7 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = "static/" STATICFILES_DIRS = [ BASE_DIR / "static", @@ -139,16 +139,16 @@ # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -AUTH_USER_MODEL = 'participant.Participant' +AUTH_USER_MODEL = "participant.Participant" -LOGIN_REDIRECT_URL = '/' +LOGIN_REDIRECT_URL = "/" MESSAGE_TAGS = { - messages.DEBUG: 'alert-secondary', - messages.INFO: 'alert-info', - messages.SUCCESS: 'alert-success', - messages.WARNING: 'alert-warning', - messages.ERROR: 'alert-danger', - } \ No newline at end of file + messages.DEBUG: "alert-secondary", + messages.INFO: "alert-info", + messages.SUCCESS: "alert-success", + messages.WARNING: "alert-warning", + messages.ERROR: "alert-danger", +} diff --git a/innoweb/tests.py b/innoweb/tests.py index 0f4a752..a1b18fe 100644 --- a/innoweb/tests.py +++ b/innoweb/tests.py @@ -7,8 +7,9 @@ from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys + class HomeViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] @classmethod def setUpClass(cls): @@ -29,7 +30,7 @@ def test_title(self): def test_podium(self): self.browser.get(self.live_server_url) - podium_items = self.browser.find_elements(By.CSS_SELECTOR, '.podium-item') + podium_items = self.browser.find_elements(By.CSS_SELECTOR, ".podium-item") # get winners from db [first, second, third] = self.get_global_winners() winners = [second, first, third] @@ -37,31 +38,39 @@ def test_podium(self): # check if there are only 3 winners assert len(podium_items) == 3 - positions = ['2', '1', '3'] + positions = ["2", "1", "3"] for podium_item, winner, position in zip(podium_items, winners, positions): # check if position is correct - podium_position = podium_item.find_element(By.CSS_SELECTOR, '.podium-position') + podium_position = podium_item.find_element( + By.CSS_SELECTOR, ".podium-position" + ) assert podium_position.text == position # check if winner is correct - podium_winner = podium_item.find_element(By.CSS_SELECTOR, '.podium-winner') + podium_winner = podium_item.find_element(By.CSS_SELECTOR, ".podium-winner") assert podium_winner.text == winner.username # check if winners link redirects to profile - podium_link = podium_item.find_element(By.CSS_SELECTOR, 'a') - assert podium_link.get_attribute('href') == self.live_server_url + '/participante/' + str(winner.id) + podium_link = podium_item.find_element(By.CSS_SELECTOR, "a") + assert podium_link.get_attribute( + "href" + ) == self.live_server_url + "/participante/" + str(winner.id) # check if winners img is correct - podium_link = podium_item.find_element(By.CSS_SELECTOR, 'img') - assert podium_link.get_attribute('src') == winner.photo + podium_link = podium_item.find_element(By.CSS_SELECTOR, "img") + assert podium_link.get_attribute("src") == winner.photo def test_open_events(self): self.browser.get(self.live_server_url) - event_containers = self.browser.find_elements(By.CSS_SELECTOR, '.events-container') + event_containers = self.browser.find_elements( + By.CSS_SELECTOR, ".events-container" + ) - open_events_cards = event_containers[0].find_elements(By.CSS_SELECTOR, 'a.event-card') + open_events_cards = event_containers[0].find_elements( + By.CSS_SELECTOR, "a.event-card" + ) open_events = Event.objects.filter(status="Abierto") self.check_events_cards(self, open_events_cards, open_events) @@ -69,9 +78,13 @@ def test_open_events(self): def test_current_events(self): self.browser.get(self.live_server_url) - event_containers = self.browser.find_elements(By.CSS_SELECTOR, '.events-container') + event_containers = self.browser.find_elements( + By.CSS_SELECTOR, ".events-container" + ) - current_events_cards = event_containers[1].find_elements(By.CSS_SELECTOR, 'a.event-card') + current_events_cards = event_containers[1].find_elements( + By.CSS_SELECTOR, "a.event-card" + ) current_events = Event.objects.filter(status="En proceso") self.check_events_cards(self, current_events_cards, current_events) @@ -79,9 +92,13 @@ def test_current_events(self): def test_past_events(self): self.browser.get(self.live_server_url) - event_containers = self.browser.find_elements(By.CSS_SELECTOR, '.events-container') + event_containers = self.browser.find_elements( + By.CSS_SELECTOR, ".events-container" + ) - past_events_cards = event_containers[2].find_elements(By.CSS_SELECTOR, 'a.event-card') + past_events_cards = event_containers[2].find_elements( + By.CSS_SELECTOR, "a.event-card" + ) past_events = Event.objects.filter(status="Finalizado") self.check_events_cards(self, past_events_cards, past_events) @@ -98,19 +115,21 @@ def check_events_cards(cls, self, events_cards, events): @classmethod def check_event_card(cls, self, event_card, event): # check if card title is correct - card_title = event_card.find_element(By.CSS_SELECTOR, '.title-event') + card_title = event_card.find_element(By.CSS_SELECTOR, ".title-event") assert card_title.text == event.name # check if card link redirects to event - assert event_card.get_attribute('href') == self.live_server_url + '/evento/' + str(event.id) + assert event_card.get_attribute( + "href" + ) == self.live_server_url + "/evento/" + str(event.id) # check if card img is correct - card_img = event_card.find_element(By.CSS_SELECTOR, '.event-image') - assert card_img.get_attribute('src') == event.photo + card_img = event_card.find_element(By.CSS_SELECTOR, ".event-image") + assert card_img.get_attribute("src") == event.photo @classmethod def get_global_winners(cls): - scores = Score.objects.order_by('-value') + scores = Score.objects.order_by("-value") first = None second = None @@ -141,8 +160,9 @@ def get_global_winners(cls): winners = [first, second, third] return winners + class LoginViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] @classmethod def setUpClass(cls): @@ -155,58 +175,56 @@ def setUpClass(cls): def tearDownClass(cls): cls.browser.quit() super(LoginViewTest, cls).tearDownClass() - + def test_login_success(self): - + username = "userTest" password = "Testpassword17" PORT = self.live_server_url.split(":")[2] self.browser.get(self.live_server_url) self.browser.get("http://localhost:" + PORT + "/login") - - + self.browser.find_element("name", "username").send_keys(username) - - self.browser.find_element("name","password").send_keys(password) - + + self.browser.find_element("name", "password").send_keys(password) + self.browser.find_element("name", "submit").click() - - assert self.browser.find_element(By.CLASS_NAME,"podium").is_enabled() == True - - + + assert self.browser.find_element(By.CLASS_NAME, "podium").is_enabled() == True + def test_login_username_fail(self): username = "incorrectusername" password = "Testpassword17" PORT = self.live_server_url.split(":")[2] self.browser.get(self.live_server_url) self.browser.get("http://localhost:" + PORT + "/login") - - + self.browser.find_element("name", "username").send_keys(username) - - self.browser.find_element("name","password").send_keys(password) - + + self.browser.find_element("name", "password").send_keys(password) + self.browser.find_element("name", "submit").click() - - assert len(self.browser.find_elements("id","error-form")) == 1 - + + assert len(self.browser.find_elements("id", "error-form")) == 1 + def test_login_password_fail(self): username = "userTest" password = "incorrectpassword" PORT = self.live_server_url.split(":")[2] self.browser.get(self.live_server_url) self.browser.get("http://localhost:" + PORT + "/login") - - + self.browser.find_element("name", "username").send_keys(username) - - self.browser.find_element("name","password").send_keys(password) - + + self.browser.find_element("name", "password").send_keys(password) + self.browser.find_element("name", "submit").click() - - assert len(self.browser.find_elements("id","error-form")) == 1 + + assert len(self.browser.find_elements("id", "error-form")) == 1 + + class RegisterViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] username = "usernameTest" firstname = "firstnameTest" lastname = "Lastname Test" @@ -219,7 +237,7 @@ class RegisterViewTest(StaticLiveServerTestCase): def setUpClass(cls): super(RegisterViewTest, cls).setUpClass() options = webdriver.ChromeOptions() - options.headless= True + options.headless = True cls.browser = webdriver.Chrome(options=options) @classmethod @@ -227,82 +245,191 @@ def tearDownClass(cls): cls.browser.quit() super(RegisterViewTest, cls).tearDownClass() - def send_keys(self, username, firstname, lastname, email, password, password2, photo): + def send_keys( + self, username, firstname, lastname, email, password, password2, photo + ): if username is not None: - self.browser.find_element('id','id_username').send_keys(username) + self.browser.find_element("id", "id_username").send_keys(username) if firstname is not None: - self.browser.find_element('id','id_first_name').send_keys(firstname) + self.browser.find_element("id", "id_first_name").send_keys(firstname) if lastname is not None: - self.browser.find_element('id','id_last_name').send_keys(lastname) + self.browser.find_element("id", "id_last_name").send_keys(lastname) if email is not None: - self.browser.find_element('id','id_email').send_keys(email) + self.browser.find_element("id", "id_email").send_keys(email) if password is not None: - self.browser.find_element('id','id_password1').send_keys(password) + self.browser.find_element("id", "id_password1").send_keys(password) if password2 is not None: - self.browser.find_element('id','id_password2').send_keys(password2) + self.browser.find_element("id", "id_password2").send_keys(password2) if photo is not None: - self.browser.find_element('id','id_photo').send_keys(photo) - self.browser.find_element('id','id_submit_button').send_keys(Keys.RETURN) - + self.browser.find_element("id", "id_photo").send_keys(photo) + self.browser.find_element("id", "id_submit_button").send_keys(Keys.RETURN) + def test_register_success(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, self.email, self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"podium").is_enabled() == True + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + self.email, + self.password, + self.password2, + self.photo, + ) + assert self.browser.find_element(By.CLASS_NAME, "podium").is_enabled() == True def test_register_username_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(None, self.firstname, self.lastname, self.email, self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + None, + self.firstname, + self.lastname, + self.email, + self.password, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_firstname_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, None, self.lastname, self.email, self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + None, + self.lastname, + self.email, + self.password, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_lastname_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, None, self.email, self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + None, + self.email, + self.password, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_email_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, None, self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + None, + self.password, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) def test_register_password_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, self.email, None, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + self.email, + None, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_password2_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, self.email, self.password, None, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + self.email, + self.password, + None, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_username_exist_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys("juasaljur", self.firstname, self.lastname, self.email, self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + "juasaljur", + self.firstname, + self.lastname, + self.email, + self.password, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_email_exist_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, "juasaljur@alum.us.es", self.password, self.password2, self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + "juasaljur@alum.us.es", + self.password, + self.password2, + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_password_different_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, self.email, self.password, "estaEsMiPassword18", self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True - + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + self.email, + self.password, + "estaEsMiPassword18", + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + def test_register_password_weak_fail(self): - self.browser.get(self.live_server_url + '/registro/') - self.send_keys(self.username, self.firstname, self.lastname, self.email, "hola", "hola", self.photo) - assert self.browser.find_element(By.CLASS_NAME,"errorlist").is_enabled() == True + self.browser.get(self.live_server_url + "/registro/") + self.send_keys( + self.username, + self.firstname, + self.lastname, + self.email, + "hola", + "hola", + self.photo, + ) + assert ( + self.browser.find_element(By.CLASS_NAME, "errorlist").is_enabled() == True + ) + - - class EventViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] @classmethod def setUpClass(cls): @@ -315,7 +442,7 @@ def setUpClass(cls): def tearDownClass(cls): cls.browser.quit() super(EventViewTest, cls).tearDownClass() - + def test_register_event(self): username = "userTest" password = "Testpassword17" @@ -324,55 +451,64 @@ def test_register_event(self): self.browser.get("http://localhost:" + PORT + "/login") self.browser.find_element("name", "username").send_keys(username) - - self.browser.find_element("name","password").send_keys(password) - + + self.browser.find_element("name", "password").send_keys(password) + self.browser.find_element("name", "submit").click() - + self.browser.get(self.live_server_url) - event_cards = self.browser.find_elements(By.CSS_SELECTOR, 'a.event-card') - first_event_ulr = event_cards[0].get_attribute('href') + event_cards = self.browser.find_elements(By.CSS_SELECTOR, "a.event-card") + first_event_ulr = event_cards[0].get_attribute("href") self.browser.get(first_event_ulr) - register_button = self.browser.find_element(By.CSS_SELECTOR, 'a.sign-up') + register_button = self.browser.find_element(By.CSS_SELECTOR, "a.sign-up") register_button.click() - assert self.browser.find_element(By.CLASS_NAME,"alert-success").is_enabled() == True - + assert ( + self.browser.find_element(By.CLASS_NAME, "alert-success").is_enabled() + == True + ) + def test_register_event_already_registered(self): username = "userTest" password = "Testpassword17" PORT = self.live_server_url.split(":")[2] self.browser.get(self.live_server_url) self.browser.get("http://localhost:" + PORT + "/login") - + self.browser.find_element("name", "username").send_keys(username) - - self.browser.find_element("name","password").send_keys(password) - + + self.browser.find_element("name", "password").send_keys(password) + self.browser.find_element("name", "submit").click() - + self.browser.get(self.live_server_url) - event_cards = self.browser.find_elements(By.CSS_SELECTOR, 'a.event-card') - first_event_ulr = event_cards[0].get_attribute('href') + event_cards = self.browser.find_elements(By.CSS_SELECTOR, "a.event-card") + first_event_ulr = event_cards[0].get_attribute("href") self.browser.get(first_event_ulr) - register_button = self.browser.find_element(By.CSS_SELECTOR, 'a.sign-up') + register_button = self.browser.find_element(By.CSS_SELECTOR, "a.sign-up") register_button.click() self.browser.get(first_event_ulr) - register_button = self.browser.find_element(By.CSS_SELECTOR, 'a.sign-up') + register_button = self.browser.find_element(By.CSS_SELECTOR, "a.sign-up") register_button.click() - assert self.browser.find_element(By.CLASS_NAME,"alert-warning").is_enabled() == True - + assert ( + self.browser.find_element(By.CLASS_NAME, "alert-warning").is_enabled() + == True + ) def test_register_event_without_login(self): self.browser.get(self.live_server_url) - event_cards = self.browser.find_elements(By.CSS_SELECTOR, 'a.event-card') - first_event_ulr = event_cards[0].get_attribute('href') + event_cards = self.browser.find_elements(By.CSS_SELECTOR, "a.event-card") + first_event_ulr = event_cards[0].get_attribute("href") self.browser.get(first_event_ulr) - register_button = self.browser.find_element(By.CSS_SELECTOR, 'a.sign-up') + register_button = self.browser.find_element(By.CSS_SELECTOR, "a.sign-up") register_button.click() - assert self.browser.find_element(By.CLASS_NAME,"alert-danger").is_enabled() == True + assert ( + self.browser.find_element(By.CLASS_NAME, "alert-danger").is_enabled() + == True + ) + class ProfileViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] @classmethod def setUpClass(cls): @@ -385,7 +521,7 @@ def setUpClass(cls): def tearDownClass(cls): cls.browser.quit() super(ProfileViewTest, cls).tearDownClass() - + def test_next_events_are_shown(self): username = "userTest" password = "Testpassword17" @@ -394,19 +530,22 @@ def test_next_events_are_shown(self): self.browser.get("http://localhost:" + PORT + "/login") self.browser.find_element("name", "username").send_keys(username) - - self.browser.find_element("name","password").send_keys(password) - + + self.browser.find_element("name", "password").send_keys(password) + self.browser.find_element("name", "submit").click() - + self.browser.get(self.live_server_url) - event_cards = self.browser.find_elements(By.CSS_SELECTOR, 'a.event-card') - first_event_ulr = event_cards[0].get_attribute('href') + event_cards = self.browser.find_elements(By.CSS_SELECTOR, "a.event-card") + first_event_ulr = event_cards[0].get_attribute("href") self.browser.get(first_event_ulr) - register_button = self.browser.find_element(By.CSS_SELECTOR, 'a.sign-up') + register_button = self.browser.find_element(By.CSS_SELECTOR, "a.sign-up") register_button.click() - profile_url = self.browser.find_element(By.CSS_SELECTOR, 'a.navbar-link-primary').get_attribute('href') + profile_url = self.browser.find_element( + By.CSS_SELECTOR, "a.navbar-link-primary" + ).get_attribute("href") self.browser.get(profile_url) - assert self.browser.find_element(By.CSS_SELECTOR, 'td.event-name').is_enabled() == True - - + assert ( + self.browser.find_element(By.CSS_SELECTOR, "td.event-name").is_enabled() + == True + ) diff --git a/innoweb/urls.py b/innoweb/urls.py index f9d9c54..b7f9f08 100644 --- a/innoweb/urls.py +++ b/innoweb/urls.py @@ -21,12 +21,16 @@ urlpatterns = [ - path('admin/', admin.site.urls), - path('registro/', include('accounts.urls')), - path('', home, name='home'), - path('evento/', include('event.urls')), - path('', include('django.contrib.auth.urls')), - path('participante/', include('participant.urls')), - path('puntuacion/', include('score.urls')), - path('certificate//', certificate, name='certificate'), + path("admin/", admin.site.urls), + path("registro/", include("accounts.urls")), + path("", home, name="home"), + path("evento/", include("event.urls")), + path("", include("django.contrib.auth.urls")), + path("participante/", include("participant.urls")), + path("puntuacion/", include("score.urls")), + path( + "certificate//", + certificate, + name="certificate", + ), ] diff --git a/innoweb/views.py b/innoweb/views.py index a5e4769..a53406d 100644 --- a/innoweb/views.py +++ b/innoweb/views.py @@ -12,29 +12,28 @@ # view for testing components def index(request): - return render(request, 'index.html') + return render(request, "index.html") + def home(request): - future_events = Event.objects.filter(status='Abierto') - current_events = Event.objects.filter(status='En proceso') - past_events = Event.objects.filter(status='Finalizado') + future_events = Event.objects.filter(status="Abierto") + current_events = Event.objects.filter(status="En proceso") + past_events = Event.objects.filter(status="Finalizado") - if request.GET.get('logout') == 'logout': - logout(request) + if request.GET.get("logout") == "logout": + logout(request) user = None if request.user.is_authenticated: user = request.user - - scores = Score.objects.order_by('-value').exclude(value=None) + scores = Score.objects.order_by("-value").exclude(value=None) first = None second = None third = None - if len(scores) > 0: scores_dict = {} for score in scores: @@ -43,7 +42,6 @@ def home(request): else: scores_dict[score.participant] = score.value - participants = sorted(scores_dict, key=scores_dict.get, reverse=True) if len(participants) >= 3: @@ -58,15 +56,18 @@ def home(request): first = participants[0] first.username = first.get_username() - return render(request, 'base_HOME.html', + return render( + request, + "base_HOME.html", { - 'current_events': current_events, - 'past_events': past_events, - 'future_events': future_events, - 'first': first, - 'second': second, - 'third': third - }) + "current_events": current_events, + "past_events": past_events, + "future_events": future_events, + "first": first, + "second": second, + "third": third, + }, + ) def certificate(request, event_id, participant_id): @@ -76,23 +77,25 @@ def certificate(request, event_id, participant_id): score = Score.objects.get(event=e, participant=participant) - certificate = Image.open("static\images\Sample_certificate.png") certificate.load() certificate = certificate.convert("RGB") - new = ImageDraw.Draw(certificate) font = ImageFont.truetype(r"BRUSHSCI.TTF", 90) font_small = ImageFont.truetype(r"BRUSHSCI.TTF", 50) new.text((498, 518), participant.get_complete_name(), (0, 0, 0), font=font) new.text((757, 620), e.name, (0, 0, 0), font=font_small) - new.text((560, 690), datetime.strftime(e.date, "%d/%m/%Y"), (0, 0, 0), font=font_small) + new.text( + (560, 690), datetime.strftime(e.date, "%d/%m/%Y"), (0, 0, 0), font=font_small + ) new.text((890, 690), e.place, (0, 0, 0), font=font_small) new.text((1000, 757), str(score.value), (0, 0, 0), font=font_small) certificate.save("static\certificates\Certificado.pdf", "PDF", resolution=180.0) - - return FileResponse(open("static\certificates\Certificado.pdf", 'rb'), content_type='application/pdf') \ No newline at end of file + return FileResponse( + open("static\certificates\Certificado.pdf", "rb"), + content_type="application/pdf", + ) diff --git a/innoweb/wsgi.py b/innoweb/wsgi.py index 95ea353..02c9574 100644 --- a/innoweb/wsgi.py +++ b/innoweb/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'innoweb.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "innoweb.settings") application = get_wsgi_application() diff --git a/loadtest/locustfile.py b/loadtest/locustfile.py index 11c49ea..e5c6855 100644 --- a/loadtest/locustfile.py +++ b/loadtest/locustfile.py @@ -1,72 +1,71 @@ -from locust import ( - HttpUser, - SequentialTaskSet, - TaskSet, - task, - between -) - -''' +from locust import HttpUser, SequentialTaskSet, TaskSet, task, between + +""" Para ejecutar los tests de carga: - 1. Vaciar tablas de la base de datos + 1. Vaciar tablas de la base de datos 2. Para poblarla con datos estáticos, ejecutar el siguiente comando: python manage.py loaddata "fixtures/initial.json" -''' +""" HOST = "http://localhost:8000" PARTICIPANT_ID = 2 EVENT_ID = 1 -class DefHome(TaskSet): +class DefHome(TaskSet): @task def home(self): self.client.get("") -class DefLogin(TaskSet): +class DefLogin(TaskSet): @task def login(self): self.client.get("/login") -class DefRegister(TaskSet): +class DefRegister(TaskSet): @task def register(self): self.client.get("/registro") -class DefParticipantProfile(TaskSet): +class DefParticipantProfile(TaskSet): @task def participant_profile(self): self.client.get("/participante/{0}".format(PARTICIPANT_ID)) -class DefEventDetails(TaskSet): +class DefEventDetails(TaskSet): @task def event_details(self): self.client.get("/evento/{0}".format(EVENT_ID)) + class Home(HttpUser): host = HOST tasks = [DefHome] - wait_time = between(3,5) + wait_time = between(3, 5) + class Login(HttpUser): host = HOST tasks = [DefLogin] - wait_time = between(3,5) + wait_time = between(3, 5) + class Register(HttpUser): host = HOST tasks = [DefRegister] - wait_time = between(3,5) + wait_time = between(3, 5) + class ParticipantProfile(HttpUser): host = HOST tasks = [DefParticipantProfile] - wait_time = between(3,5) + wait_time = between(3, 5) + class EventDetails(HttpUser): host = HOST tasks = [DefEventDetails] - wait_time = between(3,5) \ No newline at end of file + wait_time = between(3, 5) diff --git a/manage.py b/manage.py index 4447d9b..6702744 100644 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'innoweb.development_settings') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "innoweb.development_settings") try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -18,5 +18,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/participant/admin.py b/participant/admin.py index ad24366..5362691 100644 --- a/participant/admin.py +++ b/participant/admin.py @@ -2,54 +2,51 @@ from django.contrib.auth.admin import UserAdmin from .models import Participant + # Register your models here. + class ParticipantAdmin(UserAdmin): model = Participant - list_display = ( - 'username', 'email', 'first_name', 'last_name', 'photo' - ) + list_display = ("username", "email", "first_name", "last_name", "photo") fieldsets = ( - (None, { - 'fields': ('username', 'password') - }), - ('Personal info', { - 'fields': ('first_name', 'last_name', 'email') - }), - ('Permissions', { - 'fields': ( - 'is_active', 'is_staff', 'is_superuser', - 'groups', 'user_permissions' + (None, {"fields": ("username", "password")}), + ("Personal info", {"fields": ("first_name", "last_name", "email")}), + ( + "Permissions", + { + "fields": ( + "is_active", + "is_staff", + "is_superuser", + "groups", + "user_permissions", ) - }), - ('Important dates', { - 'fields': ('last_login', 'date_joined') - }), - ('Additional info', { - 'fields': (['photo']) - }) + }, + ), + ("Important dates", {"fields": ("last_login", "date_joined")}), + ("Additional info", {"fields": (["photo"])}), ) add_fieldsets = ( - (None, { - 'fields': ('username', 'password1', 'password2') - }), - ('Personal info', { - 'fields': ('first_name', 'last_name', 'email') - }), - ('Permissions', { - 'fields': ( - 'is_active', 'is_staff', 'is_superuser', - 'groups', 'user_permissions' + (None, {"fields": ("username", "password1", "password2")}), + ("Personal info", {"fields": ("first_name", "last_name", "email")}), + ( + "Permissions", + { + "fields": ( + "is_active", + "is_staff", + "is_superuser", + "groups", + "user_permissions", ) - }), - ('Important dates', { - 'fields': ('last_login', 'date_joined') - }), - ('Additional info', { - 'fields': ((['photo'])) - }) + }, + ), + ("Important dates", {"fields": ("last_login", "date_joined")}), + ("Additional info", {"fields": ((["photo"]))}), ) -admin.site.register(Participant, ParticipantAdmin) \ No newline at end of file + +admin.site.register(Participant, ParticipantAdmin) diff --git a/participant/apps.py b/participant/apps.py index c25c05b..32ba838 100644 --- a/participant/apps.py +++ b/participant/apps.py @@ -2,5 +2,5 @@ class ParticipantConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'participant' + default_auto_field = "django.db.models.BigAutoField" + name = "participant" diff --git a/participant/models.py b/participant/models.py index 19d2e49..e9fff73 100644 --- a/participant/models.py +++ b/participant/models.py @@ -1,13 +1,21 @@ from django.db import models from django.contrib.auth.models import AbstractUser -from django.core.validators import EmailValidator,URLValidator +from django.core.validators import EmailValidator, URLValidator + class Participant(AbstractUser): - id = models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID') + id = models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ) first_name = models.CharField(("first name"), max_length=150) last_name = models.CharField(("last name"), max_length=150) email = models.EmailField(unique=True) - photo = models.URLField(max_length=200, help_text="Introduce la url de tu foto", blank=True, default="http://cdn.onlinewebfonts.com/svg/img_569204.png") + photo = models.URLField( + max_length=200, + help_text="Introduce la url de tu foto", + blank=True, + default="http://cdn.onlinewebfonts.com/svg/img_569204.png", + ) def save(self, *args, **kwargs): val = EmailValidator() diff --git a/participant/tests.py b/participant/tests.py index 2dadeb0..ce8eb2e 100644 --- a/participant/tests.py +++ b/participant/tests.py @@ -5,139 +5,286 @@ from selenium.webdriver.common.by import By from selenium import webdriver + class ParticipantTestCase(TestCase): def setUp(self): - Participant.objects.create(username = "Amekit", first_name = "Tomas", last_name = "Camero", email = "tcamerob@gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - Participant.objects.create(username = "UserUpdate", first_name = "UserUpdate", last_name = "UserUpdate", email ="UserUpdate@gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="Amekit", + first_name="Tomas", + last_name="Camero", + email="tcamerob@gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + Participant.objects.create( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdate@gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create(self): - participant = Participant.objects.get(username = "Amekit") + participant = Participant.objects.get(username="Amekit") self.assertIsNotNone(participant) - self.assertEqual(participant.username,"Amekit") - self.assertEqual(participant.first_name,"Tomas") - self.assertEqual(participant.last_name,"Camero") - self.assertEqual(participant.email,"tcamerob@gmail.com") - self.assertEqual(participant.photo,"https://cdn-icons-png.flaticon.com/512/149/149071.png") - + self.assertEqual(participant.username, "Amekit") + self.assertEqual(participant.first_name, "Tomas") + self.assertEqual(participant.last_name, "Camero") + self.assertEqual(participant.email, "tcamerob@gmail.com") + self.assertEqual( + participant.photo, "https://cdn-icons-png.flaticon.com/512/149/149071.png" + ) + def test_participant_delete(self): participant = Participant.objects.get(username="Amekit") participant.delete() - self.assertEqual(1,Participant.objects.count()) - + self.assertEqual(1, Participant.objects.count()) + def test_participant_update(self): participant = Participant.objects.get(username="Amekit") - participant.username="Prueba" - participant.first_name="Prueba" - participant.last_name="Prueba" - participant.email="Prueba@gmail.com" - participant.photo="https://www.google.es" + participant.username = "Prueba" + participant.first_name = "Prueba" + participant.last_name = "Prueba" + participant.email = "Prueba@gmail.com" + participant.photo = "https://www.google.es" participant.save() participant_nuevo = Participant.objects.get(username="Prueba") self.assertIsNotNone(participant_nuevo) - self.assertEqual(participant_nuevo.username,"Prueba") - self.assertEqual(participant_nuevo.first_name,"Prueba") - self.assertEqual(participant_nuevo.last_name,"Prueba") - self.assertEqual(participant_nuevo.email,"Prueba@gmail.com") - self.assertEqual(participant_nuevo.photo,"https://www.google.es") - - #Create Tests - + self.assertEqual(participant_nuevo.username, "Prueba") + self.assertEqual(participant_nuevo.first_name, "Prueba") + self.assertEqual(participant_nuevo.last_name, "Prueba") + self.assertEqual(participant_nuevo.email, "Prueba@gmail.com") + self.assertEqual(participant_nuevo.photo, "https://www.google.es") + + # Create Tests + def test_participant_create_email_duplicated(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User3", first_name = "Tomas", last_name = "Camero", email = "tcamerob@gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="User3", + first_name="Tomas", + last_name="Camero", + email="tcamerob@gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_username_duplicated(self): with self.assertRaises(Exception): - Participant.objects.create(username = "Amekit",first_name = "User2", last_name = "User2", email = "User2@gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="Amekit", + first_name="User2", + last_name="User2", + email="User2@gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_photo_incorrect(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User4", first_name = "User4", last_name = "User4", email = "User4@gmail.com", photo = "urlincorrect") - + Participant.objects.create( + username="User4", + first_name="User4", + last_name="User4", + email="User4@gmail.com", + photo="urlincorrect", + ) + def test_participant_create_email_incorrect(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User5", first_name = "User5", last_name = "User5", email = "User5gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="User5", + first_name="User5", + last_name="User5", + email="User5gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_username_blank(self): with self.assertRaises(Exception): - Participant.objects.create(first_name = "User6", last_name = "User6", email = "User6gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + first_name="User6", + last_name="User6", + email="User6gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_first_name_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User7", last_name = "User7", email = "User7gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="User7", + last_name="User7", + email="User7gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_sur_name_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User8", first_name="User8", last_name = "User8", email = "User8gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="User8", + first_name="User8", + last_name="User8", + email="User8gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_email_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User9", first_name="User9", last_name = "User9", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") + Participant.objects.create( + username="User9", + first_name="User9", + last_name="User9", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) def test_participant_create_first_name_incorrect_lenght(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User10", first_name = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",last_name = "User10", email = "User10gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="User10", + first_name="UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", + last_name="User10", + email="User10gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_last_name_incorrect_lenght(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User11", first_name = "User11",last_name = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", email = "User11gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="User11", + first_name="User11", + last_name="UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", + email="User11gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_create_photo_incorrect_lenght(self): with self.assertRaises(Exception): - Participant.objects.create(username = "User12", first_name = "User12",last_name = "User12", email = "User12gmail.com", photo = "https://UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUcdn-icons-png.flaticon.com/512/149/149071.png") - - #Update Tests - + Participant.objects.create( + username="User12", + first_name="User12", + last_name="User12", + email="User12gmail.com", + photo="https://UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUcdn-icons-png.flaticon.com/512/149/149071.png", + ) + + # Update Tests + def test_participant_update_email_duplicated(self): with self.assertRaises(Exception): - Participant.objects.update(username = "UserUpdate", first_name = "UserUpdate", last_name = "UserUpdate", email ="tcamerob@gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.update( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="tcamerob@gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_username_duplicated(self): with self.assertRaises(Exception): - Participant.objects.update(username = "Amekit", first_name = "UserUpdate", last_name = "UserUpdate", email ="UserUpdate@gmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.update( + username="Amekit", + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdate@gmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_photo_incorrect(self): with self.assertRaises(Exception): - Participant.objects.update(username = "UserUpdate", first_name = "UserUpdate", last_name = "UserUpdate", email ="UserUpdate@gmail.com", photo = "noturl") - + Participant.objects.update( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdate@gmail.com", + photo="noturl", + ) + def test_participant_update_email_incorrect(self): with self.assertRaises(Exception): - Participant.objects.update(username = "UserUpdate", first_name = "UserUpdate", last_name = "UserUpdate", email ="UserUpdate", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.update( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdate", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_username_blank(self): with self.assertRaises(Exception): - Participant.objects.create(first_name = "UserUpdate", last_name = "UserUpdate", email = "UserUpdategmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdategmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_first_name_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", last_name = "UserUpdate", email = "UserUpdategmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="UserUpdate", + last_name="UserUpdate", + email="UserUpdategmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_sur_name_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", first_name="UserUpdate", last_name = "UserUpdate", email = "UserUpdategmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdategmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_email_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", first_name="UserUpdate", last_name = "UserUpdate", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_photo_blank(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", first_name="UserUpdate", last_name = "UserUpdate", email = "User10@gmail.com") - + Participant.objects.create( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="User10@gmail.com", + ) + def test_participant_update_first_name_incorrect_lenght(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", first_name = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",last_name = "UserUpdate", email = "UserUpdategmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="UserUpdate", + first_name="UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", + last_name="UserUpdate", + email="UserUpdategmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_last_name_incorrect_lenght(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", first_name = "UserUpdate",last_name = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", email = "UserUpdategmail.com", photo = "https://cdn-icons-png.flaticon.com/512/149/149071.png") - + Participant.objects.create( + username="UserUpdate", + first_name="UserUpdate", + last_name="UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", + email="UserUpdategmail.com", + photo="https://cdn-icons-png.flaticon.com/512/149/149071.png", + ) + def test_participant_update_photo_incorrect_lenght(self): with self.assertRaises(Exception): - Participant.objects.create(username = "UserUpdate", first_name = "UserUpdate",last_name = "UserUpdate", email = "UserUpdategmail.com", photo = "https://UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUcdn-icons-png.flaticon.com/512/149/149071.png") + Participant.objects.create( + username="UserUpdate", + first_name="UserUpdate", + last_name="UserUpdate", + email="UserUpdategmail.com", + photo="https://UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUcdn-icons-png.flaticon.com/512/149/149071.png", + ) + class ProfileViewTest(StaticLiveServerTestCase): - fixtures = ['fixtures/initial.json'] + fixtures = ["fixtures/initial.json"] @classmethod def setUpClass(cls): @@ -154,27 +301,41 @@ def tearDownClass(cls): def test_title(self): PORT = self.live_server_url.split(":")[2] - titles = ["Innoweb - ezegonmac", "Innoweb - tomcambor","Innoweb - juasaljur","Innoweb - ismperort","Innoweb - migromarj"] + titles = [ + "Innoweb - ezegonmac", + "Innoweb - tomcambor", + "Innoweb - juasaljur", + "Innoweb - ismperort", + "Innoweb - migromarj", + ] self.browser.get(self.live_server_url) - for i in range(2,7): - self.browser.get("http://localhost:" + PORT + "/participante/"+str(i)) - assert titles[i-2] == self.browser.title + for i in range(2, 7): + self.browser.get("http://localhost:" + PORT + "/participante/" + str(i)) + assert titles[i - 2] == self.browser.title def test_participant_name(self): PORT = self.live_server_url.split(":")[2] - names = ["Ezequiel González", "Tomás Camero","Juan Salado","Ismael Pérez","Miguel Romero"] + names = [ + "Ezequiel González", + "Tomás Camero", + "Juan Salado", + "Ismael Pérez", + "Miguel Romero", + ] self.browser.get(self.live_server_url) - for i in range(2,7): - - self.browser.get("http://localhost:" + PORT + "/participante/"+str(i)) - participant_name = self.browser.find_element(By.CSS_SELECTOR, 'h3.user-name').text + for i in range(2, 7): - assert names[i-2] == participant_name + self.browser.get("http://localhost:" + PORT + "/participante/" + str(i)) + participant_name = self.browser.find_element( + By.CSS_SELECTOR, "h3.user-name" + ).text + + assert names[i - 2] == participant_name def test_participant_total_points(self): @@ -183,12 +344,14 @@ def test_participant_total_points(self): self.browser.get(self.live_server_url) - for i in range(2,7): - - self.browser.get("http://localhost:" + PORT + "/participante/"+str(i)) - participant_total_points = self.browser.find_element(By.CSS_SELECTOR, 'h1.user-points-number').text - - assert total_points[i-2] == participant_total_points + for i in range(2, 7): + + self.browser.get("http://localhost:" + PORT + "/participante/" + str(i)) + participant_total_points = self.browser.find_element( + By.CSS_SELECTOR, "h1.user-points-number" + ).text + + assert total_points[i - 2] == participant_total_points def test_participant_total_events(self): @@ -197,56 +360,76 @@ def test_participant_total_events(self): self.browser.get(self.live_server_url) - for i in range(2,7): - - self.browser.get("http://localhost:" + PORT + "/participante/"+str(i)) - participant_total_events = self.browser.find_element(By.CSS_SELECTOR, 'h2.user-events-number').text + for i in range(2, 7): - assert total_events[i-2] == participant_total_events + self.browser.get("http://localhost:" + PORT + "/participante/" + str(i)) + participant_total_events = self.browser.find_element( + By.CSS_SELECTOR, "h2.user-events-number" + ).text + + assert total_events[i - 2] == participant_total_events def test_participant_events(self): PORT = self.live_server_url.split(":")[2] - events_ezegonmac = [{"name": "Torneo Futbolín 2022","position": "#1","points": "96"}, - {"name": "Torneo Ajedrez 2022","position": "#1","points": "90"}, - {"name": "Torneo Brawhalla 2022","position": "#2","points": "70"}, - {"name": "Torneo de Cartas 2022","position": "#2","points": "68"}, - {"name": "Escape Room 2022","position": "#3","points": "32"}] - - events_tomcambor = [{"name": "Torneo Brawhalla 2022","position": "#1","points": "100"}, - {"name": "Torneo Futbolín 2022","position": "#2","points": "94"}, - {"name": "Torneo de Bolos 2022","position": "#1","points": "93"}, - {"name": "Torneo Ajedrez 2022","position": "#3","points": "65"}] - - events_juasaljur = [{"name": "Gymkhana Innosoft 2022","position": "#1","points": "97"}, - {"name": "Escape Room 2022","position": "#1","points": "95"}, - {"name": "Torneo Futbolín 2022","position": "#3","points": "73"}] - - events_ismperort = [{"name": "Torneo de Cartas 2022","position": "#1","points": "97"}, - {"name": "Gymkhana Innosoft 2022","position": "#2","points": "88"}, - {"name": "Torneo de Bolos 2022","position": "#2","points": "78"}, - {"name": "Torneo Ajedrez 2022","position": "#2","points": "67"}, - {"name": "Escape Room 2022","position": "#2","points": "46"},] - - events_migromarj = [{"name": "Torneo Brawhalla 2022","position": "#3","points": "64"}, - {"name": "Gymkhana Innosoft 2022","position": "#3","points": "50"}, - {"name": "Torneo de Cartas 2022","position": "#3","points": "47"}, - {"name": "Torneo de Bolos 2022","position": "#3","points": "20"}] - - all_participants_events = [events_ezegonmac, events_tomcambor, events_juasaljur, events_ismperort, events_migromarj] + events_ezegonmac = [ + {"name": "Torneo Futbolín 2022", "position": "#1", "points": "96"}, + {"name": "Torneo Ajedrez 2022", "position": "#1", "points": "90"}, + {"name": "Torneo Brawhalla 2022", "position": "#2", "points": "70"}, + {"name": "Torneo de Cartas 2022", "position": "#2", "points": "68"}, + {"name": "Escape Room 2022", "position": "#3", "points": "32"}, + ] + + events_tomcambor = [ + {"name": "Torneo Brawhalla 2022", "position": "#1", "points": "100"}, + {"name": "Torneo Futbolín 2022", "position": "#2", "points": "94"}, + {"name": "Torneo de Bolos 2022", "position": "#1", "points": "93"}, + {"name": "Torneo Ajedrez 2022", "position": "#3", "points": "65"}, + ] + + events_juasaljur = [ + {"name": "Gymkhana Innosoft 2022", "position": "#1", "points": "97"}, + {"name": "Escape Room 2022", "position": "#1", "points": "95"}, + {"name": "Torneo Futbolín 2022", "position": "#3", "points": "73"}, + ] + + events_ismperort = [ + {"name": "Torneo de Cartas 2022", "position": "#1", "points": "97"}, + {"name": "Gymkhana Innosoft 2022", "position": "#2", "points": "88"}, + {"name": "Torneo de Bolos 2022", "position": "#2", "points": "78"}, + {"name": "Torneo Ajedrez 2022", "position": "#2", "points": "67"}, + {"name": "Escape Room 2022", "position": "#2", "points": "46"}, + ] + + events_migromarj = [ + {"name": "Torneo Brawhalla 2022", "position": "#3", "points": "64"}, + {"name": "Gymkhana Innosoft 2022", "position": "#3", "points": "50"}, + {"name": "Torneo de Cartas 2022", "position": "#3", "points": "47"}, + {"name": "Torneo de Bolos 2022", "position": "#3", "points": "20"}, + ] + + all_participants_events = [ + events_ezegonmac, + events_tomcambor, + events_juasaljur, + events_ismperort, + events_migromarj, + ] self.browser.get(self.live_server_url) - for i in range(2,7): - - participant_events = all_participants_events[i-2] + for i in range(2, 7): + + participant_events = all_participants_events[i - 2] - self.browser.get("http://localhost:" + PORT + "/participante/"+str(i)) - participant_events_table = self.browser.find_elements(By.CSS_SELECTOR, 'tr') + self.browser.get("http://localhost:" + PORT + "/participante/" + str(i)) + participant_events_table = self.browser.find_elements(By.CSS_SELECTOR, "tr") for event in range(1, len(participant_events_table)): - event_info = participant_events_table[event].find_elements(By.CSS_SELECTOR, 'td') - assert participant_events[event-1]["name"] == event_info[0].text - assert participant_events[event-1]["position"] == event_info[1].text - assert participant_events[event-1]["points"] == event_info[2].text \ No newline at end of file + event_info = participant_events_table[event].find_elements( + By.CSS_SELECTOR, "td" + ) + assert participant_events[event - 1]["name"] == event_info[0].text + assert participant_events[event - 1]["position"] == event_info[1].text + assert participant_events[event - 1]["points"] == event_info[2].text diff --git a/participant/urls.py b/participant/urls.py index ff97eb8..d3d697c 100644 --- a/participant/urls.py +++ b/participant/urls.py @@ -2,5 +2,5 @@ from . import views urlpatterns = [ - path('', views.profile, name='profile'), -] \ No newline at end of file + path("", views.profile, name="profile"), +] diff --git a/participant/views.py b/participant/views.py index 663a06a..edc820f 100644 --- a/participant/views.py +++ b/participant/views.py @@ -7,51 +7,67 @@ def get_future_events(request): - user = request.user - future_events = Score.objects.filter(participant=user).filter(value=None).order_by('event__date') + user = request.user + future_events = ( + Score.objects.filter(participant=user) + .filter(value=None) + .order_by("event__date") + ) + + return [aux.event for aux in future_events] - return [aux.event for aux in future_events] - - def profile(request, id): + def get_position(participant, event): + scores = ( + Score.objects.filter(event=event).order_by("-value").exclude(value=None) + ) + position = 1 + for score in scores: + if score.participant == participant: + return position + position += 1 + + user = None + my_profile = False + if request.user.is_authenticated: + user = request.user + if user.id == id: + my_profile = True + + p = Participant.objects.get(id=id) + events_aux = ( + Score.objects.filter(participant=p).order_by("-value").exclude(value=None) + ) + + events = [] + total_points = 0 + n_events = 0 + + for e in events_aux: + event = { + "id": e.event.id, + "name": e.event.name, + "points": e.value, + "position": get_position(p, e.event), + } + events.append(event) + total_points += e.value + n_events += 1 + + future_events = [] + if my_profile: + future_events = get_future_events(request) - def get_position(participant, event): - scores = Score.objects.filter(event=event).order_by('-value').exclude(value=None) - position = 1 - for score in scores: - if score.participant == participant: - return position - position += 1 - - user = None - my_profile = False - if request.user.is_authenticated: - user = request.user - if user.id == id: - my_profile = True - - p = Participant.objects.get(id=id) - events_aux = Score.objects.filter(participant=p).order_by('-value').exclude(value=None) - - events = [] - total_points = 0 - n_events = 0 - - for e in events_aux: - event = { - "id": e.event.id, - 'name': e.event.name, - 'points': e.value, - 'position': get_position(p, e.event) - } - events.append(event) - total_points += e.value - n_events += 1 - - future_events = [] - if my_profile: - future_events = get_future_events(request) - - - return render(request, 'base_PROFILE.html', {"participant":p ,"u_events":events, "total_points":total_points, "n_events":n_events, "my_profile":my_profile, "future_events":future_events}) \ No newline at end of file + return render( + request, + "base_PROFILE.html", + { + "participant": p, + "u_events": events, + "total_points": total_points, + "n_events": n_events, + "my_profile": my_profile, + "future_events": future_events, + }, + ) diff --git a/score/admin.py b/score/admin.py index cf7c6d0..d3b65bd 100644 --- a/score/admin.py +++ b/score/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from .models import Score + # Register your models here. -admin.site.register(Score) \ No newline at end of file +admin.site.register(Score) diff --git a/score/apps.py b/score/apps.py index 9daab99..f5298f3 100644 --- a/score/apps.py +++ b/score/apps.py @@ -2,5 +2,5 @@ class ScoreConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'score' + default_auto_field = "django.db.models.BigAutoField" + name = "score" diff --git a/score/models.py b/score/models.py index a91c87c..19e4eac 100644 --- a/score/models.py +++ b/score/models.py @@ -10,9 +10,9 @@ class Score(models.Model): event = models.ForeignKey(e.Event, on_delete=models.CASCADE) value = models.PositiveIntegerField(default=0, null=True, blank=True) - #unique constraint for participant and event + # unique constraint for participant and event class Meta: - unique_together = (('participant', 'event'),) + unique_together = (("participant", "event"),) def __str__(self): return str(self.participant) + " - " + str(self.event) + " - " + str(self.value) diff --git a/score/templates/score/score_view.html b/score/templates/score/score_view.html index 088ae8a..05d2663 100644 --- a/score/templates/score/score_view.html +++ b/score/templates/score/score_view.html @@ -5,7 +5,7 @@
{% block content %} -

Mostrando puntuación

+

Mostrando puntuación

Participante: {{e.participant.name}}

Evento: {{e.event.name}}

Puntuación: {{e.value}}

diff --git a/score/tests.py b/score/tests.py index 7688713..51642de 100644 --- a/score/tests.py +++ b/score/tests.py @@ -4,29 +4,39 @@ from participant.models import Participant from score.models import Score -class ScoreTestCase(TestCase): +class ScoreTestCase(TestCase): def setUp(self): self.e1 = Event.objects.create( - name="Evento 1", - description="Esta es la descripción del evento", - date=datetime.datetime.now(), - place="Etsii", - photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", - status="Abierto" - ) - self.p1 = Participant.objects.create(username = "juanperez", first_name="Juan", last_name="Perez", email="juanperez@gmail.com") + name="Evento 1", + description="Esta es la descripción del evento", + date=datetime.datetime.now(), + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) + self.p1 = Participant.objects.create( + username="juanperez", + first_name="Juan", + last_name="Perez", + email="juanperez@gmail.com", + ) self.score = Score.objects.create(participant=self.p1, event=self.e1, value=100) self.e2 = Event.objects.create( - name="Evento 2", - description="Esta es la descripción del evento", - date=datetime.datetime.now(), - place="Etsii", - photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", - status="Abierto" - ) - self.p2 = Participant.objects.create(username = "juanperez2", first_name="Juan2", last_name="Perez2", email="juanperez2@gmail.com") + name="Evento 2", + description="Esta es la descripción del evento", + date=datetime.datetime.now(), + place="Etsii", + photo="https://img.freepik.com/foto-gratis/campo-cesped-nubes_1112-621.jpg?w=2000", + status="Abierto", + ) + self.p2 = Participant.objects.create( + username="juanperez2", + first_name="Juan2", + last_name="Perez2", + email="juanperez2@gmail.com", + ) def tearDown(self): super().tearDown() @@ -85,7 +95,9 @@ def test_score_create_value_blank(self): def test_score_create_value_negative(self): with self.assertRaises(Exception): - score2 = Score.objects.create(participant=self.p2, event=self.e2, value=-100) + score2 = Score.objects.create( + participant=self.p2, event=self.e2, value=-100 + ) score2.save() def test_score_create_unique_event_participant(self): diff --git a/score/urls.py b/score/urls.py index b9906ad..ad5a79c 100644 --- a/score/urls.py +++ b/score/urls.py @@ -4,6 +4,5 @@ urlpatterns = [ - path('/', views.score_view, name='score'), - -] \ No newline at end of file + path("/", views.score_view, name="score"), +] diff --git a/score/views.py b/score/views.py index 7d0972f..5cbd9d7 100644 --- a/score/views.py +++ b/score/views.py @@ -8,10 +8,11 @@ p = importlib.import_module("participant.models") e = importlib.import_module("event.models") + def score_view(request, participant_id, event_id): - participant = p.Participant.objects.get(id=participant_id) - event = e.Event.objects.get(id=event_id) + participant = p.Participant.objects.get(id=participant_id) + event = e.Event.objects.get(id=event_id) - score = Score.objects.get(participant=participant, event=event) - return render(request, 'score/score_view.html', {"e":score}) \ No newline at end of file + score = Score.objects.get(participant=participant, event=event) + return render(request, "score/score_view.html", {"e": score}) diff --git a/static/styles/base.css b/static/styles/base.css index d09079c..d829ef0 100644 --- a/static/styles/base.css +++ b/static/styles/base.css @@ -42,7 +42,7 @@ height: 40px; } -/* MESSAGES STYLES FROM BOOTSTRAP <-- I added these lines because if I added the whole bootstrap library, +/* MESSAGES STYLES FROM BOOTSTRAP <-- I added these lines because if I added the whole bootstrap library, the whole style of the page would change to something completely different. Besides, this is the only thing we really need so we can show the messages right.*/ diff --git a/static/styles/event.css b/static/styles/event.css index d84ce16..7ccd7dd 100644 --- a/static/styles/event.css +++ b/static/styles/event.css @@ -94,7 +94,7 @@ padding: 100px 50px; } -.event-header { +.event-header { display: flex; justify-content: space-around; flex-direction: row; @@ -161,7 +161,7 @@ color: #000000; } - + .download-certificate { text-decoration: none; padding-right: 5px; @@ -172,7 +172,7 @@ } @media(max-width: 720px) { - + .event-details { padding: 100px 20px; } diff --git a/static/styles/home.css b/static/styles/home.css index c15a30e..1a98ba1 100644 --- a/static/styles/home.css +++ b/static/styles/home.css @@ -44,7 +44,7 @@ } @media only screen and (max-width: 1200px) { - + .decoration-left { scale: 0.8; left: -5%; diff --git a/static/styles/login.css b/static/styles/login.css index d98ac74..9977686 100644 --- a/static/styles/login.css +++ b/static/styles/login.css @@ -31,12 +31,12 @@ font-size: 1rem; color: var(--clr-dark-blue); margin-bottom: 5px; - + } h4{ text-align: center; - margin-bottom: 20px; + margin-bottom: 20px; } a{ @@ -102,7 +102,7 @@ label{ position: fixed; top: 45%; left: 50%; - + } html{ @@ -110,8 +110,8 @@ label{ background-repeat: no-repeat; background-position: center; background-attachment: fixed; - - - + + + } } \ No newline at end of file diff --git a/static/styles/main.css b/static/styles/main.css index da56b36..9116147 100644 --- a/static/styles/main.css +++ b/static/styles/main.css @@ -3,14 +3,14 @@ /* COLOR PALETTE */ --clr-white: hsl(0, 0%, 97%); --clr-black: hsl(0, 0%, 5%); - + /* Primary */ --clr-light-blue: hsl(205, 51%, 66%); --clr-yellow: hsl(44, 100%, 46%); --clr-dark-blue: hsl(225, 41%, 21%); --clr-dark-grey: hsl(0, 0%, 27%); --clr-light-grey: hsl(0, 0%, 84%); - + /* Secondary */ --clr-magenta: hsl(295, 85%, 57%); --clr-red: hsl(0, 100%, 46%); @@ -140,7 +140,7 @@ select { html:focus-within { scroll-behavior: auto; } - + *, *::before, *::after { diff --git a/static/styles/navbar.css b/static/styles/navbar.css index 3ab61a8..da65619 100644 --- a/static/styles/navbar.css +++ b/static/styles/navbar.css @@ -161,7 +161,7 @@ .navbar-toggle { display: flex; } - + .navbar-rightsection { display: none; } @@ -170,7 +170,7 @@ height: 3.5rem; font-size: 0.8rem; } - + } @media only screen and (max-width: 450px) { diff --git a/static/styles/podium.css b/static/styles/podium.css index ccf32ce..27b988f 100644 --- a/static/styles/podium.css +++ b/static/styles/podium.css @@ -72,7 +72,7 @@ body { .podium .second { height: 7rem; } - + .podium .third { height: 5rem; } diff --git a/static/styles/register.css b/static/styles/register.css index e340075..7672ae3 100644 --- a/static/styles/register.css +++ b/static/styles/register.css @@ -2,7 +2,7 @@ height: 100%; background-image: url(https://theuniqueacademy.co.in/assets/images/test.png); background-repeat: no-repeat; - + background-attachment: fixed; background-position: left; background-size: cover; @@ -38,7 +38,7 @@ font-size: 1rem; color: var(--clr-dark-blue); margin-bottom: 5px; - + } li{ @@ -49,7 +49,7 @@ li{ h4{ text-align: center; - margin-bottom: 20px; + margin-bottom: 20px; } a{ @@ -119,7 +119,7 @@ label{ .container-register{ width: 70%; - + } html{ @@ -127,8 +127,8 @@ label{ background-repeat: no-repeat; background-position: center; background-attachment: fixed; - - - + + + } } \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 8080117..75d9234 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,10 +2,10 @@ {% block title %}My amazing site{% endblock %} - + - + {% load static %} diff --git a/templates/base_EVENT.html b/templates/base_EVENT.html index 9c085e6..32d0099 100644 --- a/templates/base_EVENT.html +++ b/templates/base_EVENT.html @@ -5,7 +5,7 @@ {% load static %} -{% endblock %} +{% endblock %} {% block content %}
@@ -15,11 +15,11 @@

{{ e.name}}

- Event image + Event image
-
+
{% include "components/podium.html"%}
@@ -46,7 +46,7 @@

- + {% endblock %} diff --git a/templates/base_HOME.html b/templates/base_HOME.html index 66f371a..06b14bb 100644 --- a/templates/base_HOME.html +++ b/templates/base_HOME.html @@ -10,10 +10,10 @@ {% block content %}
- + - +
{% include "components/podium.html" %}
diff --git a/templates/base_PROFILE.html b/templates/base_PROFILE.html index a4e6bda..228a0a5 100644 --- a/templates/base_PROFILE.html +++ b/templates/base_PROFILE.html @@ -26,12 +26,12 @@
{% include "components/user_past_events.html" with events=u_events p=participant %}
- +
{% if my_profile and future_events|length > 0 %} {% include "components/user_next_events.html" with events=future_events p=participant %} - + {% endif %}
diff --git a/templates/components/event.html b/templates/components/event.html index 3f2809d..8044115 100644 --- a/templates/components/event.html +++ b/templates/components/event.html @@ -3,6 +3,6 @@

{{ event.name}}

- +
- \ No newline at end of file + \ No newline at end of file diff --git a/templates/components/navbar.html b/templates/components/navbar.html index f5f77d9..d013e9a 100644 --- a/templates/components/navbar.html +++ b/templates/components/navbar.html @@ -17,13 +17,13 @@

INNOSOFT eventos

{% comment %} ADD SAME LINKS IN BOTTOM SECTION FOR MOBILE SUPPORT {% endcomment %} {% comment %} Enlace Ejemplo {% endcomment %} {% comment %} Enlace Ejemplo {% endcomment %} - + {% if user.is_authenticated %} {{ user.username }} - {% else %} + {% else %} Acceder {% endif %}
@@ -36,14 +36,14 @@

INNOSOFT eventos

- +

diff --git a/templates/components/podium.html b/templates/components/podium.html index fba80fe..6837036 100644 --- a/templates/components/podium.html +++ b/templates/components/podium.html @@ -7,10 +7,10 @@
{% url 'profile' second.id as second_url %} {% if second_url %} - + - {% else %} - + {% else %} + {% endif %}

{{ second.username }}

@@ -21,7 +21,7 @@
{% url 'profile' first.id as first_url %} {% if first_url %} - + {% else %} diff --git a/templates/registration/login.html b/templates/registration/login.html index 48457b7..c6d3433 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -18,11 +18,11 @@ {% endif %}