feat: bolinha de status ativo/inativo clicavel na lista de clientes
This commit is contained in:
@@ -715,6 +715,73 @@ def test_excluir_cliente_com_dependencia_mostra_erro(monkeypatch):
|
||||
assert "tem contato" in resposta.text
|
||||
|
||||
|
||||
def test_alternar_ativo_inverte_e_redireciona_para_url_informada(monkeypatch):
|
||||
monkeypatch.setattr(router_clientes.db_clientes, "alternar_ativo", lambda cliente_id: True)
|
||||
resposta = client.post(
|
||||
"/clientes/1/alternar-ativo",
|
||||
data={"csrf_token": CSRF_TESTE, "redirecionar_para": "/clientes?status=todos&pagina=3"},
|
||||
)
|
||||
assert resposta.status_code == 303
|
||||
assert resposta.headers["location"].startswith("/clientes?status=todos&pagina=3")
|
||||
|
||||
|
||||
def test_alternar_ativo_redirecionar_para_invalido_cai_no_clientes_generico(monkeypatch):
|
||||
monkeypatch.setattr(router_clientes.db_clientes, "alternar_ativo", lambda cliente_id: True)
|
||||
resposta = client.post(
|
||||
"/clientes/1/alternar-ativo",
|
||||
data={"csrf_token": CSRF_TESTE, "redirecionar_para": "https://malicioso.example/"},
|
||||
)
|
||||
assert resposta.status_code == 303
|
||||
assert resposta.headers["location"].startswith("/clientes?")
|
||||
assert "malicioso" not in resposta.headers["location"]
|
||||
|
||||
|
||||
def test_alternar_ativo_sem_redirecionar_para_cai_no_clientes_generico(monkeypatch):
|
||||
monkeypatch.setattr(router_clientes.db_clientes, "alternar_ativo", lambda cliente_id: True)
|
||||
resposta = client.post("/clientes/1/alternar-ativo", data={"csrf_token": CSRF_TESTE})
|
||||
assert resposta.status_code == 303
|
||||
assert resposta.headers["location"].startswith("/clientes?")
|
||||
|
||||
|
||||
def test_alternar_ativo_id_inexistente_nao_finge_sucesso(monkeypatch):
|
||||
monkeypatch.setattr(router_clientes.db_clientes, "alternar_ativo", lambda cliente_id: False)
|
||||
resposta = client.post("/clientes/999/alternar-ativo", data={"csrf_token": CSRF_TESTE})
|
||||
assert resposta.status_code == 303
|
||||
assert "n%C3%A3o+encontrado" in resposta.headers["location"] or "nao encontrado" in resposta.headers["location"]
|
||||
|
||||
|
||||
def test_listar_clientes_mostra_bolinha_de_status(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
router_clientes.db_clientes,
|
||||
"listar_clientes",
|
||||
lambda **kwargs: [
|
||||
{"ID": 1, "CODIGO": "000001", "RAZAO": "Cliente Ativo", "FANTASIA": "A", "CNPJ": "1", "ATIVO": 1},
|
||||
{"ID": 2, "CODIGO": "000002", "RAZAO": "Cliente Inativo", "FANTASIA": "I", "CNPJ": "2", "ATIVO": 0},
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(router_clientes.db_clientes, "contar_clientes", lambda **kwargs: 2)
|
||||
|
||||
resposta = client.get("/clientes?status=todos")
|
||||
assert resposta.status_code == 200
|
||||
assert "status-dot-ativo" in resposta.text
|
||||
assert "status-dot-inativo" in resposta.text
|
||||
assert '/clientes/1/alternar-ativo' in resposta.text
|
||||
assert '/clientes/2/alternar-ativo' in resposta.text
|
||||
|
||||
|
||||
def test_listar_clientes_redirecionar_para_reflete_url_atual(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
router_clientes.db_clientes,
|
||||
"listar_clientes",
|
||||
lambda **kwargs: [{"ID": 1, "CODIGO": "000001", "RAZAO": "Cliente Um", "FANTASIA": "A", "CNPJ": "1", "ATIVO": 1}],
|
||||
)
|
||||
monkeypatch.setattr(router_clientes.db_clientes, "contar_clientes", lambda **kwargs: 1)
|
||||
|
||||
resposta = client.get("/clientes?status=inativos&pagina=2&por_pagina=50")
|
||||
assert resposta.status_code == 200
|
||||
assert 'value="/clientes?status=inativos&pagina=2&por_pagina=50"' in resposta.text
|
||||
|
||||
|
||||
def _limpar_codigo(codigo: str) -> None:
|
||||
conn = get_connection()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user