Browse Source

Ajusta test_materia.py e erro apontados pós ajustes

pull/1361/head
LeandroRoberto 7 years ago
parent
commit
7b9ab90f44
  1. 9
      sapl/materia/forms.py
  2. 19
      sapl/materia/migrations/0011_auto_20170808_1034.py
  3. 10
      sapl/materia/tests/test_materia.py

9
sapl/materia/forms.py

@ -697,7 +697,7 @@ class AutoriaForm(ModelForm):
empty_label=_('Selecione'),) empty_label=_('Selecione'),)
data_relativa = forms.DateField( data_relativa = forms.DateField(
widget=forms.HiddenInput()) widget=forms.HiddenInput(), required=False)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(AutoriaForm, self).__init__(*args, **kwargs) super(AutoriaForm, self).__init__(*args, **kwargs)
@ -721,12 +721,15 @@ class AutoriaForm(ModelForm):
def clean(self): def clean(self):
cd = super(AutoriaForm, self).clean() cd = super(AutoriaForm, self).clean()
if self.errors:
return self.errors
autorias = Autoria.objects.filter( autorias = Autoria.objects.filter(
materia=self.instance.materia, autor=cd['autor']) materia=self.instance.materia, autor=cd['autor'])
pk = self.instance.pk pk = self.instance.pk
if ((not pk and autorias.exists()) if ((not pk and autorias.exists()) or
or (pk and autorias.exclude(pk=pk).exists())): (pk and autorias.exclude(pk=pk).exists())):
raise ValidationError(_('Esse Autor já foi cadastrado.')) raise ValidationError(_('Esse Autor já foi cadastrado.'))
return cd return cd

19
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'},
),
]

10
sapl/materia/tests/test_materia.py

@ -1,9 +1,9 @@
import pytest
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from model_mommy import mommy from model_mommy import mommy
import pytest
from sapl.base.models import Autor, TipoAutor from sapl.base.models import Autor, TipoAutor
from sapl.comissoes.models import Comissao, TipoComissao from sapl.comissoes.models import Comissao, TipoComissao
@ -133,12 +133,13 @@ def test_autoria_submit(admin_client):
nome='Autor Teste') nome='Autor Teste')
# Testa POST # Testa POST
response = admin_client.post(reverse('sapl.materia:autoria_create', response = admin_client.post(
reverse('sapl.materia:autoria_create',
kwargs={'pk': materia_principal.pk}), kwargs={'pk': materia_principal.pk}),
{'autor': autor.pk, {'autor': autor.pk,
'primeiro_autor': True, 'primeiro_autor': True,
'materia_id': materia_principal.pk, 'materia_id': materia_principal.pk,
'partido': '', 'data_relativa': '',
'salvar': 'salvar'}, 'salvar': 'salvar'},
follow=True) follow=True)
assert response.status_code == 200 assert response.status_code == 200
@ -323,8 +324,7 @@ def test_form_errors_autoria(admin_client):
response = admin_client.post(reverse('sapl.materia:autoria_create', response = admin_client.post(reverse('sapl.materia:autoria_create',
kwargs={'pk': materia_principal.pk}), kwargs={'pk': materia_principal.pk}),
{'materia_id': materia_principal.pk, {'materia_id': materia_principal.pk,
'partido': '', 'autor_id': '',
'autor': '',
'salvar': 'salvar'}, 'salvar': 'salvar'},
follow=True) follow=True)

Loading…
Cancel
Save