Skip to content

Commit

Permalink
nuevos test validar participantes
Browse files Browse the repository at this point in the history
  • Loading branch information
m4droid committed Aug 18, 2016
1 parent ca9887e commit db52446
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 5 deletions.
11 changes: 11 additions & 0 deletions actas/fixtures/test_actas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"model": "actas.acta",
"pk": 1,
"fields": {
"fecha": "2016-07-18T00:01:00.000Z",
"comuna": 13101,
"participantes": [1]
}
}
]
12 changes: 12 additions & 0 deletions actas/fixtures/test_actasrespuestasitems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"model": "actas.actarespuestaitem",
"pk": 1,
"fields": {
"acta": 1,
"item": 1,
"categoria": 1,
"fundamento": "D"
}
}
]
11 changes: 11 additions & 0 deletions actas/fixtures/test_grupoitems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"model": "actas.grupoitems",
"pk": 1,
"fields": {
"nombre": "A",
"descripcion": "B",
"orden": 1
}
}
]
11 changes: 11 additions & 0 deletions actas/fixtures/test_items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"model": "actas.item",
"pk": 1,
"fields": {
"grupo_items": 1,
"nombre": "C",
"orden": 1
}
}
]
18 changes: 18 additions & 0 deletions actas/fixtures/test_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"model": "auth.user",
"pk": 1,
"fields": {
"last_login": null,
"is_superuser": true,
"username": "1-9",
"first_name": "Test",
"last_name": "User",
"is_staff": false,
"is_active": false,
"date_joined": "2016-07-18T00:00:00.000Z",
"groups": [],
"user_permissions": []
}
}
]
8 changes: 4 additions & 4 deletions actas/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ def validar_participantes(acta):
# Ruts diferentes
ruts = set(ruts_participantes)
if not (config['participantes_min'] <= len(ruts) <= config['participantes_max']):
return ['Existen RUTs repetidos']
return ['Existen RUTs repetidos.']

# Nombres diferentes
nombres = set(
(p['nombre'].lower(), p['apellido'].lower(), ) for p in participantes
)
if not (config['participantes_min'] <= len(nombres) <= config['participantes_max']):
return ['Existen nombres repetidos']
return ['Existen nombres repetidos.']

# Verificar que los participantes no hayan enviado una acta antes
participantes_en_db = User.objects.filter(username__in=list(ruts))
# Verificar que los participantes no hayan enviado un acta antes
participantes_en_db = User.objects.prefetch_related('participantes').filter(username__in=list(ruts))

if len(participantes_en_db) > 0:
for participante in participantes_en_db:
Expand Down
60 changes: 59 additions & 1 deletion actas/tests/test_libs_validar_participantes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.test.testcases import TransactionTestCase
from django.test.utils import override_settings

from ..libs import validar_participantes
from ..libs import validar_participantes, guardar_acta
# from ..models import


class LibsValidarParticipantesTestCase(TestCase):
Expand Down Expand Up @@ -55,3 +57,59 @@ def test_participante_invalido(self):
'participantes': participantes
})
self.assertEquals(expected, result)

@override_settings(DISCUSION_ABIERTA={'PARTICIPANTES_MIN': 2, 'PARTICIPANTES_MAX': 2})
def test_participantes_ruts_repetidos(self):
expected = ['Existen RUTs repetidos.']
result = validar_participantes({
'participantes': [
{'rut': '1-9', 'nombre': 'Aa', 'apellido': 'Bb'},
{'rut': '1-9', 'nombre': 'Aa', 'apellido': 'Bb'},
]
})
self.assertEquals(expected, result)

@override_settings(DISCUSION_ABIERTA={'PARTICIPANTES_MIN': 2, 'PARTICIPANTES_MAX': 2})
def test_participantes_nombres_repetidos(self):
expected = ['Existen nombres repetidos.']
result = validar_participantes({
'participantes': [
{'rut': '1-9', 'nombre': 'Aa', 'apellido': 'Bb'},
{'rut': '2-7', 'nombre': 'Aa', 'apellido': 'Bb'},
]
})
self.assertEquals(expected, result)


class LibsValidarParticipantesExistentesTestCase(TransactionTestCase):

fixtures = [
'regiones.json',
'provincias.json',
'comunas.json',
'test_users.json',
'test_grupoitems.json',
'test_items.json',
'test_actas.json',
'test_actasrespuestasitems.json',
]

@override_settings(DISCUSION_ABIERTA={'PARTICIPANTES_MIN': 1, 'PARTICIPANTES_MAX': 1})
def test_participante_existente(self):
expected = ['El RUT 1-9 ya participó del proceso.']
result = validar_participantes({
'participantes': [
{'rut': '1-9', 'nombre': 'Aa', 'apellido': 'Bb'},
]
})
self.assertEquals(expected, result)

@override_settings(DISCUSION_ABIERTA={'PARTICIPANTES_MIN': 1, 'PARTICIPANTES_MAX': 1})
def test_participante_nuevo(self):
expected = []
result = validar_participantes({
'participantes': [
{'rut': '2-7', 'nombre': 'Aa', 'apellido': 'Bb'},
]
})
self.assertEquals(expected, result)

0 comments on commit db52446

Please sign in to comment.