From 054a642a6143a1abd7d97288443ef29b9b52f74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 6 Nov 2026 11:02:43 -0300 Subject: [PATCH] test: the suite follows pull-only machines, the proof lock and 200 DPI The old tests created orders with an automatic machine and moved them without one. They now choose a machine or pass it to the pull, expect the proof lock before any move, and use the 200 DPI clean grade. --- tests/smoke_test.py | 39 +++++++++++--------- tests/users_test.py | 80 ++++++++++++++---------------------------- tests/workflow_test.py | 12 +++++-- 3 files changed, 60 insertions(+), 71 deletions(-) diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 2f686eb..e971993 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -210,9 +210,11 @@ def run(): # A cart the Site priced is approved at once and can be paid straight away, # at the server's own prices; no operator can then change it. # The server works the grade out from the file: this PNG is 6059 px across - # 57 cm, 270 DPI, which is grade 90. + # 57 cm, 270 DPI, which is grade 100 under the 200 DPI clean threshold. png=b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR'+(6059).to_bytes(4,'big')+(2000).to_bytes(4,'big')+b'\x08\x06\x00\x00\x00'+b'\x00'*4 graded=upload_bytes(client,png,name='arte-270dpi.png') + low_png=b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR'+(3366).to_bytes(4,'big')+(2000).to_bytes(4,'big')+b'\x08\x06\x00\x00\x00'+b'\x00'*4 + low=upload_bytes(client,low_png,name='arte-150dpi.png') small={**draft,'request_key':str(uuid4()),'items':[item_spec('avulsa','2.75',90,graded)]} auto=client.call('/quotes',small) assert auto['status']=='approved' @@ -258,9 +260,10 @@ def run(): assert client.call('/quotes/'+held['id'])['review_reason']=='Nota não conferida no servidor' # A better grade than the file supports, or one the server cannot check, waits too: # the price ignores the grade, but the order shows it. - inflated=client.call('/quotes',{**small,'request_key':str(uuid4()),'items':[item_spec('avulsa','2.75',100,graded)]}) + low_item={**item_spec('avulsa','2.75',100,low),'quality_status':'warning','quality_acknowledged':True} + inflated=client.call('/quotes',{**small,'request_key':str(uuid4()),'items':[low_item]}) assert inflated['status']=='pending_review' - assert client.call('/quotes/'+inflated['id'])['review_reason']=='Nota 100 maior que a do arquivo (90)' + assert client.call('/quotes/'+inflated['id'])['review_reason']=='Nota 100 maior que a do arquivo (75)' unchecked=client.call('/quotes',{**small,'request_key':str(uuid4()),'items':[item_spec('avulsa','2.75',90,uid)]}) assert client.call('/quotes/'+unchecked['id'])['review_reason']=='Nota não conferida no servidor' print('PASS: priced carts are approved at checkout; large or inconsistent ones wait for review') @@ -275,9 +278,19 @@ def run(): board=client.call('/operator/board',operator=True) assert len([o for o in board['orders'] if o['quote_id']==qid])==1 client.call('/operator/orders/'+oid+'/move',{'state':'fin','version':0},operator=True,expected=409) - client.call('/operator/orders/'+oid+'/move',{'state':'cor','version':0},operator=True,expected=422) - version=0 + # Above 10 m the proof comes first: the parent cannot move at all until + # Prova OK on its proof card in Revisão (item 0.1). + held=client.call('/operator/orders/'+oid+'/move',{'state':'cor','version':0},operator=True,expected=409) + assert 'Aguardando prova' in held['detail'], held + card=next(o for o in board['orders'] if o['id']==oid)['proof_card'] + from app.core import db + with db.connect() as c: + c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s",(card['id'],)) + client.call('/operator/orders/'+card['id']+'/proof-answer',{'result':'ok'},operator=True) + version=next(o for o in client.call('/operator/board',operator=True)['orders'] if o['id']==oid)['version'] + client.call('/operator/orders/'+oid+'/move',{'state':'cor','version':version},operator=True,expected=422) # Dropstar's flow (2026-10-23): Arte conferida is the queue, Revisão comes before Finalizado. + machine=None for state in ('cor','rec','tra','imp','rev','fin'): if state=='tra': # The queue takes approved final files only. @@ -285,18 +298,12 @@ def run(): files=[{'item_index':i,'upload_id':upload_bytes(client,final_png_bytes(str(i)),name=f'LOCAL-FINAL-{i}.png',order_id=oid)} for i in range(4)] result=client.call('/operator/orders/'+oid+'/final-files',{'version':version,'files':files,'note':'Local test manual final-file approval'},operator=True) version=result['version'] + body={'state':state,'version':version,'reason':'Local test correction' if state=='cor' else ''} if state=='imp': - # Above 10 m the proof comes first (app/proof.py): the order waits - # outside the queue for Prova OK on its proof card in Revisão. - held=client.call('/operator/orders/'+oid+'/move',{'state':'imp','version':version},operator=True,expected=409) - assert 'Aguardando prova' in held['detail'], held - card=next(o for o in client.call('/operator/board',operator=True)['orders'] if o['id']==oid)['proof_card'] - from app.core import db - with db.connect() as c: - c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s",(card['id'],)) - client.call('/operator/orders/'+card['id']+'/proof-answer',{'result':'ok'},operator=True) - version+=1 - moved=client.call('/operator/orders/'+oid+'/move',{'state':state,'version':version,'reason':'Local test correction' if state=='cor' else ''},operator=True) + if machine is None: + machine=client.call('/operator/machines',{'name':'Smoke '+uuid4().hex[:6],'products':['textil']},operator=True)['id'] + body['machine_id']=machine + moved=client.call('/operator/orders/'+oid+'/move',body,operator=True) version+=1;assert moved['version']==version client.call('/operator/orders/'+oid+'/move',{'state':'rec','version':0},operator=True,expected=409) assert len(client.call('/operator/orders/'+oid+'/history',operator=True))==6 diff --git a/tests/users_test.py b/tests/users_test.py index a231115..78284c0 100644 --- a/tests/users_test.py +++ b/tests/users_test.py @@ -4,13 +4,11 @@ Run inside the API container: python -m tests.users_test """ import secrets import time -from decimal import Decimal from urllib.request import Request, urlopen from uuid import uuid4 from psycopg.types.json import Jsonb -from app import machines as routing from app import payments, proof from app.core import db from tests.smoke_test import BASE, Client, with_host @@ -61,34 +59,7 @@ def pickup_photo(client, oid, content): return uid -def expected_machine(su, product, metres=1.0): - """What app/machines.py should pick now: the active machine of the product - with the fewest metres open, among those with room, else among all.""" - # Listed in the order they were registered: min() keeps the first of equals, as the routing does. - rows = [m for m in su.call('/operator/machines', operator=True)['machines'] if m['active'] and product in m['products']] - room = [m for m in rows if m['limit_metres'] is None or m['open_metres'] + metres <= m['limit_metres']] - return min(room or rows, key=lambda m: m['open_metres'])['id'] - - -def picking(): - """The choice itself: room first, then the fewest metres, then the first registered.""" - textil = {'snapshot': {'items': [{'mode': 'file', 'billed_metres': '1'}]}} - uv = {'snapshot': {'items': [{'mode': 'uvfile', 'billed_metres': '1'}]}} - a = {'id': 'a', 'products': ['textil'], 'active': True, 'limit_metres': Decimal('2')} - b = {'id': 'b', 'products': ['textil'], 'active': True, 'limit_metres': None} - off = {'id': 'off', 'products': ['textil'], 'active': False, 'limit_metres': None} - assert routing.pick([a, b], {}, textil)['id'] == 'a' - assert routing.pick([off, a, b], {'a': Decimal('0.5')}, textil)['id'] == 'b' - # Full: the one with room takes it, even with more metres open. - assert routing.pick([a, b], {'a': Decimal('1.5'), 'b': Decimal('9')}, textil)['id'] == 'b' - # All full: the least loaded anyway. - b_full = {**b, 'limit_metres': Decimal('3')} - assert routing.pick([a, b_full], {'a': Decimal('5'), 'b': Decimal('4')}, textil)['id'] == 'b' - assert routing.pick([a, b], {}, uv) is None - - def run(): - picking() tag = secrets.token_hex(3) su = Client() su.call('/session') @@ -131,19 +102,22 @@ def run(): expected=409) admin.call(f"/operator/users/{mine['id']}/delete", {}, expected=409) - # Orders other suites left open get their machines first; then each paid - # order goes to the machine of its product with the fewest metres open. + # No machine at payment: a card waits for a person to choose one or to + # pull it into Imprimindo (Dropstar, 2026-11-05). su.call('/operator/board', operator=True) - want = {'textil': expected_machine(su, 'textil'), 'uv': expected_machine(su, 'uv')} with db.connect() as c: textil_q, textil_o = order_fixture(c, owner, 'file') uv_q, uv_o = order_fixture(c, owner, 'uvfile') made += [(textil_q, textil_o), (uv_q, uv_o)] board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} - assert board[str(textil_o)]['machine']['id'] == want['textil'] and not board[str(textil_o)]['machine']['chosen'] - assert board[str(uv_o)]['machine']['id'] == want['uv'] and not board[str(uv_o)]['machine']['chosen'] - # On the UV machine of this test, whatever the others carry. + assert board[str(uv_o)]['machine'] is None and not board[str(textil_o)]['machine_chosen'] + assert board[str(uv_o)]['machine'] is None and not board[str(uv_o)]['machine_chosen'] + # Chosen before printing, each one stays there. + su.call(f'/operator/orders/{textil_o}/machine', {'machine_id': textil}, operator=True) su.call(f'/operator/orders/{uv_o}/machine', {'machine_id': uv}, operator=True) + board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} + assert board[str(textil_o)]['machine']['id'] == textil and board[str(textil_o)]['machine']['chosen'] + assert board[str(uv_o)]['machine']['id'] == uv and board[str(uv_o)]['machine']['chosen'] # The operator prints: Arte conferida to Imprimindo to Revisão, nothing # else (Dropstar, 2026-10-23). After signing in they say which machine @@ -338,36 +312,36 @@ def run(): listed = {m['id']: m for m in admin.call('/operator/machines')['machines']} assert listed[textil2]['operators'] == [] and [o['id'] for o in listed[uv]['operators']] == [op_id], listed[uv] assert next(u for u in admin.call('/operator/users')['users'] if u['id'] == op_id)['machines'] == [uv] - # The next order goes to the one with fewer metres open. - target = expected_machine(su, 'textil') + # A paid order starts with no machine; choosing one by hand is the + # only way it gets one before a pull (Dropstar, 2026-11-05). with db.connect() as c: made.append(order_fixture(c, owner, 'file')) second = str(made[-1][1]) board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} - assert board[second]['machine']['id'] == target - # Chosen by hand, the order stays there; back to automatic, it is routed again. + assert board[second]['machine'] is None and not board[second]['machine_chosen'] su.call(f'/operator/orders/{second}/machine', {'machine_id': textil2}, operator=True) + board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} + assert board[second]['machine']['id'] == textil2 and board[second]['machine']['chosen'] listed = {m['id']: m for m in su.call('/operator/machines', operator=True)['machines']} assert listed[textil2]['open_orders'] >= 1 and listed[textil2]['states'].get('rec', 0) >= 1 - # A limit: once full, the next order goes to a machine with room. + # The limit is shown on the machine; it no longer routes new orders. open_now = listed[textil2]['open_metres'] admin.call(f'/operator/machines/{textil2}', {'name': f'Têxtil B {tag}', 'products': ['textil'], 'limit_metres': round(open_now + 0.5, 1)}) listed = {m['id']: m for m in su.call('/operator/machines', operator=True)['machines']} assert listed[textil2]['limit_metres'] == round(open_now + 0.5, 1) - target = expected_machine(su, 'textil') - assert target != textil2 with db.connect() as c: made.append(order_fixture(c, owner, 'file')) third = str(made[-1][1]) board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} - assert board[third]['machine']['id'] == target + assert board[third]['machine'] is None and not board[third]['machine_chosen'] + su.call(f'/operator/orders/{third}/machine', {'machine_id': textil}, operator=True) admin.call(f'/operator/machines/{textil2}', {'name': f'Têxtil B {tag}', 'products': ['textil'], 'limit_metres': 0}, expected=422) su.call(f'/operator/orders/{second}/machine', {'machine_id': None}, operator=True) board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} - assert not board[second]['machine']['chosen'] + assert not board[second]['machine_chosen'] # Números per machine: an order printed for half an hour on its machine, then # finished. It counts the film printed (0,40 m), not the metre billed. @@ -381,10 +355,10 @@ def run(): c.execute(f'''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back,created_at) VALUES(%s,%s,%s,'users-test','',false,{at})''', (third, frm, to)) after = {m['id']: m for m in su.call('/operator/stats?days=7', operator=True)['machines']} - assert after[target]['orders'] == before[target]['orders'] + 1 - assert round(after[target]['metres'] - before[target]['metres'], 2) == 0.4, (before[target], after[target]) - assert after[target]['last_finished'] and after[target]['metres_per_hour'] is not None - assert after[target]['printing_hours'] >= before[target]['printing_hours'] + 0.49 + assert after[textil]['orders'] == before[textil]['orders'] + 1 + assert round(after[textil]['metres'] - before[textil]['metres'], 2) == 0.4, (before[textil], after[textil]) + assert after[textil]['last_finished'] and after[textil]['metres_per_hour'] is not None + assert after[textil]['printing_hours'] >= before[textil]['printing_hours'] + 0.49 # Two orders printing at once on one machine: the half hour they share counts # once, so the machine did 1,50 m in 0,5 h, not in 1 h. with db.connect() as c: @@ -494,12 +468,13 @@ def run(): assert {o['name'] for o in on_free} == {'Op', 'Marcus'}, on_free designer.call('/operator/me/machine', {'machine_id': free}, expected=403) - # Switched off, a machine gives its automatic orders to another one. + # Switching a machine off no longer re-routes the cards: a person + # chooses another machine (Dropstar, 2026-11-05). with db.connect() as c: c.execute('UPDATE dtf_local.orders SET machine_id=%s, machine_chosen=false WHERE id=%s', (textil2, second)) admin.call(f'/operator/machines/{textil2}', {'name': f'Têxtil B {tag}', 'products': ['textil'], 'active': False}) board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} - assert board[second]['machine']['id'] not in (None, textil2) + assert board[second]['machine']['id'] == textil2 # Disabled, the operator is out at once; deleted, the account is gone. op_row = users[emails['operador']] @@ -508,12 +483,11 @@ def run(): op.call('/operator/board', expected=401) admin.call(f"/operator/users/{op_row['id']}/delete", {}) assert emails['operador'] not in {u['email'] for u in admin.call('/operator/users')['users']} - # A deleted machine sends its orders back to the automatic choice. + # A deleted machine leaves its cards without a machine; a person picks one. su.call(f'/operator/machines/{uv}/delete', {}, operator=True) machines.remove(uv) board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']} - back = board[str(textil_o)]['machine'] - assert back and back['id'] != uv and not back['chosen'] + assert board[str(uv_o)]['machine'] is None # Rework (D-02 to D-04): Gestão opens it with its cause, an Administrador # authorizes it, never their own, and only then it counts in Números. emails['gestao'] = f'gestao-{tag}@example.test' diff --git a/tests/workflow_test.py b/tests/workflow_test.py index 30fbee1..59e4a03 100644 --- a/tests/workflow_test.py +++ b/tests/workflow_test.py @@ -50,8 +50,16 @@ def run(): assert other.call('/customer/orders/'+oid)['id']==oid print('PASS: registration claims only current guest records, cross-session account login, revoked sessions, owner UUID is not a credential') + machine = None def move(state,version): - return customer.call('/operator/orders/'+oid+'/move',{'state':state,'version':version,'reason':'Please replace the artwork' if state=='cor' else ''},operator=True)['version'] + nonlocal machine + body={'state':state,'version':version,'reason':'Please replace the artwork' if state=='cor' else ''} + if state=='imp': + if machine is None: + machine=customer.call('/operator/machines',{'name':'Workflow '+uuid4().hex[:6], + 'products':['textil']},operator=True)['id'] + body['machine_id']=machine + return customer.call('/operator/orders/'+oid+'/move',body,operator=True)['version'] # Arte conferida is the print queue (2026-10-23): it takes approved finals only. version=0 customer.call('/operator/orders/'+oid+'/move',{'state':'tra','version':version},operator=True,expected=409) @@ -73,7 +81,7 @@ def run(): version=move('tra',version) # The print queue's files come named after their order, straight from storage. queued=customer.call('/operator/queue/finals',operator=True)['files'] - mine=[f for f in queued if urlopen(f['url']).read()==final_one] + mine=[f for f in queued if f['order']==oid and urlopen(f['url']).read()==final_one] assert len(mine)==1 and mine[0]['name'].startswith('DTF-%d-item-1-' % mine[0]['number']), queued customer.call('/operator/queue/finals',expected=401) version=move('imp',version);version=move('cor',version)