feat: the launch reset keeps the order numbering and clears the folders (0.11)

The existing launch_reset now also empties the Kanban flow folders, keeps
Estampas/, and no longer restarts orders.number: DTF-1…DTF-15 already exist
in Tiny. It still refuses real money, counts first and needs APAGAR.
This commit is contained in:
Cauê Faleiros
2026-11-06 11:11:36 -03:00
parent 6351a094f4
commit 2bcdb060fd
5 changed files with 71 additions and 153 deletions

View File

@@ -3,6 +3,8 @@
It empties the order tables, so it runs last. Run inside the API container:
python -m tests.launch_reset_test
"""
import tempfile
from pathlib import Path
from uuid import uuid4
from psycopg.types.json import Jsonb
@@ -37,6 +39,8 @@ def run():
with db.connect() as c:
assert c.execute('SELECT 1 FROM dtf_local.orders WHERE id=%s', (order,)).fetchone()
with db.connect() as c:
before_number = c.execute('SELECT COALESCE(max(number),0) AS n FROM dtf_local.orders').fetchone()['n']
lines.clear()
assert launch_reset.main(['--confirmar', 'APAGAR'], out=lines.append) == 0, lines
with db.connect() as c:
@@ -45,8 +49,8 @@ def run():
assert not c.execute('''SELECT 1 FROM dtf_local.uploads WHERE purged_at IS NULL
AND expires_at>now()''').fetchone()
assert c.execute('SELECT count(*) AS n FROM dtf_local.operators').fetchone()['n'] >= 1
assert 'Apagado.' in lines and 'A numeração dos pedidos recomeça em #1.' in lines, lines
# The worker's own role restarts the numbers: the next order is #1.
assert 'Apagado.' in lines and 'continua de onde parou' in lines[-1], lines
# The numbering is not reset: DTF-1…DTF-15 already exist in Tiny.
with db.connect() as c:
quote = uuid4()
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
@@ -55,10 +59,25 @@ def run():
first = c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin)
VALUES(%s,%s,%s,%s,%s,'site') RETURNING number''', (uuid4(), quote, owner, Jsonb({'items': []}),
Jsonb({'provider': 'teste'}))).fetchone()['number']
assert first == 1, first
assert first > before_number, (first, before_number)
c.execute('DELETE FROM dtf_local.orders WHERE quote_id=%s', (quote,))
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (quote,))
print('PASS: launch cleanup refuses real payments, counts first, then removes test orders and quotes')
# The Kanban folders: only the flow folders are emptied; Estampas stays.
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
for name in ('1. Arte recebida', '2. Arte conferida', '3. Imprimindo',
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões'):
(root / name).mkdir()
(root / name / 'card.txt').write_text('x')
(root / 'Estampas').mkdir()
(root / 'Estampas' / '1001.png').write_bytes(b'art')
lines.clear()
assert launch_reset.main(['--root', temp, '--confirmar', 'APAGAR'], out=lines.append) == 0, lines
for name in ('1. Arte recebida', '2. Arte conferida', '3. Imprimindo',
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões'):
assert list((root / name).iterdir()) == [], name
assert (root / 'Estampas' / '1001.png').read_bytes() == b'art'
print('PASS: launch cleanup refuses real payments, counts first, then removes test orders and quotes, keeping the numbering and the art library')
if __name__ == '__main__':

View File

@@ -1,32 +0,0 @@
"""0.11 folder cleaning: empty the flow folders, keep the art library."""
import tempfile
import unittest
from pathlib import Path
from ops.reset_board import FLOW_FOLDERS, clean_folders
class ResetFoldersTests(unittest.TestCase):
def test_empties_flow_folders_and_keeps_estampas(self):
with tempfile.TemporaryDirectory() as folder:
root = Path(folder)
for name in FLOW_FOLDERS:
(root / name).mkdir()
(root / name / 'card.txt').write_text('x')
library = root / 'Estampas'
library.mkdir()
(library / '1001.png').write_bytes(b'art')
clean_folders(root, dry_run=False)
for name in FLOW_FOLDERS:
self.assertTrue((root / name).is_dir(), name)
self.assertEqual(list((root / name).iterdir()), [], name)
self.assertEqual((library / '1001.png').read_bytes(), b'art')
def test_refuses_a_folder_that_is_not_the_kanban_root(self):
with tempfile.TemporaryDirectory() as folder:
with self.assertRaises(SystemExit):
clean_folders(folder, dry_run=True)
if __name__ == '__main__':
unittest.main()