|
|
|
@ -280,7 +280,7 @@ def test_composicaomesa_form_valido(): |
|
|
|
parlamentar = baker.make('parlamentares.Parlamentar') |
|
|
|
cargo = baker.make('parlamentares.CargoMesa') |
|
|
|
mesa_diretora = baker.make('parlamentares.MesaDiretora') |
|
|
|
mandato = baker.make( |
|
|
|
baker.make( |
|
|
|
'parlamentares.Mandato', |
|
|
|
parlamentar=parlamentar, |
|
|
|
legislatura=mesa_diretora.legislatura) |
|
|
|
@ -300,7 +300,7 @@ def test_composicaomesa_form_parlamentar_ocupando_cargo_na_mesma_mesa(): |
|
|
|
cargo1 = baker.make('parlamentares.CargoMesa') |
|
|
|
cargo2 = baker.make('parlamentares.CargoMesa') |
|
|
|
mesa_diretora = baker.make('parlamentares.MesaDiretora') |
|
|
|
mandato = baker.make( |
|
|
|
baker.make( |
|
|
|
'parlamentares.Mandato', |
|
|
|
parlamentar=parlamentar, |
|
|
|
legislatura=mesa_diretora.legislatura) |
|
|
|
@ -332,8 +332,8 @@ def test_composicaomesa_form_parlamentar_cargo_unico_mesma_mesa(): |
|
|
|
|
|
|
|
mesa_diretora = baker.make('parlamentares.MesaDiretora') |
|
|
|
|
|
|
|
mandato1 = baker.make('parlamentares.Mandato', parlamentar=parlamentar1, legislatura=mesa_diretora.legislatura) |
|
|
|
mandato2 = baker.make('parlamentares.Mandato', parlamentar=parlamentar2, legislatura=mesa_diretora.legislatura) |
|
|
|
baker.make('parlamentares.Mandato', parlamentar=parlamentar1, legislatura=mesa_diretora.legislatura) |
|
|
|
baker.make('parlamentares.Mandato', parlamentar=parlamentar2, legislatura=mesa_diretora.legislatura) |
|
|
|
|
|
|
|
ComposicaoMesa.objects.create( |
|
|
|
parlamentar=parlamentar1, |
|
|
|
@ -362,7 +362,7 @@ def test_composicaomesa_form_view_create(admin_client): |
|
|
|
parlamentar = baker.make('parlamentares.Parlamentar') |
|
|
|
cargo = baker.make('parlamentares.CargoMesa') |
|
|
|
mesa_diretora = baker.make('parlamentares.MesaDiretora') |
|
|
|
mandato = baker.make( |
|
|
|
baker.make( |
|
|
|
'parlamentares.Mandato', |
|
|
|
parlamentar=parlamentar, |
|
|
|
legislatura=mesa_diretora.legislatura) |
|
|
|
@ -372,6 +372,7 @@ def test_composicaomesa_form_view_create(admin_client): |
|
|
|
'cargo': cargo.id, |
|
|
|
}) |
|
|
|
|
|
|
|
assert response.status_code == 302 # Redirecionamento após criação bem-sucedida |
|
|
|
assert ComposicaoMesa.objects.filter(parlamentar=parlamentar, cargo=cargo, mesa_diretora=mesa_diretora).exists() |
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False) |
|
|
|
@ -379,7 +380,7 @@ def test_composicaomesa_form_view_update(admin_client): |
|
|
|
parlamentar = baker.make('parlamentares.Parlamentar') |
|
|
|
cargo = baker.make('parlamentares.CargoMesa') |
|
|
|
mesa_diretora = baker.make('parlamentares.MesaDiretora') |
|
|
|
mandato = baker.make( |
|
|
|
baker.make( |
|
|
|
'parlamentares.Mandato', |
|
|
|
parlamentar=parlamentar, |
|
|
|
legislatura=mesa_diretora.legislatura) |
|
|
|
@ -398,4 +399,74 @@ def test_composicaomesa_form_view_update(admin_client): |
|
|
|
}) |
|
|
|
|
|
|
|
composicao.refresh_from_db() |
|
|
|
assert response.status_code == 302 # Redirecionamento após atualização bem-sucedida |
|
|
|
assert composicao.cargo == new_cargo |
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False) |
|
|
|
def test_mesadiretora_filter_set_sem_get(client): |
|
|
|
# MesaDiretoraFilterSet deve retornar apenas a legislatura atual quando não há parâmetros GET |
|
|
|
|
|
|
|
legislatura_antiga = baker.make('parlamentares.Legislatura', data_inicio='2017-01-01', data_fim='2020-12-31') |
|
|
|
baker.make('parlamentares.MesaDiretora', legislatura=legislatura_antiga, data_inicio='2017-01-01', data_fim='2018-12-31') |
|
|
|
|
|
|
|
legislatura_atual = baker.make('parlamentares.Legislatura', data_inicio='2021-01-01', data_fim='2024-12-31') |
|
|
|
baker.make('parlamentares.MesaDiretora', legislatura=legislatura_atual, data_inicio='2021-01-01', data_fim='2022-12-31') |
|
|
|
mesa_at2 = baker.make('parlamentares.MesaDiretora', legislatura=legislatura_atual, data_inicio='2022-01-01', data_fim='2023-12-31') |
|
|
|
|
|
|
|
response = client.get(reverse('sapl.parlamentares:mesadiretora_list')) |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.context['filter'].qs.count() == 2 |
|
|
|
assert response.context['filter'].qs.first() == mesa_at2 |
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False) |
|
|
|
def test_mesadiretora_filter_set_get_mesa_404(client): |
|
|
|
# MesaDiretoraFilterSet deve retornar 404 quando o parâmetro GET 'mesa' não corresponder a nenhuma mesa existente |
|
|
|
|
|
|
|
response = client.get(reverse('sapl.parlamentares:mesadiretora_list'), {'mesa': 9999}) |
|
|
|
assert response.status_code == 404 |
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False) |
|
|
|
def test_mesadiretora_filter_set_get_mesa(client): |
|
|
|
# MesaDiretoraFilterSet deve retornar a mesa correspondente quando o parâmetro GET 'mesa' corresponder a uma mesa existente |
|
|
|
|
|
|
|
legislatura_atual = baker.make('parlamentares.Legislatura', data_inicio='2021-01-01', data_fim='2024-12-31') |
|
|
|
mesa = baker.make('parlamentares.MesaDiretora', legislatura=legislatura_atual, data_inicio='2021-01-01', data_fim='2022-12-31') |
|
|
|
|
|
|
|
response = client.get(reverse('sapl.parlamentares:mesadiretora_list'), {'mesa': mesa.id}) |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.context['filter'].qs.count() == 1 |
|
|
|
assert response.context['filter'].qs.first() == mesa |
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False) |
|
|
|
def test_mesadiretora_filter_set_get_legislatura(client): |
|
|
|
# MesaDiretoraFilterSet deve retornar apenas as mesas correspondentes à legislatura especificada no parâmetro GET 'legislatura' |
|
|
|
|
|
|
|
legislatura_antiga = baker.make('parlamentares.Legislatura', data_inicio='2017-01-01', data_fim='2020-12-31') |
|
|
|
baker.make('parlamentares.MesaDiretora', legislatura=legislatura_antiga, data_inicio='2017-01-01', data_fim='2018-12-31') |
|
|
|
|
|
|
|
legislatura_atual = baker.make('parlamentares.Legislatura', data_inicio='2021-01-01', data_fim='2024-12-31') |
|
|
|
mesa_at1 = baker.make('parlamentares.MesaDiretora', legislatura=legislatura_atual, data_inicio='2021-01-01', data_fim='2022-12-31') |
|
|
|
mesa_at2 = baker.make('parlamentares.MesaDiretora', legislatura=legislatura_atual, data_inicio='2022-01-01', data_fim='2023-12-31') |
|
|
|
|
|
|
|
response = client.get(reverse('sapl.parlamentares:mesadiretora_list'), {'legislatura': legislatura_atual.id}) |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.context['filter'].qs.count() == 2 |
|
|
|
assert mesa_at1 in response.context['filter'].qs |
|
|
|
assert mesa_at2 in response.context['filter'].qs |
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False) |
|
|
|
def test_mesadiretora_filter_set_(client): |
|
|
|
# Uma legislatura com 3 mesas, testar as abas no html |
|
|
|
legislatura = baker.make('parlamentares.Legislatura', data_inicio='2021-01-01', data_fim='2024-12-31') |
|
|
|
_ = baker.make('parlamentares.MesaDiretora', legislatura=legislatura, data_inicio='2021-01-01', data_fim='2022-12-31') |
|
|
|
_ = baker.make('parlamentares.MesaDiretora', legislatura=legislatura, data_inicio='2022-01-01', data_fim='2023-12-31') |
|
|
|
_ = baker.make('parlamentares.MesaDiretora', legislatura=legislatura, data_inicio='2023-01-01', data_fim='2024-12-31') |
|
|
|
|
|
|
|
response = client.get(reverse('sapl.parlamentares:mesadiretora_list')) |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.context['filter'].qs.count() == 3 |
|
|
|
|
|
|
|
ids_mesas = [f'id="tab-mesa-{mesa.id}"' for mesa in response.context['filter'].qs] |
|
|
|
|
|
|
|
for id_mesa in ids_mesas: |
|
|
|
assert id_mesa in response.content.decode('utf-8') |
|
|
|
|