Add 'gerenciador/' from commit '34cc9c75a57dedbf61a6e6a1ba1f35f76e72434b'
git-subtree-dir: gerenciador git-subtree-mainline:f4f546c928git-subtree-split:34cc9c75a5
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from app import n8n_client
|
||||
|
||||
|
||||
def test_nao_configurado_retorna_vazio(monkeypatch):
|
||||
monkeypatch.delenv("N8N_API_URL", raising=False)
|
||||
monkeypatch.delenv("N8N_API_KEY", raising=False)
|
||||
assert n8n_client.configurado() is False
|
||||
assert n8n_client.listar_envios() == []
|
||||
|
||||
|
||||
def test_configurado_com_ambas_variaveis(monkeypatch):
|
||||
monkeypatch.setenv("N8N_API_URL", "https://devn8n.exemplo.com")
|
||||
monkeypatch.setenv("N8N_API_KEY", "chave-teste")
|
||||
assert n8n_client.configurado() is True
|
||||
|
||||
|
||||
def test_listar_envios_falha_de_rede_retorna_vazio(monkeypatch):
|
||||
monkeypatch.setenv("N8N_API_URL", "https://devn8n.exemplo.com")
|
||||
monkeypatch.setenv("N8N_API_KEY", "chave-teste")
|
||||
|
||||
def _get_com_erro(*args, **kwargs):
|
||||
raise httpx.ConnectError("falhou")
|
||||
|
||||
monkeypatch.setattr(n8n_client.httpx, "get", _get_com_erro)
|
||||
assert n8n_client.listar_envios() == []
|
||||
|
||||
|
||||
def test_listar_envios_sucesso_retorna_linhas(monkeypatch):
|
||||
monkeypatch.setenv("N8N_API_URL", "https://devn8n.exemplo.com/")
|
||||
monkeypatch.setenv("N8N_API_KEY", "chave-teste")
|
||||
|
||||
linhas = [{"codigo_cliente": "000001", "status": "enviado"}]
|
||||
|
||||
class _RespostaFalsa:
|
||||
def raise_for_status(self):
|
||||
pass
|
||||
|
||||
def json(self):
|
||||
return {"data": linhas}
|
||||
|
||||
capturado = {}
|
||||
|
||||
def _get_falso(url, headers=None, params=None, timeout=None):
|
||||
capturado["url"] = url
|
||||
capturado["headers"] = headers
|
||||
capturado["params"] = params
|
||||
return _RespostaFalsa()
|
||||
|
||||
monkeypatch.setattr(n8n_client.httpx, "get", _get_falso)
|
||||
|
||||
resultado = n8n_client.listar_envios(limite=10)
|
||||
assert resultado == linhas
|
||||
assert capturado["url"] == "https://devn8n.exemplo.com/api/v1/data-tables/bJHhFUDwFJ30YJVt/rows"
|
||||
assert capturado["headers"]["X-N8N-API-KEY"] == "chave-teste"
|
||||
# Regression guard: a API do n8n usa "limit", não "take" (achado real
|
||||
# testando contra a instância de verdade — "take" retorna 400).
|
||||
assert capturado["params"] == {"limit": 10, "sortBy": "data_processamento:desc"}
|
||||
Reference in New Issue
Block a user