diff --git a/sigi/apps/casas/test_casas.py b/sigi/apps/casas/test_casas.py
index 53e69b9..9e113c1 100644
--- a/sigi/apps/casas/test_casas.py
+++ b/sigi/apps/casas/test_casas.py
@@ -6,7 +6,12 @@ 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
+ return parliaments_from_names([
+ "Assembleia Legislativa do Amapa",
+ "Camara Municipal de Fortaleza",
+ "Camara Legislativa do Distrito Federal",
+ ])
+
+
+def parliaments_from_names(names):
+ return [G(CasaLegislativa, nome=name, foto=None, gerente_contas=None,) for name in names]
diff --git a/sigi/apps/parlamentares/templates/parlamentares/carrinho.html b/sigi/apps/parlamentares/templates/parlamentares/carrinho.html
index 0014856..8f10f18 100644
--- a/sigi/apps/parlamentares/templates/parlamentares/carrinho.html
+++ b/sigi/apps/parlamentares/templates/parlamentares/carrinho.html
@@ -13,7 +13,7 @@
{% block mensagem%}
{%if carIsEmpty%}
- - {% trans 'O carrinho está vazio, sendo assim todas as casas entram na lista para exportação de acordo com os filtros aplicados.' %}
+ - {% trans 'O carrinho está vazio, sendo assim todos os parlamentares entram na lista para exportação de acordo com os filtros aplicados.' %}
{%else%}
- {{paginas.paginator.count}} {% trans 'Parlamentares no carrinho' %}.
{%endif%}
diff --git a/sigi/apps/parlamentares/test_parlamentares.py b/sigi/apps/parlamentares/test_parlamentares.py
index de8f836..271820d 100644
--- a/sigi/apps/parlamentares/test_parlamentares.py
+++ b/sigi/apps/parlamentares/test_parlamentares.py
@@ -10,10 +10,11 @@ pytestmark = pytest.mark.django_db
@pytest.fixture
def some_parliamentarians():
- a = G(Parlamentar, nome_completo="Andre Silva", foto=None)
- b = G(Parlamentar, nome_completo="Bartolomeu Gusmao", foto=None)
- c = G(Parlamentar, nome_completo="Camila Carla", foto=None)
- return a, b, c
+ return parliamentarians_from_names(["Andre Silva", "Bartolomeu Gusmao", "Camila Carla"])
+
+
+def parliamentarians_from_names(names):
+ return [G(Parlamentar, nome_completo=name, foto=None) for name in names]
def test_list_all(some_parliamentarians, app):
diff --git a/sigi/settings/test.py b/sigi/settings/test.py
index 7cb2e70..d037147 100644
--- a/sigi/settings/test.py
+++ b/sigi/settings/test.py
@@ -19,3 +19,4 @@ DATABASES = {
# http://django-dynamic-fixture.readthedocs.org/en/latest/more.html?highlight=ddf_validate_args#validate-arguments-new-in-1-5-0
DDF_VALIDATE_ARGS = True
DDF_DEBUG_MODE = True
+DDF_DEFAULT_DATA_FIXTURE = 'sigi.testutils.SigiDataFixture'
diff --git a/sigi/test_cart.py b/sigi/test_cart.py
index e06fc99..404e99d 100644
--- a/sigi/test_cart.py
+++ b/sigi/test_cart.py
@@ -1,7 +1,8 @@
+# -*- coding: utf-8 -*-
import pytest
-from sigi.apps.casas.test_casas import some_parliaments
-from sigi.apps.parlamentares.test_parlamentares import some_parliamentarians
+from sigi.apps.casas.test_casas import some_parliaments, parliaments_from_names
+from sigi.apps.parlamentares.test_parlamentares import some_parliamentarians, parliamentarians_from_names
from sigi.testutils import pdf_text
@@ -36,3 +37,59 @@ def test_add_to_cart(url, some_entries, form_action, name_attr, verbose_name_plu
assert res.content_type == 'application/pdf'
text = pdf_text(res)
right_people_present(text)
+
+
+@pytest.mark.parametrize("url, some_entries, all_expression", [
+ ('/parlamentares/parlamentar/', some_parliamentarians, 'todos os parlamentares', ),
+ ('/casas/casalegislativa/', some_parliaments, 'todas as casas', ),
+])
+def test_no_selection_brings_everyone_to_the_cart(url, some_entries, all_expression, app):
+
+ some_entries()
+
+ res = app.get(url + 'carrinho/')
+ assert res.status_code == 200
+
+ msg = 'O carrinho está vazio, sendo assim %s entram na lista para exportação' % all_expression
+ assert msg in res.content
+
+
+@pytest.mark.parametrize("url, generate_entries", [
+ ('/parlamentares/parlamentar/', parliamentarians_from_names, ),
+ ('/casas/casalegislativa/', parliaments_from_names, ),
+])
+def test_pagination(url, generate_entries, app, live_server):
+
+ def assert_on_page_1(res):
+ assert len(res.pyquery('.result_list tbody tr')) == 100
+ assert 'Página 1 de 2' in res.content
+ assert '112 itens' in res.content
+ assert 'Anterior' not in res.content
+ link = res.html.find('a', text='Próxima')
+ assert link.attrs['href'] == '?page=2'
+
+ def assert_on_page_2(res):
+ assert len(res.pyquery('.result_list tbody tr')) == 12
+ assert 'Página 2 de 2' in res.content
+ assert '112 itens' in res.content
+ assert 'Próxima' not in res.content
+ link = res.html.find('a', text='Anterior')
+ assert link.attrs['href'] == '?page=1'
+
+ generate_entries(range(112))
+ url_cart = url + 'carrinho/'
+
+ res = app.get(url_cart)
+ assert res.status_code == 200
+ assert_on_page_1(res)
+
+ res = app.get(url_cart + '?page=2')
+ assert_on_page_2(res)
+
+ # if the argument is too big we land on the last page
+ res = app.get(url_cart + '?page=1000')
+ assert_on_page_2(res)
+
+ # if the argument is not a number we land on the first page
+ res = app.get(url + 'carrinho/?page=aaaa')
+ assert_on_page_1(res)
diff --git a/sigi/test_testutils.py b/sigi/test_testutils.py
new file mode 100644
index 0000000..0ec9969
--- /dev/null
+++ b/sigi/test_testutils.py
@@ -0,0 +1,18 @@
+from sigi.testutils import SigiDataFixture
+
+
+class FieldStub(object):
+
+ def __init__(self, max_length):
+ self.max_length = max_length
+
+
+def test_sigidatafixture():
+ data_fixture = SigiDataFixture()
+
+ field1 = FieldStub(max_length=1)
+ assert ['A', 'B', 'C'] == [data_fixture.charfield_config(field1, "") for i in range(3)]
+
+ field2 = FieldStub(max_length=2)
+ pairs = ['AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', 'CA', 'CB']
+ assert pairs == [data_fixture.charfield_config(field2, "") for i in range(len(pairs))]
diff --git a/sigi/testutils.py b/sigi/testutils.py
index 2c55d1b..bae2f14 100644
--- a/sigi/testutils.py
+++ b/sigi/testutils.py
@@ -1,6 +1,9 @@
+import string
from cStringIO import StringIO
+from itertools import product
import pyPdf
+from django_dynamic_fixture.fixture_algorithms.sequential_fixture import SequentialDataFixture
def pdf_text(res):
@@ -8,3 +11,24 @@ def pdf_text(res):
pdf = pyPdf.PdfFileReader(content_as_file)
pdf_text = '\n'.join([page.extractText() for page in pdf.pages])
return pdf_text
+
+
+class SigiDataFixture(SequentialDataFixture):
+
+ alphabet = string.ascii_uppercase
+
+ def __init__(self):
+ self.word_generators = {} # length => word generator
+ super(SigiDataFixture, self).__init__()
+
+ def get_word_generator(self, length):
+ gen = self.word_generators.get(length)
+ if not gen:
+ gen = (''.join(i) for i in product(self.alphabet, repeat=length))
+ self.word_generators[length] = gen
+ return gen
+
+ def charfield_config(self, field, key):
+ length = field.max_length or 100 # XXX leave this 100 hardcoded?
+ gen = self.get_word_generator(length)
+ return gen.next()
diff --git a/templates/admin/carrinho.html b/templates/admin/carrinho.html
index e5a4a56..4eed251 100644
--- a/templates/admin/carrinho.html
+++ b/templates/admin/carrinho.html
@@ -79,7 +79,7 @@
{% endif %}
- Página {{ paginas.number }} of {{ paginas.paginator.num_pages }}.
+ Página {{ paginas.number }} de {{ paginas.paginator.num_pages }}.
{% if paginas.has_next %}