From 3c9f05041e32e690a7e9db8a3dd6dd1ca26cbd23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 14 Oct 2026 10:54:19 -0300 Subject: [PATCH] fix: Tiny's connection test no longer times out listing orders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Testar conexão" asked Tiny for one order with no filter, and on the client's account Tiny answered 400 "Sua consulta levou muito tempo". It now asks for orders since yesterday, which proves the same permission. Co-Authored-By: Claude Opus 5.5 --- app/tiny.py | 9 ++++++--- tests/test_tiny.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/tiny.py b/app/tiny.py index f0616db..a76a0e2 100644 --- a/app/tiny.py +++ b/app/tiny.py @@ -450,11 +450,14 @@ def check(auth=None, transport=None, orders=None): 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}) + def listed(path, **filters): + orders.request('GET', path, params={'limit': 1, **filters}) return 'ok' - reads = [('pedidos', lambda: listed('/pedidos')), ('contatos', lambda: listed('/contatos'))] + # Unfiltered, a large account's order list times out ("Sua consulta levou + # muito tempo"): yesterday's orders prove the same permission. + since = (local_today() - timedelta(days=1)).isoformat() + reads = [('pedidos', lambda: listed('/pedidos', dataInicial=since)), ('contatos', lambda: listed('/contatos'))] reads += [(PRODUCTS[mode], lambda mode=mode: configured_skus(orders, mode) if mode_codes(mode) else configured_product(orders, mode)[1]) for mode in PRODUCT_SETTINGS] reads.append(('forma de envio de retirada', lambda: configured_pickup(orders)[1])) diff --git a/tests/test_tiny.py b/tests/test_tiny.py index 0c7eab6..6669ee9 100644 --- a/tests/test_tiny.py +++ b/tests/test_tiny.py @@ -151,6 +151,16 @@ class TinyTests(FakeTinyCase): self.assertIn('não está ativo', results['DTF UV 28,5 cm · folha montada']) self.assertEqual(results['DTF UV 28,5 cm · artes avulsas'], 'TINY_PRODUCT_UV_AVULSA sem id') self.assertEqual(results['pedidos'], 'ok') + # The order list is asked by date: unfiltered, Tiny times out on a large account. + asked = [] + def timing_out(request): + if request.url.path.endswith('/pedidos'): + asked.append(dict(request.url.params)) + if 'dataInicial' not in request.url.params: + return httpx.Response(400, json={'mensagem': 'Sua consulta levou muito tempo.'}) + return self.handler(request) + self.assertEqual(check(auth=FakeAuth(), transport=httpx.MockTransport(timing_out))['pedidos'], 'ok') + self.assertEqual(asked[-1]['limit'], '1') denied = check(auth=FakeAuth(), transport=httpx.MockTransport(lambda r: httpx.Response(403, text='forbidden'))) self.assertTrue(denied['pedidos'].startswith('GET /pedidos: 403'))