From 7b9ab90f44b35933308c4037ed6f0c7847a04ec6 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Tue, 8 Aug 2017 11:04:46 -0300 Subject: [PATCH] =?UTF-8?q?Ajusta=20test=5Fmateria.py=20e=20erro=20apontad?= =?UTF-8?q?os=20p=C3=B3s=20ajustes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/forms.py | 9 +++++--- .../migrations/0011_auto_20170808_1034.py | 19 ++++++++++++++++ sapl/materia/tests/test_materia.py | 22 +++++++++---------- 3 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 sapl/materia/migrations/0011_auto_20170808_1034.py diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 11e2d62b7..1c6ad78b1 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -697,7 +697,7 @@ class AutoriaForm(ModelForm): empty_label=_('Selecione'),) data_relativa = forms.DateField( - widget=forms.HiddenInput()) + widget=forms.HiddenInput(), required=False) def __init__(self, *args, **kwargs): super(AutoriaForm, self).__init__(*args, **kwargs) @@ -721,12 +721,15 @@ class AutoriaForm(ModelForm): def clean(self): cd = super(AutoriaForm, self).clean() + if self.errors: + return self.errors + autorias = Autoria.objects.filter( materia=self.instance.materia, autor=cd['autor']) pk = self.instance.pk - if ((not pk and autorias.exists()) - or (pk and autorias.exclude(pk=pk).exists())): + if ((not pk and autorias.exists()) or + (pk and autorias.exclude(pk=pk).exists())): raise ValidationError(_('Esse Autor já foi cadastrado.')) return cd diff --git a/sapl/materia/migrations/0011_auto_20170808_1034.py b/sapl/materia/migrations/0011_auto_20170808_1034.py new file mode 100644 index 000000000..209a87c70 --- /dev/null +++ b/sapl/materia/migrations/0011_auto_20170808_1034.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2017-08-08 10:34 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0010_auto_20170808_0850'), + ] + + operations = [ + migrations.AlterModelOptions( + name='autoria', + options={'ordering': ('-primeiro_autor', 'autor__nome'), 'verbose_name': 'Autoria', 'verbose_name_plural': 'Autorias'}, + ), + ] diff --git a/sapl/materia/tests/test_materia.py b/sapl/materia/tests/test_materia.py index 20f3a12fa..fc160b952 100644 --- a/sapl/materia/tests/test_materia.py +++ b/sapl/materia/tests/test_materia.py @@ -1,9 +1,9 @@ -import pytest from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse from model_mommy import mommy +import pytest from sapl.base.models import Autor, TipoAutor from sapl.comissoes.models import Comissao, TipoComissao @@ -133,14 +133,15 @@ def test_autoria_submit(admin_client): nome='Autor Teste') # Testa POST - response = admin_client.post(reverse('sapl.materia:autoria_create', - kwargs={'pk': materia_principal.pk}), - {'autor': autor.pk, - 'primeiro_autor': True, - 'materia_id': materia_principal.pk, - 'partido': '', - 'salvar': 'salvar'}, - follow=True) + response = admin_client.post( + reverse('sapl.materia:autoria_create', + kwargs={'pk': materia_principal.pk}), + {'autor': autor.pk, + 'primeiro_autor': True, + 'materia_id': materia_principal.pk, + 'data_relativa': '', + 'salvar': 'salvar'}, + follow=True) assert response.status_code == 200 # Verifica se o autor foi realmente criado @@ -323,8 +324,7 @@ def test_form_errors_autoria(admin_client): response = admin_client.post(reverse('sapl.materia:autoria_create', kwargs={'pk': materia_principal.pk}), {'materia_id': materia_principal.pk, - 'partido': '', - 'autor': '', + 'autor_id': '', 'salvar': 'salvar'}, follow=True)