feat: check Tiny products and add a supervised order test
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 2m39s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m43s
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 2m39s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m43s
"Testar conexão" now also reads the four configured Tiny products and requires each to be active. app/tiny_probe.py runs from the worker console to list products, confirm the configured ids, and create one marked test order through the worker's own delivery path, proving the duplicate guard by search before a second delivery. Nothing is sent without --confirmar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
33
app/tiny.py
33
app/tiny.py
@@ -223,16 +223,35 @@ def order_payload(payload, contact_id, today=None):
|
||||
return pedido
|
||||
|
||||
|
||||
def check(auth=None, transport=None):
|
||||
def configured_product(orders, mode):
|
||||
"""The Tiny product a mode's setting points at, or a reason it cannot be used."""
|
||||
setting = PRODUCT_SETTINGS[mode]
|
||||
value = os.environ.get(setting, '')
|
||||
if not value.isdigit():
|
||||
return None, f'{setting} sem id'
|
||||
found = orders.request('GET', f'/produtos/{value}')
|
||||
if found.get('situacao') != 'A':
|
||||
return found, f"produto {value} não está ativo no Tiny ({found.get('situacao')})"
|
||||
return found, 'ok'
|
||||
|
||||
|
||||
def check(auth=None, transport=None, orders=None):
|
||||
"""Read-only proof that the connection and permissions work: one order and
|
||||
one contact listed, nothing created. Raises TinyNotConnected when there is
|
||||
no usable connection; otherwise reports each read separately."""
|
||||
orders = TinyOrders(auth=auth or TinyAuth(), transport=transport)
|
||||
one contact listed and each configured product found active, nothing
|
||||
created. Raises TinyNotConnected when there is no usable connection;
|
||||
otherwise reports each read separately."""
|
||||
orders = orders or TinyOrders(auth=auth or TinyAuth(), transport=transport)
|
||||
|
||||
def listed(path):
|
||||
orders.request('GET', path, params={'limit': 1})
|
||||
return 'ok'
|
||||
|
||||
reads = [('pedidos', lambda: listed('/pedidos')), ('contatos', lambda: listed('/contatos'))]
|
||||
reads += [(PRODUCTS[mode], lambda mode=mode: configured_product(orders, mode)[1]) for mode in PRODUCT_SETTINGS]
|
||||
results = {}
|
||||
for name, path in (('pedidos', '/pedidos'), ('contatos', '/contatos')):
|
||||
for name, read in reads:
|
||||
try:
|
||||
orders.request('GET', path, params={'limit': 1})
|
||||
results[name] = 'ok'
|
||||
results[name] = read()
|
||||
except TinyNotConnected:
|
||||
raise
|
||||
except TinyError as exc:
|
||||
|
||||
Reference in New Issue
Block a user