|
@ -21,6 +21,13 @@ def assert_h1(res, title): |
|
|
assert res.html.find('h1').text == title |
|
|
assert res.html.find('h1').text == title |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def assert_on_list_page(res): |
|
|
|
|
|
assert_h1(res, 'Comissões') |
|
|
|
|
|
assert 'Adicionar Comissão' in res |
|
|
|
|
|
assert res.html.find('table') |
|
|
|
|
|
# XXX ... characterize better |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def assert_on_create_page(res): |
|
|
def assert_on_create_page(res): |
|
|
assert_h1(res, 'Adicionar Comissão') |
|
|
assert_h1(res, 'Adicionar Comissão') |
|
|
form = res.form |
|
|
form = res.form |
|
@ -35,8 +42,9 @@ def assert_on_detail_page(res, stub_name): |
|
|
assert 'Excluir Comissão' in res |
|
|
assert 'Excluir Comissão' in res |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("make_invalid_submit", [True, False]) |
|
|
@pytest.mark.parametrize("cancel, make_invalid_submit", [ |
|
|
def test_flux_list_create_detail(app, make_invalid_submit): |
|
|
(a, b) for a in (True, False) for b in (True, False)]) |
|
|
|
|
|
def test_flux_list_create_detail(app, cancel, make_invalid_submit): |
|
|
|
|
|
|
|
|
# to have a couple an option for tipo field |
|
|
# to have a couple an option for tipo field |
|
|
stub_tipo = mommy.make(TipoComissao) |
|
|
stub_tipo = mommy.make(TipoComissao) |
|
@ -44,7 +52,8 @@ def test_flux_list_create_detail(app, make_invalid_submit): |
|
|
res = app.get('/comissoes/') |
|
|
res = app.get('/comissoes/') |
|
|
|
|
|
|
|
|
# on list page |
|
|
# on list page |
|
|
assert_h1(res, 'Comissões') |
|
|
assert_on_list_page(res) |
|
|
|
|
|
|
|
|
res = res.click('Adicionar Comissão') |
|
|
res = res.click('Adicionar Comissão') |
|
|
previous_objects = set(Comissao.objects.all()) |
|
|
previous_objects = set(Comissao.objects.all()) |
|
|
|
|
|
|
|
@ -52,32 +61,41 @@ def test_flux_list_create_detail(app, make_invalid_submit): |
|
|
assert_on_create_page(res) |
|
|
assert_on_create_page(res) |
|
|
|
|
|
|
|
|
# test bifurcation ! |
|
|
# test bifurcation ! |
|
|
if make_invalid_submit: |
|
|
if cancel: |
|
|
# some fields are required => validation error |
|
|
res = res.click('Cancelar') |
|
|
res = res.form.submit() |
|
|
# back to list page |
|
|
'Formulário inválido. O registro não foi criado.' in res |
|
|
assert_on_list_page(res) |
|
|
assert_on_create_page(res) |
|
|
# db has not changed |
|
|
assert previous_objects == set(Comissao.objects.all()) |
|
|
assert previous_objects == set(Comissao.objects.all()) |
|
|
|
|
|
else: |
|
|
|
|
|
# and a test detour ! |
|
|
|
|
|
if make_invalid_submit: |
|
|
|
|
|
# some fields are required => validation error |
|
|
|
|
|
res = res.form.submit() |
|
|
|
|
|
'Formulário inválido. O registro não foi criado.' in res |
|
|
|
|
|
assert_on_create_page(res) |
|
|
|
|
|
# db has not changed |
|
|
|
|
|
assert previous_objects == set(Comissao.objects.all()) |
|
|
|
|
|
|
|
|
|
|
|
# now fill out some fields |
|
|
|
|
|
form = res.form |
|
|
|
|
|
stub_name = '### Nome Especial ###' |
|
|
|
|
|
form['nome'] = stub_name |
|
|
|
|
|
form['sigla'] = 'SIGLA' |
|
|
|
|
|
form['tipo'] = stub_tipo.id |
|
|
|
|
|
form['data_criacao'] = '1/1/2001' |
|
|
|
|
|
res = form.submit() |
|
|
|
|
|
|
|
|
|
|
|
# on redirect to detail page |
|
|
|
|
|
created = Comissao.objects.get(nome=stub_name) |
|
|
|
|
|
assert res.url.endswith('/comissoes/%s' % created.id) |
|
|
|
|
|
res = res.follow() |
|
|
|
|
|
|
|
|
# now fill out some fields |
|
|
# on detail page |
|
|
form = res.form |
|
|
assert_on_detail_page(res, stub_name) |
|
|
stub_name = '### Nome Especial ###' |
|
|
assert 'Registro criado com sucesso!' in res |
|
|
form['nome'] = stub_name |
|
|
[new_obj] = list(set(Comissao.objects.all()) - previous_objects) |
|
|
form['sigla'] = 'SIGLA' |
|
|
assert new_obj.nome == stub_name |
|
|
form['tipo'] = stub_tipo.id |
|
|
|
|
|
form['data_criacao'] = '1/1/2001' |
|
|
|
|
|
res = form.submit() |
|
|
|
|
|
|
|
|
|
|
|
# on redirect to detail page |
|
|
|
|
|
created = Comissao.objects.get(nome=stub_name) |
|
|
|
|
|
assert res.url.endswith('/comissoes/%s' % created.id) |
|
|
|
|
|
res = res.follow() |
|
|
|
|
|
|
|
|
|
|
|
# on detail page |
|
|
|
|
|
assert 'Registro criado com sucesso!' in res |
|
|
|
|
|
assert_on_detail_page(res, stub_name) |
|
|
|
|
|
[new_obj] = list(set(Comissao.objects.all()) - previous_objects) |
|
|
|
|
|
assert new_obj.nome == stub_name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_detail_page(app): |
|
|
def get_detail_page(app): |
|
@ -88,25 +106,35 @@ def get_detail_page(app): |
|
|
return stub, res |
|
|
return stub, res |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_flux_detail_update_detail(app): |
|
|
@pytest.mark.parametrize("cancel", [True, False]) |
|
|
|
|
|
def test_flux_detail_update_detail(app, cancel): |
|
|
stub, res = get_detail_page(app) |
|
|
stub, res = get_detail_page(app) |
|
|
res = res.click('Editar Comissão') |
|
|
res = res.click('Editar Comissão') |
|
|
|
|
|
|
|
|
# on update page |
|
|
# on update page |
|
|
assert_h1(res, stub.nome) |
|
|
assert_h1(res, stub.nome) |
|
|
form = res.form |
|
|
|
|
|
new_name = '### New Name ###' |
|
|
|
|
|
form['nome'] = new_name |
|
|
|
|
|
res = form.submit() |
|
|
|
|
|
|
|
|
|
|
|
# on redirect to detail page |
|
|
# test bifurcation ! |
|
|
assert res.url.endswith('/comissoes/%s' % stub.id) |
|
|
if cancel: |
|
|
res = res.follow() |
|
|
res = res.click('Cancelar') |
|
|
|
|
|
|
|
|
|
|
|
# back to detail page |
|
|
|
|
|
assert_on_detail_page(res, stub.nome) |
|
|
|
|
|
assert Comissao.objects.get(pk=stub.pk).nome == stub.nome |
|
|
|
|
|
else: |
|
|
|
|
|
form = res.form |
|
|
|
|
|
new_name = '### New Name ###' |
|
|
|
|
|
form['nome'] = new_name |
|
|
|
|
|
res = form.submit() |
|
|
|
|
|
|
|
|
|
|
|
# on redirect to detail page |
|
|
|
|
|
assert res.url.endswith('/comissoes/%s' % stub.id) |
|
|
|
|
|
res = res.follow() |
|
|
|
|
|
|
|
|
# back to detail page |
|
|
# back to detail page |
|
|
assert 'Registro alterado com sucesso!' in res |
|
|
assert_on_detail_page(res, new_name) |
|
|
assert_h1(res, new_name) |
|
|
assert 'Registro alterado com sucesso!' in res |
|
|
assert Comissao.objects.get(pk=stub.pk).nome == new_name |
|
|
assert Comissao.objects.get(pk=stub.pk).nome == new_name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("cancel", [True, False]) |
|
|
@pytest.mark.parametrize("cancel", [True, False]) |
|
@ -123,7 +151,7 @@ def test_flux_detail_delete_list(app, cancel): |
|
|
res = res.click('Cancelar') |
|
|
res = res.click('Cancelar') |
|
|
|
|
|
|
|
|
# back to detail page |
|
|
# back to detail page |
|
|
assert_h1(res, stub.nome) |
|
|
assert_on_detail_page(res, stub.nome) |
|
|
assert Comissao.objects.filter(pk=stub.pk) |
|
|
assert Comissao.objects.filter(pk=stub.pk) |
|
|
else: |
|
|
else: |
|
|
res = res.form.submit() |
|
|
res = res.form.submit() |
|
|