Browse Source

Test flux from 1st pg to 2nd and back on list view

pull/6/head
Marcio Mazza 10 years ago
parent
commit
e5f23978a9
  1. 44
      sapl/test_crud.py

44
sapl/test_crud.py

@ -2,10 +2,10 @@ import pytest
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from model_mommy import mommy from model_mommy import mommy
from comissoes.models import Comissao, TipoComissao
from .crud import (get_field_display, build_crud, make_pagination, from_to, from .crud import (get_field_display, build_crud, make_pagination, from_to,
NO_ENTRIES_MSG) NO_ENTRIES_MSG)
from comissoes.views import comissao_crud from comissoes.models import Comissao, TipoComissao
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
@ -185,7 +185,7 @@ def assert_on_detail_page(res, stub_name):
@pytest.mark.urls('sapl.teststubs.urls_for_list_test') @pytest.mark.urls('sapl.teststubs.urls_for_list_test')
@pytest.mark.parametrize("num_entries, page_size, ranges, page_list", [ @pytest.mark.parametrize("num_entries, page_size, ranges, page_list", [
(0, 6, [], []), (0, 6, [], []),
(5, 5, [], []), (5, 5, [(0, 5)], []),
(10, 5, [(0, 5), (5, 10)], ['«', '1', '2', '»']), (10, 5, [(0, 5), (5, 10)], ['«', '1', '2', '»']),
(9, 4, [(0, 4), (4, 8), (8, 9)], ['«', '1', '2', '3', '»']), (9, 4, [(0, 4), (4, 8), (8, 9)], ['«', '1', '2', '3', '»']),
]) ])
@ -194,7 +194,8 @@ def test_flux_list_paginate_detail(
entries_labels = [] entries_labels = []
for i in range(num_entries): for i in range(num_entries):
nome, sigla, tipo = 'nome %s' % i, 'sigla %s' % i, 'tipo %s' % i, # letter = next(letters)
nome, sigla, tipo = 'nome %s' % i, 'sigla %s' % i, 'tipo %s' % i
entries_labels.append([nome, sigla, tipo]) entries_labels.append([nome, sigla, tipo])
mommy.make(Comissao, nome=nome, sigla=sigla, tipo__nome=tipo) mommy.make(Comissao, nome=nome, sigla=sigla, tipo__nome=tipo)
@ -202,33 +203,42 @@ def test_flux_list_paginate_detail(
crud.CrudListView.paginate_by = page_size crud.CrudListView.paginate_by = page_size
res = app.get('/comissoes/') res = app.get('/comissoes/')
assert_on_list_page(res)
table = res.html.find('table')
paginator = res.html.find('ul', {'class': 'pagination'})
if num_entries == 0: if num_entries == 0:
assert_on_list_page(res)
assert NO_ENTRIES_MSG in res assert NO_ENTRIES_MSG in res
assert not table # no table
assert not paginator assert not res.html.find('table')
# no pagination
assert not res.html.find('ul', {'class': 'pagination'})
else: else:
def rows(): def assert_at_page(res, i):
header, *rows = table.findAll('tr') assert_on_list_page(res)
table = res.html.find('table')
assert table
header, *trs = table.findAll('tr')
assert header.text.strip().split() == ['nome', 'sigla', 'tipo'] assert header.text.strip().split() == ['nome', 'sigla', 'tipo']
return [[td.text.strip() for td in tr.findAll('td')] rows = [[td.text.strip() for td in tr.findAll('td')]
for tr in rows] for tr in trs]
start, end = ranges[i - 1]
assert entries_labels[start:end] == rows
paginator = res.html.find('ul', {'class': 'pagination'})
if page_list: if page_list:
assert paginator assert paginator
assert paginator.text.strip().split() == page_list assert paginator.text.strip().split() == page_list
assert entries_labels[:page_size] == rows() assert_at_page(res, 1)
if len(ranges) > 1:
res = res.click('2', href='page=2')
assert_at_page(res, 2)
res = res.click('1', href='page=1')
assert_at_page(res, 1)
# TODO... go to the second page and back
# TODO... go to detail page # TODO... go to detail page
@pytest.mark.parametrize("cancel, make_invalid_submit", [ @pytest.mark.parametrize("cancel, make_invalid_submit", [
(a, b) for a in (True, False) for b in (True, False)]) (a, b) for a in (True, False) for b in (True, False)])
def test_flux_list_create_detail(app, cancel, make_invalid_submit): def test_flux_list_create_detail(app, cancel, make_invalid_submit):

Loading…
Cancel
Save