git-subtree-dir: gerenciador git-subtree-mainline:f4f546c928git-subtree-split:34cc9c75a5
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import pytest
|
|
|
|
from app.db import log as db_log
|
|
from app.db.connection import get_connection
|
|
|
|
|
|
def _limpar_teste():
|
|
conn = get_connection()
|
|
try:
|
|
with conn.cursor() as cur:
|
|
cur.execute("DELETE FROM LOG_PAINEL WHERE USUARIO = 'teste-log'")
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
@pytest.fixture
|
|
def limpar():
|
|
_limpar_teste()
|
|
yield
|
|
_limpar_teste()
|
|
|
|
|
|
def test_registrar_e_listar(limpar):
|
|
db_log.registrar("teste-log", "criar", "cliente", "1", True)
|
|
db_log.registrar("teste-log", "excluir", "cliente", "1", False, "tem contato")
|
|
|
|
linhas = db_log.listar(limite=10)
|
|
linhas_teste = [l for l in linhas if l["USUARIO"] == "teste-log"]
|
|
assert len(linhas_teste) == 2
|
|
# ORDER BY CRIADO_EM DESC, ID DESC -> a mais recente (excluir) vem primeiro.
|
|
assert linhas_teste[0]["ACAO"] == "excluir"
|
|
assert linhas_teste[0]["SUCESSO"] == 0
|
|
assert linhas_teste[0]["DETALHE"] == "tem contato"
|
|
assert linhas_teste[1]["ACAO"] == "criar"
|
|
assert linhas_teste[1]["SUCESSO"] == 1
|
|
|
|
|
|
def test_contar(limpar):
|
|
antes = db_log.contar()
|
|
db_log.registrar("teste-log", "criar", "cliente", "1", True)
|
|
depois = db_log.contar()
|
|
assert depois == antes + 1
|
|
|
|
|
|
def test_limpar_apaga_tudo(limpar):
|
|
db_log.registrar("teste-log", "criar", "cliente", "1", True)
|
|
assert db_log.contar() > 0
|
|
|
|
db_log.limpar()
|
|
|
|
assert db_log.contar() == 0
|