Browse Source

Test add parliaments to cart (abstracting add to cart)

producao
Marcio Mazza 10 years ago
parent
commit
41f40776c6
  1. 2
      sigi/apps/casas/templates/casas/carrinho.html
  2. 12
      sigi/apps/casas/test_casas.py
  3. 30
      sigi/apps/parlamentares/test_parlamentares.py
  4. 38
      sigi/test_cart.py

2
sigi/apps/casas/templates/casas/carrinho.html

@ -63,7 +63,7 @@
</ul> </ul>
<div id="tabs-1"> <div id="tabs-1">
<form action="../labels/{{query_str}}" method="post">{% csrf_token %} <form id="generate_labels" action="../labels/{{query_str}}" method="post">{% csrf_token %}
<fieldset><legend>{% trans 'Tipo de etiqueta' %}</legend> <fieldset><legend>{% trans 'Tipo de etiqueta' %}</legend>
<ul class="tabs-conteudo"> <ul class="tabs-conteudo">
<li><input type="radio" name="tipo_etiqueta" <li><input type="radio" name="tipo_etiqueta"

12
sigi/apps/casas/test_casas.py

@ -0,0 +1,12 @@
import pytest
from django_dynamic_fixture import G
from sigi.apps.casas.models import CasaLegislativa
@pytest.fixture
def some_parliaments():
a = G(CasaLegislativa, nome="Assembleia Legislativa do Amapa", foto=None, gerente_contas=None,)
b = G(CasaLegislativa, nome="Camara Municipal de Fortaleza", foto=None, gerente_contas=None,)
c = G(CasaLegislativa, nome="Camara Legislativa do Distrito Federal", foto=None, gerente_contas=None,)
return a, b, c

30
sigi/apps/parlamentares/test_parlamentares.py

@ -3,7 +3,6 @@ import pytest
from django_dynamic_fixture import G from django_dynamic_fixture import G
from sigi.apps.parlamentares.models import Parlamentar from sigi.apps.parlamentares.models import Parlamentar
from sigi.testutils import pdf_text
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
@ -34,32 +33,3 @@ def test_list_filtered_by_capital_letter(some_parlamentarians, app):
assert a.nome_completo not in decoded_content assert a.nome_completo not in decoded_content
assert b.nome_completo in decoded_content assert b.nome_completo in decoded_content
assert c.nome_completo not in decoded_content assert c.nome_completo not in decoded_content
def test_add_to_cart(some_parlamentarians, app):
res = app.get('/parlamentares/parlamentar/')
assert res.status_code == 200
a, b, c = some_parlamentarians
form = res.forms['changelist-form']
form['_selected_action'] = [a.pk, b.pk] # Andre and Bartolomeu
form['action'] = 'adiciona_parlamentar'
res = form.submit()
"2 Parlamentares adicionados" in res.content
res = app.get('/parlamentares/parlamentar/carrinho/')
def right_people_present(content):
assert a.nome_completo in content
assert b.nome_completo in content
assert c.nome_completo not in content
right_people_present(res.content)
'Formato da Etiqueta' in res.content
'Gerar Etiqueta' in res.content
labels_form = res.forms['generate_labels']
res = labels_form.submit()
assert res.content_type == 'application/pdf'
text = pdf_text(res)
right_people_present(text)

38
sigi/test_cart.py

@ -0,0 +1,38 @@
import pytest
from sigi.apps.casas.test_casas import some_parliaments
from sigi.apps.parlamentares.test_parlamentares import some_parlamentarians
from sigi.testutils import pdf_text
@pytest.mark.parametrize("url, some_entries, form_action, name_attr, verbose_name_plural", [
('/parlamentares/parlamentar/', some_parlamentarians, 'adiciona_parlamentar', 'nome_completo', 'Parlamentares'),
('/casas/casalegislativa/', some_parliaments, 'adicionar_casas', 'nome', 'Casas Legislativas'),
])
def test_add_to_cart(url, some_entries, form_action, name_attr, verbose_name_plural, app, live_server):
a, b, c = some_entries()
res = app.get(url)
assert res.status_code == 200
form = res.forms['changelist-form']
form['_selected_action'] = [a.pk, b.pk] # Andre and Bartolomeu
form['action'] = form_action
res = form.submit()
"2 %s adicionados" % verbose_name_plural in res.content
res = app.get(url + 'carrinho/')
def right_people_present(content):
assert getattr(a, name_attr) in content
assert getattr(b, name_attr) in content
assert getattr(c, name_attr) not in content
right_people_present(res.content)
'Formato da Etiqueta' in res.content
'Gerar Etiqueta' in res.content
labels_form = res.forms['generate_labels']
res = labels_form.submit()
assert res.content_type == 'application/pdf'
text = pdf_text(res)
right_people_present(text)
Loading…
Cancel
Save