fix: Tiny uses Dropstar's SKUs and finds the pickup method without settings
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 3m40s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m4s

"Testar conexão" in production said every product and the pickup forma de
envio were "sem id": the SKUs and the pickup id only existed as stack
settings nobody had set. They are Dropstar's fixed catalogue, checked against
its Tiny export: Têxtil as DTFIMP.TX.100CM plus DTFIMP.TX.0010CM to 0090CM,
UV as DTFIMP.UV.1MT plus DTFIMP.UV.010CM, for the ready sheet and loose
artwork alike. These are now the defaults, and the pickup forma de envio is
the one named like "retirar" in Tiny; the test says so when there is none,
or more than one. The settings still override both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-14 11:17:24 -03:00
parent 3c9f05041e
commit 44458aea3e
4 changed files with 102 additions and 15 deletions

View File

@@ -28,6 +28,13 @@ PICKUP = {**PAID, 'order': {**PAID['order'], 'destination': None, 'freight': {'s
READY = {'order_id': PAID['order_id'], 'number': 42, 'event': 'ready', 'reason': '', 'order': PICKUP['order']}
def product_ids(cls):
"""These tests sell by product id: without Dropstar's SKU defaults."""
for name in ('SKU_DEFAULTS', 'STEP_DEFAULTS', 'METRE_DEFAULTS'):
cls = mock.patch.dict(f'app.tiny.{name}', {}, clear=True)(cls)
return cls
class FakeAuth:
def access_token(self):
return 'access-1'
@@ -95,6 +102,7 @@ class FakeTinyCase(unittest.TestCase):
today=date(2026, 9, 24))
@product_ids
@mock.patch.dict(os.environ, PRODUCTS)
class TinyTests(FakeTinyCase):
def test_payload_carries_contact_products_address_and_freight(self):
@@ -170,6 +178,7 @@ class TinyTests(FakeTinyCase):
tiny.deliver('k4', PAID)
@product_ids
@mock.patch.dict(os.environ, PRODUCTS)
class TinyStatusTests(FakeTinyCase):
"""Situações that the client's Tiny -> n8n notices turn into WhatsApp messages."""
@@ -249,11 +258,23 @@ class TinyStatusTests(FakeTinyCase):
with mock.patch.dict(os.environ, {'TINY_FORMA_ENVIO_RETIRADA': ''}):
self.assertNotIn('transportador', order_payload(PICKUP, 1))
def test_pickup_forma_de_envio_is_found_by_name(self):
from app.tiny import check
with mock.patch.dict(os.environ, {'TINY_FORMA_ENVIO_RETIRADA': ''}):
self.tiny.deliver('k1', PICKUP)
self.assertEqual(self.orders[0]['transportador'], {'formaEnvio': {'id': 77}})
self.assertEqual(check(orders=self.tiny)['forma de envio de retirada'], 'ok')
self.methods['79'] = {'id': 79, 'nome': 'Retirada na loja', 'tipo': '6'}
self.assertIn('mais de uma', check(orders=self.tiny)['forma de envio de retirada'])
del self.methods['77'], self.methods['79']
self.assertIn('nenhuma', check(orders=self.tiny)['forma de envio de retirada'])
TEXTIL = {**PAID, 'order': {**PAID['order'], 'items': [
{'mode': 'file', 'grade': 100, 'billed_metres': '2.8', 'unit_cents': 1490, 'total_cents': 4172}]}}
@product_ids
@mock.patch.dict(os.environ, {**PRODUCTS, 'TINY_SKU_TEXTIL_FOLHA': 'DTFIMP.TX'})
class TinySkuTests(FakeTinyCase):
"""Têxtil folha sold as the client's SKUs: 1 metro plus 10 to 90 cm."""
@@ -318,6 +339,7 @@ UV = {**PAID, 'order': {**PAID['order'], 'items': [
{'mode': 'uvfile', 'grade': 100, 'billed_metres': '2.3', 'unit_cents': 6990, 'total_cents': 16077}]}}
@product_ids
@mock.patch.dict(os.environ, {**PRODUCTS, 'TINY_SKU10_UV_FOLHA': 'DTFIMP.UV.010CM'})
class TinyStepSkuTests(FakeTinyCase):
"""UV sold as one SKU per 10 cm, the only UV SKU the client has."""
@@ -346,6 +368,7 @@ class TinyStepSkuTests(FakeTinyCase):
self.assertIn('DTFIMP.UV.010CM', check(orders=self.tiny)['DTF UV 28,5 cm · folha montada'])
@product_ids
@mock.patch.dict(os.environ, {**PRODUCTS, 'TINY_SKU10_UV_FOLHA': 'DTFIMP.UV.010CM',
'TINY_SKU_METRO_UV_FOLHA': 'DTFIMP.UV.1MT'})
class TinyMetreAndStepSkuTests(FakeTinyCase):
@@ -372,6 +395,7 @@ class TinyMetreAndStepSkuTests(FakeTinyCase):
self.assertIn('DTFIMP.UV.1MT', check(orders=self.tiny)['DTF UV 28,5 cm · folha montada'])
@product_ids
@mock.patch.dict(os.environ, PRODUCTS)
class TinyProbeTests(FakeTinyCase):
"""The supervised console tool run against the fake Tiny."""
@@ -424,5 +448,23 @@ class TinyProbeTests(FakeTinyCase):
self.assertIn('o 2º envio não foi feito', lines[-1])
class DefaultSkuTests(unittest.TestCase):
"""Dropstar's catalogue needs no settings; a setting replaces a default."""
def test_defaults_and_overrides(self):
from app import tiny
empty = {name: '' for name in [*tiny.SKU_SETTINGS.values(), *tiny.STEP_SETTINGS.values(),
*tiny.METRE_SETTINGS.values(), *tiny.PRODUCT_SETTINGS.values()]}
with mock.patch.dict(os.environ, empty):
self.assertEqual(tiny.mode_codes('file'), tiny.sku_codes('DTFIMP.TX'))
self.assertEqual(tiny.mode_codes('avulsa'), tiny.sku_codes('DTFIMP.TX'))
self.assertEqual(tiny.mode_codes('uv'), ['DTFIMP.UV.1MT', 'DTFIMP.UV.010CM'])
self.assertEqual(tiny.required_settings(), ['TINY_CLIENT_ID', 'TINY_CLIENT_SECRET', 'TINY_REDIRECT_URI'])
with mock.patch.dict(os.environ, {'TINY_SKU10_UV_FOLHA': 'UV.X'}):
self.assertEqual(tiny.mode_codes('uvfile'), ['UV.X'])
with mock.patch.dict(os.environ, {'TINY_SKU_UV_FOLHA': 'UV.P'}):
self.assertEqual(tiny.mode_codes('uvfile'), tiny.sku_codes('UV.P'))
if __name__ == '__main__':
unittest.main()