feat: the Tiny probe reads what a complete order needs
Some checks failed
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Failing after 50s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Has been skipped

"campos" tries each lookup a complete order needs (formas de recebimento,
financial categories, sellers, intermediaries) and names the app permission
to release when Tiny refuses one; it also shows Correios and Jadlog as Tiny
keeps them, with their freight options. "exemplo NUMERO" prints an existing
order's payment, carrier, seller, category and tags, without the customer or
the address, so Site orders can copy the store's. Both only read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-16 18:46:49 -03:00
parent dbf1efc112
commit 5910d3161f
2 changed files with 110 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ from unittest import mock
import httpx
from app import tiny as tiny_module
from app.tiny import TinyError, TinyOrders, contact_payload, order_payload
PAID = {'order_id': 'b6f1c0de-0000-4000-8000-000000000001', 'number': 42, 'event': 'payment_approved',
@@ -86,7 +87,10 @@ class FakeTinyCase(unittest.TestCase):
next(o for o in self.orders if o['id'] == wanted)['situacao'] = json.loads(request.content)['situacao']
return httpx.Response(204)
if request.method == 'GET' and path == '/pedidos':
return httpx.Response(200, json={'itens': [{'id': o['id']} for o in self.orders]})
return httpx.Response(200, json={'itens': [{'id': o['id'], 'numeroPedido': o['numeroPedido']}
for o in self.orders]})
if request.method == 'GET' and path.endswith('/marcadores'):
return httpx.Response(200, json=[{'descricao': 'SITE DTF'}])
if request.method == 'GET' and path.startswith('/pedidos/'):
wanted = int(path.rsplit('/', 1)[-1])
return httpx.Response(200, json=next(o for o in self.orders if o['id'] == wanted))
@@ -472,6 +476,36 @@ class TinyProbeTests(FakeTinyCase):
self.assertIn('77\t6\tRetirar pessoalmente', text)
self.assertTrue(all(method == 'GET' for method, _ in self.calls))
def test_campos_says_which_lookup_needs_a_permission(self):
handler = self.handler
def account(request):
path = request.url.path.removeprefix('/public-api/v3')
if path == '/formas-recebimento':
return httpx.Response(200, json={'itens': [{'id': 1, 'nome': 'Pix'}]})
if path == '/categorias-receita-despesa':
return httpx.Response(403, json={'mensagem': 'sem permissão'})
if path in ('/vendedores', '/intermediadores'):
return httpx.Response(200, json={'itens': []})
return handler(request)
self.tiny.http = httpx.Client(base_url=tiny_module.API, transport=httpx.MockTransport(account))
code, text = self.probe('campos')
self.assertEqual(code, 1)
self.assertIn('Formas de recebimento: 1', text)
self.assertIn('"nome": "Pix"', text)
self.assertIn('Libere "Contas Receber (Leitura)"', text)
self.assertIn('Forma de envio 78 · tipo 1 · Correios', text)
def test_exemplo_shows_an_order_without_the_customer(self):
self.tiny.deliver('k1', PAID)
self.orders[0].update(cliente={'nome': 'Fulano', 'cpfCnpj': '1'}, pagamento={'formaRecebimento': {'id': 1}})
code, text = self.probe('exemplo', self.orders[0]['numeroPedido'])
self.assertEqual(code, 0)
self.assertIn('"formaRecebimento"', text)
self.assertNotIn('Fulano', text)
self.assertIn('cliente', text.splitlines()[-1])
self.assertTrue(all(method == 'GET' for method, _ in self.calls[-3:]))
def test_order_is_shown_and_not_created_without_confirmation(self):
code, text = self.probe('pedido', '--cnpj', '11.222.333/0001-81', '--email', 'a@example.test',
'--celular', '16999999999')