From db52446b7f2d6c46a5ce236a7ce2886ae8f95ca5 Mon Sep 17 00:00:00 2001 From: Francisco Madrid Date: Thu, 18 Aug 2016 20:33:52 -0300 Subject: [PATCH] nuevos test validar participantes --- actas/fixtures/test_actas.json | 11 ++++ actas/fixtures/test_actasrespuestasitems.json | 12 ++++ actas/fixtures/test_grupoitems.json | 11 ++++ actas/fixtures/test_items.json | 11 ++++ actas/fixtures/test_users.json | 18 ++++++ actas/libs.py | 8 +-- .../tests/test_libs_validar_participantes.py | 60 ++++++++++++++++++- 7 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 actas/fixtures/test_actas.json create mode 100644 actas/fixtures/test_actasrespuestasitems.json create mode 100644 actas/fixtures/test_grupoitems.json create mode 100644 actas/fixtures/test_items.json create mode 100644 actas/fixtures/test_users.json diff --git a/actas/fixtures/test_actas.json b/actas/fixtures/test_actas.json new file mode 100644 index 0000000..55c22ea --- /dev/null +++ b/actas/fixtures/test_actas.json @@ -0,0 +1,11 @@ +[ +{ + "model": "actas.acta", + "pk": 1, + "fields": { + "fecha": "2016-07-18T00:01:00.000Z", + "comuna": 13101, + "participantes": [1] + } +} +] \ No newline at end of file diff --git a/actas/fixtures/test_actasrespuestasitems.json b/actas/fixtures/test_actasrespuestasitems.json new file mode 100644 index 0000000..b396508 --- /dev/null +++ b/actas/fixtures/test_actasrespuestasitems.json @@ -0,0 +1,12 @@ +[ +{ + "model": "actas.actarespuestaitem", + "pk": 1, + "fields": { + "acta": 1, + "item": 1, + "categoria": 1, + "fundamento": "D" + } +} +] \ No newline at end of file diff --git a/actas/fixtures/test_grupoitems.json b/actas/fixtures/test_grupoitems.json new file mode 100644 index 0000000..60ff84b --- /dev/null +++ b/actas/fixtures/test_grupoitems.json @@ -0,0 +1,11 @@ +[ +{ + "model": "actas.grupoitems", + "pk": 1, + "fields": { + "nombre": "A", + "descripcion": "B", + "orden": 1 + } +} +] \ No newline at end of file diff --git a/actas/fixtures/test_items.json b/actas/fixtures/test_items.json new file mode 100644 index 0000000..20966a1 --- /dev/null +++ b/actas/fixtures/test_items.json @@ -0,0 +1,11 @@ +[ +{ + "model": "actas.item", + "pk": 1, + "fields": { + "grupo_items": 1, + "nombre": "C", + "orden": 1 + } +} +] diff --git a/actas/fixtures/test_users.json b/actas/fixtures/test_users.json new file mode 100644 index 0000000..765b1ac --- /dev/null +++ b/actas/fixtures/test_users.json @@ -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": [] + } +} +] \ No newline at end of file diff --git a/actas/libs.py b/actas/libs.py index a5ca5fc..31fb61e 100644 --- a/actas/libs.py +++ b/actas/libs.py @@ -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: diff --git a/actas/tests/test_libs_validar_participantes.py b/actas/tests/test_libs_validar_participantes.py index 6ffb8d4..3516608 100644 --- a/actas/tests/test_libs_validar_participantes.py +++ b/actas/tests/test_libs_validar_participantes.py @@ -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): @@ -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)