Browse Source

Test add parlamentarians to cart

producao
Marcio Mazza 10 years ago
parent
commit
1bf06f6aaa
  1. 4
      requirements/dev.txt
  2. 2
      sigi/apps/parlamentares/templates/parlamentares/carrinho.html
  3. 43
      sigi/apps/parlamentares/test_parlamentares.py
  4. 10
      sigi/testutils.py

4
requirements/dev.txt

@ -1,11 +1,13 @@
-r producao.txt -r producao.txt
# para testes # para testes
coverage==3.7.1
pytest-django==2.7.0 pytest-django==2.7.0
WebTest==2.0.16 WebTest==2.0.16
django-webtest==1.7.7 django-webtest==1.7.7
django-dynamic-fixture==1.7.0 django-dynamic-fixture==1.7.0
coverage==3.7.1
pytest-cov==1.8.0
pyPdf==1.13
# para desevolvimento # para desevolvimento
django-debug-toolbar==1.2.1 django-debug-toolbar==1.2.1

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

@ -58,7 +58,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 'Formato da Etiqueta' %}</legend> <fieldset><legend>{% trans 'Formato da Etiqueta' %}</legend>
<ul class="formato_etiqueta"> <ul class="formato_etiqueta">
<li><input type="radio" name="tamanho_etiqueta" <li><input type="radio" name="tamanho_etiqueta"

43
sigi/apps/parlamentares/test_parlamentares.py

@ -3,6 +3,7 @@ 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
@ -10,19 +11,18 @@ pytestmark = pytest.mark.django_db
@pytest.fixture @pytest.fixture
def some_parlamentarians(): def some_parlamentarians():
a = G(Parlamentar, nome_completo=u"Andre Silva", foto=None) a = G(Parlamentar, nome_completo="Andre Silva", foto=None)
b = G(Parlamentar, nome_completo=u"Bartolomeu Gusmao", foto=None) b = G(Parlamentar, nome_completo="Bartolomeu Gusmao", foto=None)
c = G(Parlamentar, nome_completo=u"Camila Carla", foto=None) c = G(Parlamentar, nome_completo="Camila Carla", foto=None)
return a, b, c return a, b, c
def test_list(some_parlamentarians, admin_client): def test_list_all(some_parlamentarians, admin_user, app):
response = admin_client.get('/parlamentares/parlamentar', follow=True) response = app.get('/parlamentares/parlamentar/', auto_follow=True, user=admin_user.username)
assert response.status_code == 200 assert response.status_code == 200
decoded_content = response.content.decode('utf-8')
for x in some_parlamentarians: for x in some_parlamentarians:
assert x.nome_completo in decoded_content assert x.nome_completo in response.content
def test_list_filtered_by_capital_letter(some_parlamentarians, admin_client): def test_list_filtered_by_capital_letter(some_parlamentarians, admin_client):
@ -34,3 +34,32 @@ def test_list_filtered_by_capital_letter(some_parlamentarians, admin_client):
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, admin_user, app):
res = app.get('/parlamentares/parlamentar/', auto_follow=True, user=admin_user.username)
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/', auto_follow=True, user=admin_user.username)
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)

10
sigi/testutils.py

@ -0,0 +1,10 @@
from cStringIO import StringIO
import pyPdf
def pdf_text(res):
content_as_file = StringIO(res.content)
pdf = pyPdf.PdfFileReader(content_as_file)
pdf_text = '\n'.join([page.extractText() for page in pdf.pages])
return pdf_text
Loading…
Cancel
Save