Skip to content

Commit

Permalink
Merge pull request EGCETSII#13 from Full-Tortuga/master
Browse files Browse the repository at this point in the history
full-tortuga:update-001
  • Loading branch information
alejandropiuryp authored Dec 10, 2021
2 parents 8126f7e + a3b1a39 commit 7f626a2
Show file tree
Hide file tree
Showing 41 changed files with 38,999 additions and 496 deletions.
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![Build Status](https://travis-ci.com/wadobo/decide.svg?branch=master)](https://travis-ci.com/wadobo/decide) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Coverage)

Plataforma voto electrónico educativa
=====================================

El objetivo de este proyecto es implementar una plataforma de voto
electrónico seguro, que cumpla una serie de garantías básicas, como la
Expand Down Expand Up @@ -56,27 +55,53 @@ Para configurar el proyecto, podremos crearnos un fichero local_settings.py basa
local_settings.example.py, donde podremos configurar la ruta de nuestras apps o escoger que módulos
ejecutar.

Una vez hecho esto, será necesario instalar las dependencias del proyecto, las cuales están en el
Se hará uso de la base de datos MongoDB, para el correcto funcionamiento de la aplicación será necesaria la instalación de dicha base de datos siguiendo las instrucciones de la documentación oficial según el SO que estemos utilizando:

Windows:
- https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

Ubuntu:
- https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

WSL:
- https://docs.microsoft.com/es-es/windows/wsl/tutorials/wsl-database#install-mongodb

MacOs:
- https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

Una vez hecho esto, y corriendo la base de datos, será necesario instalar las dependencias del proyecto, las cuales están en el
fichero requirements.txt:

pip install -r requirements.txt

Tras esto tendremos que crearnos nuestra base de datos con postgres:
En caso de fallo al instalar las dependencias, es necesario instalas el paquete wheel y volver al comando anterior:
pip install wheel

sudo su - postgres
psql -c "create user decide with password 'decide'"
psql -c "create database decide owner decide"
Entramos en la carpeta del proyecto (cd decide) y realizamos las migraciones correspondientes para preparar la base de datos:

Entramos en la carpeta del proyecto (cd decide) y realizamos la primera migración para preparar la
base de datos que utilizaremos:
Además, será necesario instalar las dependencias correspondientes al panel de control desarrollado con
React. Para ello, primero se deberán tener instaldas las siguientes librerías de js con sus correspondientes
versiones: Node=14.15.0, npm=7.8.0.

./manage.py migrate
A continuación, entramos en la carpeta del panel (cd decide_panel) y ejecutamos el siguiente comando:

npm install

Situados en el directorio raíz del proyecto, entramos en la carpeta del proyecto (cd decide) y
realizamos la primera migración para preparar la base de datos que utilizaremos:

./manage.py makemigrations
./mange.py migrate

Por último, ya podremos ejecutar el módulos o módulos seleccionados en la configuración de la
siguiente manera:

./manage.py runserver

También debemos lanzar el panel de control, para ello dentro de la carpeta decide_panel ejecutamos:

npm start

Ejecutar con docker
-------------------

Expand Down
79 changes: 50 additions & 29 deletions decide/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@ def tearDown(self):

def test_login(self):
data = {'username': 'voter1', 'password': '123'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)

token = response.json()
self.assertTrue(token.get('token'))

def test_login_fail(self):
data = {'username': 'voter1', 'password': '321'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 400)

def test_getuser(self):
data = {'username': 'voter1', 'password': '123'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
token = response.json()

response = self.client.post('/authentication/getuser/', token, format='json')
response = self.client.post(
'/authentication/getuser/', token, format='json')
self.assertEqual(response.status_code, 200)

user = response.json()
Expand All @@ -53,78 +57,95 @@ def test_getuser(self):

def test_getuser_invented_token(self):
token = {'token': 'invented'}
response = self.client.post('/authentication/getuser/', token, format='json')
response = self.client.post(
'/authentication/getuser/', token, format='json')
self.assertEqual(response.status_code, 404)

def test_getuser_invalid_token(self):
data = {'username': 'voter1', 'password': '123'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(Token.objects.filter(user__username='voter1').count(), 1)
self.assertEqual(Token.objects.filter(
user__username='voter1').count(), 1)

token = response.json()
self.assertTrue(token.get('token'))

response = self.client.post('/authentication/logout/', token, format='json')
response = self.client.post(
'/authentication/logout/', token, format='json')
self.assertEqual(response.status_code, 200)

response = self.client.post('/authentication/getuser/', token, format='json')
response = self.client.post(
'/authentication/getuser/', token, format='json')
self.assertEqual(response.status_code, 404)

def test_logout(self):
data = {'username': 'voter1', 'password': '123'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(Token.objects.filter(user__username='voter1').count(), 1)
self.assertEqual(Token.objects.filter(
user__username='voter1').count(), 1)

token = response.json()
self.assertTrue(token.get('token'))

response = self.client.post('/authentication/logout/', token, format='json')
response = self.client.post(
'/authentication/logout/', token, format='json')
self.assertEqual(response.status_code, 200)

self.assertEqual(Token.objects.filter(user__username='voter1').count(), 0)
self.assertEqual(Token.objects.filter(
user__username='voter1').count(), 0)

def test_register_bad_permissions(self):
data = {'username': 'voter1', 'password': '123'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
token = response.json()

token.update({'username': 'user1'})
response = self.client.post('/authentication/register/', token, format='json')
response = self.client.post(
'/authentication/register/', token, format='json')
self.assertEqual(response.status_code, 401)

def test_register_bad_request(self):
data = {'username': 'admin', 'password': 'admin'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
token = response.json()

token.update({'username': 'user1'})
response = self.client.post('/authentication/register/', token, format='json')
self.assertEqual(response.status_code, 400)

def test_register_user_already_exist(self):
data = {'username': 'admin', 'password': 'admin'}
response = self.client.post('/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
token = response.json()

token.update(data)
response = self.client.post('/authentication/register/', token, format='json')
response = self.client.post(
'/authentication/register/', token, format='json')
self.assertEqual(response.status_code, 400)

def test_register(self):
data = {'username': 'admin', 'password': 'admin'}
response = self.client.post('/authentication/login/', data, format='json')
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
token = response.json()

token.update({'username': 'user1', 'password': 'pwd1'})
response = self.client.post('/authentication/register/', token, format='json')
response = self.client.post(
'/authentication/register/', token, format='json')
self.assertEqual(response.status_code, 201)
self.assertEqual(
sorted(list(response.json().keys())),
['token', 'user_pk']
)

def test_register_user_already_exist(self):
data = {'username': 'admin', 'password': 'admin'}
response = self.client.post(
'/authentication/login/', data, format='json')
self.assertEqual(response.status_code, 200)
token = response.json()

token.update({'username': 'admin'})
response = self.client.post(
'/authentication/register/', token, format='json')
self.assertEqual(response.status_code, 400)
33 changes: 0 additions & 33 deletions decide/base/migrations/0001_initial.py

This file was deleted.

33 changes: 0 additions & 33 deletions decide/base/migrations/0002_auto_20180921_1056.py

This file was deleted.

34 changes: 0 additions & 34 deletions decide/base/migrations/0003_auto_20180921_1119.py

This file was deleted.

26 changes: 0 additions & 26 deletions decide/census/migrations/0001_initial.py

This file was deleted.

8 changes: 6 additions & 2 deletions decide/census/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from django.db import models
from django.core.exceptions import ValidationError


class Census(models.Model):
voting_id = models.PositiveIntegerField()
voter_id = models.PositiveIntegerField()

class Meta:
unique_together = (('voting_id', 'voter_id'),)
#A new census is valid if the pair is not already in the database
def clean(self):
# Don't allow draft entries to have a pub_date.
if Census.objects.filter(voting_id=self.voting_id, voter_id=self.voter_id).exists():
raise ValidationError('There is already exists this pair', code='Error')
Loading

0 comments on commit 7f626a2

Please sign in to comment.