From bdbafc86cf67b1f6911499f08194e5a7dc4b008f Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 10 May 2016 13:04:30 -0300 Subject: [PATCH] Fix qa --- materia/forms.py | 26 +++-------------------- materia/tests/test_materia.py | 4 ++-- materia/tests/test_materia_urls.py | 8 ++++---- materia/views.py | 33 +----------------------------- 4 files changed, 10 insertions(+), 61 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index cd924567f..49dd1ee78 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -1,13 +1,14 @@ +from datetime import datetime + import django_filters from crispy_forms.helper import FormHelper -from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit +from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout from django import forms from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models from django.db.models import Max from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ -from datetime import datetime import crispy_layout_mixin import sapl @@ -61,7 +62,6 @@ class ProposicaoForm(ModelForm): def clean(self): cleaned_data = self.cleaned_data - if cleaned_data['tipo'].descricao == 'Parecer': try: materia = MateriaLegislativa.objects.get( @@ -165,26 +165,6 @@ class RelatoriaForm(ModelForm): return cleaned_data - class Meta: - model = Relatoria - fields = ['data_designacao_relator', 'comissao', 'parlamentar', - 'data_destituicao_relator', 'tipo_fim_relatoria'] - - widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})} - - def clean(self): - cleaned_data = self.cleaned_data - - try: - comissao = Comissao.objects.get(id=self.initial['comissao']) - except ObjectDoesNotExist: - msg = _('A localização atual deve ser uma comissão.') - raise ValidationError(msg) - else: - cleaned_data['comissao'] = comissao - - return cleaned_data - class TramitacaoForm(ModelForm): diff --git a/materia/tests/test_materia.py b/materia/tests/test_materia.py index b4157f6d7..8ba003ee5 100644 --- a/materia/tests/test_materia.py +++ b/materia/tests/test_materia.py @@ -416,7 +416,7 @@ def test_form_errors_relatoria(client): @pytest.mark.django_db(transaction=False) def test_proposicao_submit(client): - response = client.post(reverse('materia:adicionar_proposicao'), + response = client.post(reverse('materia:proposicao_create'), {'tipo': mommy.make(TipoProposicao, pk=3).pk, 'descricao': 'Teste proposição', 'salvar': 'salvar'}, @@ -432,7 +432,7 @@ def test_proposicao_submit(client): @pytest.mark.django_db(transaction=False) def test_form_errors_proposicao(client): - response = client.post(reverse('materia:adicionar_proposicao'), + response = client.post(reverse('materia:proposicao_create'), {'salvar': 'salvar'}, follow=True) diff --git a/materia/tests/test_materia_urls.py b/materia/tests/test_materia_urls.py index 27f350f1b..64e341c2d 100644 --- a/materia/tests/test_materia_urls.py +++ b/materia/tests/test_materia_urls.py @@ -9,11 +9,11 @@ from django.core.urlresolvers import reverse ('materia:tramitacao_update', {'pk': '8'}, '/materia/tramitacao/8/edit'), - ('materia:adicionar_proposicao', {}, '/materia/proposicao'), - ('materia:editar_proposicao', + ('materia:proposicao_create', {}, '/proposicao/create'), + ('materia:proposicao_update', {'pk': '3'}, - '/materia/proposicao/3/edit'), - ('materia:list_proposicao', {}, '/materia/proposicao_list'), + '/proposicao/3/edit'), + ('materia:proposicao_list', {}, '/proposicao/'), ]) def test_reverse(test_input, kwargs, expected): assert reverse(test_input, kwargs=kwargs) == expected diff --git a/materia/views.py b/materia/views.py index e903de246..1cdfada39 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1,4 +1,3 @@ -import os from datetime import datetime from random import choice from string import ascii_letters, digits @@ -11,10 +10,9 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.http.response import HttpResponseRedirect -from django.shortcuts import redirect from django.template import Context, loader from django.utils.translation import ugettext_lazy as _ -from django.views.generic import CreateView, ListView, TemplateView, UpdateView +from django.views.generic import CreateView, TemplateView, UpdateView from django_filters.views import FilterView import crispy_layout_mixin @@ -164,35 +162,6 @@ class RelatoriaCrud(MasterDetailCrud): form_class = RelatoriaForm -class RelatoriaCrud(MasterDetailCrud): - model = Relatoria - parent_field = 'materia' - help_path = '' - - class CreateView(MasterDetailCrud.CreateView): - form_class = RelatoriaForm - - def get_initial(self): - materia = MateriaLegislativa.objects.get(id=self.kwargs['pk']) - - loc_atual = Tramitacao.objects.filter( - materia=materia).last() - - if loc_atual is None: - localizacao = 0 - else: - comissao = loc_atual.unidade_tramitacao_destino.comissao - if comissao: - localizacao = comissao.pk - else: - localizacao = 0 - - return {'comissao': localizacao} - - class UpdateView(MasterDetailCrud.UpdateView): - form_class = RelatoriaForm - - class TramitacaoCrud(MasterDetailCrud): model = Tramitacao parent_field = 'materia'