Some checks failed
Build and deploy / Validate source (push) Successful in 1m41s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
#81's 91,5 m took 6 hours to generate. The PNG writer ran Pillow's row filters and then deflate at level 6; no filter at level 1 gives the same size in under half the time, for the file and the viewer's strips alike (1 m: 34 s -> 13 s). Its Prova OK came while the file was still being generated, so the order stayed in Arte recebida. The approval now also runs when the file finishes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
522 lines
33 KiB
Python
522 lines
33 KiB
Python
"""Print files and payment issues, against a running stack.
|
|
|
|
A paid order must get a print file generated from its approved layout, which
|
|
the operator can download and approve as the final file without re-uploading
|
|
anything. Artwork the generator cannot read goes to hand preparation with a
|
|
reason, and a paid notification that did not become an order stays on the
|
|
Kanban until someone records what was done.
|
|
|
|
Run inside the API container (it needs Pillow): python -m tests.print_file_test
|
|
"""
|
|
import io
|
|
from decimal import Decimal
|
|
import time
|
|
from urllib.request import urlopen
|
|
from uuid import uuid4
|
|
|
|
from PIL import Image
|
|
|
|
from app.core import db
|
|
from tests.payment_test import deliver
|
|
from tests.smoke_test import Client, approved_quote as approval, upload_bytes
|
|
|
|
PX_PER_CM = 300 / 2.54
|
|
|
|
|
|
def px(cm):
|
|
return int(round(cm * PX_PER_CM))
|
|
|
|
|
|
def download_png(client, upload_id):
|
|
link = client.call('/operator/uploads/' + str(upload_id) + '/download', operator=True)
|
|
with urlopen(link['url'], timeout=30) as response:
|
|
image = Image.open(io.BytesIO(response.read()))
|
|
assert image.format == 'PNG' and image.mode == 'RGBA', (image.format, image.mode)
|
|
return image
|
|
CUSTOMER = {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': 'print-test@example.test'}
|
|
|
|
|
|
def artwork(kind='PNG'):
|
|
image = Image.new('RGBA', (1600, 800), (0, 0, 0, 0))
|
|
for x in range(40, 1560):
|
|
for y in range(40, 760):
|
|
image.putpixel((x, y), (220, 30, 60, 255))
|
|
out = io.BytesIO()
|
|
if kind == 'PDF':
|
|
image.convert('RGB').save(out, 'PDF', resolution=72)
|
|
else:
|
|
image.save(out, kind, dpi=(300, 300))
|
|
return out.getvalue()
|
|
|
|
|
|
def loose_item(uid, copies=2):
|
|
"""Two copies of a 20 x 10 cm artwork side by side on 57 cm film."""
|
|
placements = [{'source_index': 0, 'copy_index': i, 'x_cm': 20 * i, 'y_cm': 0,
|
|
'width_cm': 20, 'length_cm': 10, 'rotation_degrees': 0, 'mirrored': False}
|
|
for i in range(copies)]
|
|
return {'mode': 'avulsa', 'metres': '0.1', 'grade': 90, 'uploads': [uid],
|
|
'production': {'version': 2, 'film_width_cm': 57, 'height_cm': 10,
|
|
'sources': [{'upload_id': uid, 'kind': 'artwork', 'width_cm': 20,
|
|
'length_cm': 10, 'copies': copies, 'rotation_degrees': 0,
|
|
'mirrored': False, 'measurement': 'file'}],
|
|
'placements': placements},
|
|
'quality_status': 'ok', 'quality_acknowledged': False}
|
|
|
|
|
|
def approved_quote(client, item):
|
|
quote = client.call('/quotes', {'request_key': str(uuid4()), 'customer': CUSTOMER,
|
|
'items': [item], 'freight': {'service': 'pickup'}})
|
|
approved = approval(client, quote, [item])
|
|
return quote['id'], approved['total_cents']
|
|
|
|
|
|
def paid_order(client, item):
|
|
quote_id, _ = approved_quote(client, item)
|
|
return client.call('/orders/dev-paid', {'quote_id': quote_id})
|
|
|
|
|
|
def wait_print(client, oid, wanted):
|
|
deadline = time.monotonic() + 90
|
|
while time.monotonic() < deadline:
|
|
order = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == oid)
|
|
rows = order['print_files']
|
|
if rows and rows[0]['status'] in ('ready', 'manual', 'failed'):
|
|
assert rows[0]['status'] == wanted, rows
|
|
return order, rows[0]
|
|
time.sleep(1)
|
|
raise AssertionError('Print file was not generated in time')
|
|
|
|
|
|
def run():
|
|
client = Client()
|
|
client.call('/session')
|
|
|
|
uid = upload_bytes(client, artwork(), name='LOCAL-PRINT-TEST.png')
|
|
order = paid_order(client, loose_item(uid))
|
|
order, row = wait_print(client, order['id'], 'ready')
|
|
assert row['detail']['placements'] == 2 and row['detail']['min_dpi'] == round(1600 / (20 / 2.54))
|
|
assert any('Prumo levou' in line for line in order['prumo']), order['prumo']
|
|
# A 300 DPI PNG on a transparent background (item 13): the layout's 10 cm
|
|
# and the 1,5 cm footer band, outside the billed length.
|
|
film = download_png(client, row['upload_id'])
|
|
assert film.size == (px(57), px(10) + px(1.5)), film.size
|
|
assert [p['name'] for p in row['parts']] == ['DTF-%d-item-1.png' % order['number']], row['parts']
|
|
for copy in range(2):
|
|
assert film.getpixel((px(20 * copy + 10), px(5))) == (220, 30, 60, 255), copy
|
|
assert film.getpixel((px(50), px(5)))[3] == 0
|
|
assert row['detail']['footer'].startswith('DROPSTAR · Pedido DTF-%d · Item 1/1 · ' % order['number']), row['detail']
|
|
print('PASS: paid order generated a 57 x 10 cm PNG print file with both copies and its footer')
|
|
|
|
# A ready sheet with its empty strips cut (Marcus, 2026-11-18): the cart
|
|
# sends what the Site cut from the top and bottom of a 27 x 30 cm UV sheet
|
|
# with 20 cm of art in the middle, as web/site-upload.js aplicaCorte does.
|
|
# The order bills and prints the 21 cm left, the art whole.
|
|
# At 300 DPI, so neither the Site nor the server asks for a resolution note.
|
|
sheet = Image.new('RGBA', (px(27), px(30)))
|
|
sheet.paste(Image.new('RGBA', (px(23), px(20)), (30, 60, 200, 255)), (px(2), px(5)))
|
|
buffer = io.BytesIO()
|
|
sheet.save(buffer, 'PNG', dpi=(300, 300))
|
|
sheet_upload = upload_bytes(client, buffer.getvalue(), name='LOCAL-TRIMMED-SHEET.png')
|
|
trimmed = {'mode': 'uvfile', 'metres': '0.21', 'grade': 90, 'uploads': [sheet_upload],
|
|
'production': {'version': 3, 'film_width_cm': 27, 'height_cm': 21,
|
|
'sources': [{'upload_id': sheet_upload, 'kind': 'sheet', 'width_cm': 27,
|
|
'length_cm': 21, 'copies': 1, 'rotation_degrees': 0, 'mirrored': False,
|
|
'measurement': 'file', 'trim_top_cm': 4.5, 'trim_bottom_cm': 4.5}],
|
|
'placements': [{'source_index': 0, 'copy_index': 0, 'x_cm': 0, 'y_cm': 0,
|
|
'width_cm': 27, 'length_cm': 21, 'rotation_degrees': 0,
|
|
'mirrored': False}]},
|
|
'quality_status': 'ok', 'quality_acknowledged': False}
|
|
sheet_order, sheet_row = wait_print(client, paid_order(client, trimmed)['id'], 'ready')
|
|
assert any(line.endswith('Faixas vazias cortadas: 9,0 cm') for line in sheet_order['prumo']), sheet_order['prumo']
|
|
assert Decimal(sheet_order['snapshot']['items'][0]['billed_metres']) == 1, sheet_order['snapshot']['items'][0]
|
|
trimmed_film = download_png(client, sheet_row['upload_id'])
|
|
assert trimmed_film.size == (px(27), px(21) + px(1.5)), trimmed_film.size
|
|
# 0,5 cm of margin above and below the art, which fills the rest.
|
|
assert trimmed_film.getpixel((px(13), px(0.2)))[3] == 0 and trimmed_film.getpixel((px(13), px(20.8)))[3] == 0
|
|
assert trimmed_film.getpixel((px(13), px(1))) == (30, 60, 200, 255)
|
|
assert trimmed_film.getpixel((px(13), px(20))) == (30, 60, 200, 255)
|
|
print('PASS: a ready sheet with its empty strips cut bills and prints only what is left')
|
|
|
|
# Item 7: "Abrir e conferir" gets the file in pieces, the first of which is
|
|
# the top of the film, then the original.
|
|
view = client.call('/operator/orders/' + order['id'] + '/view', operator=True)['files']
|
|
assert [f['name'] for f in view] == ['DTF-%d-item-1.png' % order['number'], 'Original'], view
|
|
manifest = view[0]['manifest']
|
|
assert (manifest['width'], manifest['height']) == film.size and manifest['levels'][0]['strips'] >= 1, manifest
|
|
with urlopen(manifest['urls'][0][0], timeout=30) as response:
|
|
strip = Image.open(io.BytesIO(response.read()))
|
|
assert strip.width == film.width and strip.getpixel((px(10), px(3))) == (220, 30, 60, 255)
|
|
print('PASS: the viewer gets the print file in pieces')
|
|
|
|
# The automatic folder, downloading on arrival, gets the generated file
|
|
# before anyone approves it; at the queue only, it does not.
|
|
oid = order['id']
|
|
early = client.call('/operator/queue/folder', {'early': True, 'held': [oid]}, operator=True)
|
|
mine = [f for f in early['files'] if f['order'] == oid]
|
|
assert [(f['upload_id'], f['state']) for f in mine] == [(str(row['upload_id']), 'rec')], early['files']
|
|
assert mine[0]['name'].startswith('DTF-%d-item-1' % order['number']) and early['states'] == {oid: 'rec'}
|
|
late = client.call('/operator/queue/folder', {'early': False, 'held': []}, operator=True)
|
|
assert not [f for f in late['files'] if f['order'] == oid] and late['states'] == {}
|
|
client.call('/operator/queue/folder', {'early': True, 'held': []}, expected=401)
|
|
print('PASS: the folder gets a received order\'s generated file early, and only at the queue otherwise')
|
|
|
|
# The operator approves the generated file as the final one, with no upload,
|
|
# and the order can then enter the print queue.
|
|
result = client.call('/operator/orders/' + oid + '/final-files',
|
|
{'version': order['version'], 'files': [{'item_index': 0, 'upload_id': str(row['upload_id'])}],
|
|
'note': 'Generated print file checked'}, operator=True)
|
|
version = result['version']
|
|
# The file the system generated from the customer's art is not "Arte tratada".
|
|
board = client.call('/operator/board', operator=True)['orders']
|
|
assert next(o for o in board if o['id'] == oid)['treated'] is None
|
|
# Arte conferida is the print queue (2026-10-23).
|
|
client.call('/operator/orders/' + oid + '/move', {'state': 'tra', 'version': version}, operator=True)
|
|
version += 1
|
|
# Printing, the folders still get the file of an order they hold (to take
|
|
# it to Finalizado later), and no one else's. The pull chooses the machine.
|
|
tag = uuid4().hex[:6]
|
|
machine = client.call('/operator/machines', {'name': f'Hot {tag}', 'products': ['textil']},
|
|
operator=True)['id']
|
|
client.call('/operator/orders/' + oid + '/move', {'state': 'imp', 'version': version,
|
|
'machine_id': machine}, operator=True)
|
|
version += 1
|
|
held = client.call('/operator/queue/folder', {'early': True, 'held': [oid]}, operator=True)
|
|
assert [(f['state'], f['upload_id']) for f in held['files'] if f['order'] == oid] == [('imp', str(row['upload_id']))], held
|
|
assert held['states'] == {oid: 'imp'}
|
|
others = client.call('/operator/queue/folder', {'early': True, 'held': []}, operator=True)
|
|
assert not [f for f in others['files'] if f['order'] == oid], others['files']
|
|
# A folder chosen before this order was paid catches up on it, printing or
|
|
# not, as a computer that was off does when it comes back; one chosen
|
|
# after it does not.
|
|
earlier = client.call('/operator/queue/folder', {'early': True, 'held': [], 'since': '2000-01-01T00:00:00Z'},
|
|
operator=True)
|
|
assert [(f['state'], f['upload_id']) for f in earlier['files'] if f['order'] == oid] == [('imp', str(row['upload_id']))]
|
|
later = client.call('/operator/queue/folder', {'early': True, 'held': [], 'since': '2999-01-01T00:00:00Z'},
|
|
operator=True)
|
|
assert not [f for f in later['files'] if f['order'] == oid], later['files']
|
|
# Once queued for printing, the final set can no longer change.
|
|
client.call('/operator/orders/' + oid + '/final-files',
|
|
{'version': version, 'files': [{'item_index': 0, 'upload_id': str(row['upload_id'])}],
|
|
'note': 'again'}, operator=True, expected=409)
|
|
print('PASS: generated file approved as final without re-uploading; order queued for printing')
|
|
|
|
# A ready file generated again for the part size of now (order #36,
|
|
# 2026-11-17): from Arte conferida or Imprimindo the generated final goes,
|
|
# the order is back in Arte recebida and the file is made once more.
|
|
again_upload = upload_bytes(client, artwork(), name='LOCAL-AGAIN.png')
|
|
again, made = wait_print(client, paid_order(client, loose_item(again_upload))['id'], 'ready')
|
|
v = client.call('/operator/orders/' + again['id'] + '/final-files',
|
|
{'version': again['version'], 'files': [{'item_index': 0, 'upload_id': str(made['upload_id'])}],
|
|
'note': 'ok'}, operator=True)['version']
|
|
client.call('/operator/orders/' + again['id'] + '/move', {'state': 'tra', 'version': v}, operator=True)
|
|
client.call('/operator/orders/' + again['id'] + '/print-files/again', {}, operator=True)
|
|
with db.connect() as c:
|
|
state = c.execute('SELECT state FROM dtf_local.orders WHERE id=%s', (again['id'],)).fetchone()['state']
|
|
finals = c.execute('''SELECT count(*) AS n FROM dtf_local.order_files
|
|
WHERE order_id=%s AND kind='final' AND active''', (again['id'],)).fetchone()['n']
|
|
back = c.execute('SELECT reason,back FROM dtf_local.movements WHERE order_id=%s ORDER BY id DESC LIMIT 1',
|
|
(again['id'],)).fetchone()
|
|
assert (state, finals, back['reason'], back['back']) == ('rec', 0, 'Arquivo gerado de novo', True), (state, finals, back)
|
|
again, remade = wait_print(client, again['id'], 'ready')
|
|
assert str(remade['upload_id']) != str(made['upload_id']), (made, remade)
|
|
print('PASS: a ready file is generated again from Arte conferida, back in Arte recebida to approve')
|
|
|
|
# The generated file approved, sent to Correção (its final stops counting)
|
|
# and back: the same file is approved again, not refused as already in
|
|
# the order (Sentry DTF-WEB-10).
|
|
redo, redo_row = wait_print(client, paid_order(client, loose_item(upload_bytes(client, artwork(), name='LOCAL-REDO.png')))['id'], 'ready')
|
|
finals = [{'item_index': 0, 'upload_id': str(redo_row['upload_id'])}]
|
|
v = client.call('/operator/orders/' + redo['id'] + '/final-files',
|
|
{'version': redo['version'], 'files': finals, 'note': 'ok'}, operator=True)['version']
|
|
def version_of(oid):
|
|
with db.connect() as c:
|
|
return c.execute('SELECT version FROM dtf_local.orders WHERE id=%s', (oid,)).fetchone()['version']
|
|
client.call('/operator/orders/' + redo['id'] + '/move', {'state': 'cor', 'version': v, 'reason': 'Teste'}, operator=True)
|
|
client.call('/operator/orders/' + redo['id'] + '/move', {'state': 'rec', 'version': version_of(redo['id']),
|
|
'reason': 'Teste'}, operator=True)
|
|
client.call('/operator/orders/' + redo['id'] + '/final-files',
|
|
{'version': version_of(redo['id']), 'files': finals, 'note': 'de novo'}, operator=True)
|
|
with db.connect() as c:
|
|
rows = c.execute('''SELECT active FROM dtf_local.order_files WHERE order_id=%s AND kind='final' ''',
|
|
(redo['id'],)).fetchall()
|
|
assert [r['active'] for r in rows] == [True], rows
|
|
print('PASS: a generated final that stopped counting is approved again')
|
|
|
|
# Item 10: printing, the file goes once into its machine's hot folder for
|
|
# its class; Flexi taking it is reported; leaving Imprimindo withdraws
|
|
# what Flexi did not take.
|
|
try:
|
|
# No class measured or chosen: the part waits for one.
|
|
assert not [p for p in client.call('/operator/queue/hot', {}, operator=True)['write'] if p['order'] == oid]
|
|
client.call('/operator/orders/' + oid + '/contraction', {'item_index': 0, 'value': 'C2'}, operator=True)
|
|
hot = client.call('/operator/queue/hot', {}, operator=True)
|
|
due = [p for p in hot['write'] if p['order'] == oid]
|
|
assert hot['folder'] == '3. Imprimindo' and [(p['folder'], p['name']) for p in due] == \
|
|
[(f'Hot {tag}/C2', 'DTF-%d-item-1.png' % order['number'])], hot
|
|
# Claimed by this computer only: asked again, nobody else gets it.
|
|
assert not [p for p in client.call('/operator/queue/hot', {}, operator=True)['write'] if p['order'] == oid]
|
|
part = due[0]['id']
|
|
assert client.call(f'/operator/queue/hot/{part}', {'state': 'written'}, operator=True)['ok']
|
|
client.call('/operator/orders/' + oid + '/contraction', {'item_index': 0, 'value': 'C1'}, operator=True,
|
|
expected=409)
|
|
watch = client.call('/operator/queue/hot', {}, operator=True)['watch']
|
|
assert [p['id'] for p in watch if p['order'] == oid] == [part], watch
|
|
assert client.call(f'/operator/queue/hot/{part}', {'state': 'consumed'}, operator=True)['ok']
|
|
assert not client.call(f'/operator/queue/hot/{part}', {'state': 'consumed'}, operator=True)['ok']
|
|
board = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == oid)
|
|
assert board['hot'] == {'parts': 1, 'taken': 1, 'waiting': 0}, board['hot']
|
|
print('PASS: the printing file goes once into its machine\'s hot folder for its class')
|
|
finally:
|
|
client.call('/operator/machines/' + machine, {'name': f'Hot {tag}', 'products': ['textil'], 'active': False},
|
|
operator=True)
|
|
|
|
# A single-page PDF is drawn from its vectors at 300 DPI.
|
|
pdf_upload = upload_bytes(client, artwork('PDF'), name='LOCAL-PRINT-TEST.pdf')
|
|
pdf_order = paid_order(client, loose_item(pdf_upload))
|
|
_, pdf_row = wait_print(client, pdf_order['id'], 'ready')
|
|
assert pdf_row['detail']['vector_sources'] == 1 and pdf_row['detail']['min_dpi'] is None, pdf_row
|
|
drawn = download_png(client, pdf_row['upload_id'])
|
|
red = drawn.getpixel((px(10), px(5)))
|
|
assert red[3] == 255 and red[0] > 200 and red[1] < 60, red
|
|
print('PASS: PDF artwork drawn into the PNG print file at 300 DPI')
|
|
|
|
# Before approving, the panel asks whether the files can be finals: the
|
|
# generated PNG can, the customer's PDF original cannot, and the answer
|
|
# says why without a refusal (Sentry DTF-WEB-11). Another order's file is
|
|
# not read.
|
|
check = client.call('/operator/orders/' + pdf_order['id'] + '/final-check',
|
|
{'uploads': [str(pdf_row['upload_id']), pdf_upload, str(row['upload_id'])]}, operator=True)
|
|
assert [p['upload_id'] for p in check['problems']] == [pdf_upload], check
|
|
assert '300 DPI' in check['problems'][0]['message'], check
|
|
print('PASS: the panel learns before approving that a file cannot be a final')
|
|
|
|
# The proof card (Dropstar, 2026-10-30 and 2026-11-03): an order above
|
|
# 10 m gets a child card "Prova"; the order waits outside the queue until
|
|
# the card in Revisão gets its answer.
|
|
# Artwork the generator refuses at once, so no 10 m file is drawn.
|
|
unread = upload_bytes(client, b'LOCAL PRINT TEST - NOT AN IMAGE', name='LOCAL-PROOF-TEST.cdr')
|
|
long = loose_item(unread, copies=1)
|
|
long['metres'] = '10.5'
|
|
long['proof_y_fraction'] = '0.8'
|
|
long['production'] = {**long['production'], 'height_cm': 1050,
|
|
'placements': [{**long['production']['placements'][0], 'y_cm': 1040}]}
|
|
parent = paid_order(client, long)
|
|
board = client.call('/operator/board', operator=True)['orders']
|
|
mine = next(o for o in board if o['id'] == parent['id'])
|
|
card = next(o for o in board if o['id'] == mine['proof_card']['id'])
|
|
assert card['proof_parent']['number'] == parent['number'] and card['state'] == 'rec', card
|
|
assert card['snapshot']['proof_of'] == parent['number'] and card['payment'] == {'provider': 'prova'}
|
|
assert float(card['snapshot']['items'][0]['proof_y_fraction']) == 0.8, card['snapshot']['items'][0]
|
|
# The proof answer is the customer contact: the old "Aguardando contato"
|
|
# mark must not survive it (item 0.1).
|
|
with db.connect() as c:
|
|
c.execute("""UPDATE dtf_local.orders SET contact_since=now(), contact_by='Site',
|
|
contact_note='Prova pedida no site' WHERE id=%s""", (parent['id'],))
|
|
c.execute('INSERT INTO dtf_local.contact_waits(order_id,started_at) VALUES(%s,now())', (parent['id'],))
|
|
with db.connect() as c:
|
|
assert not c.execute('SELECT 1 FROM dtf_local.outbox WHERE event_key LIKE %s', (card['id'] + '%',)).fetchone()
|
|
c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s", (card['id'],))
|
|
final = str(uuid4())
|
|
held = client.call('/operator/orders/' + parent['id'] + '/final-files',
|
|
{'version': parent['version'], 'files': [{'item_index': 0, 'upload_id': final}],
|
|
'note': 'Local proof test final'}, operator=True, expected=409)
|
|
assert 'Aguardando prova' in held['detail'], held
|
|
for path, body in [('/move', {'state': 'tra', 'version': parent['version']}),
|
|
('/contraction', {'item_index': 0, 'value': 'C1'}),
|
|
('/machine', {'machine_id': None}),
|
|
('/queue', {'after': card['id']})]:
|
|
held = client.call('/operator/orders/' + parent['id'] + path, body, operator=True, expected=409)
|
|
assert 'Aguardando prova' in held['detail'], (path, held)
|
|
client.call('/operator/orders/' + card['id'] + '/move', {'state': 'fin', 'version': card['version']},
|
|
operator=True, expected=409)
|
|
# Reprovada needs its reason; the order goes back to Arte recebida.
|
|
client.call('/operator/orders/' + card['id'] + '/proof-answer', {'result': 'rejected', 'reason': 'x'},
|
|
operator=True, expected=422)
|
|
client.call('/operator/orders/' + card['id'] + '/proof-answer',
|
|
{'result': 'rejected', 'reason': 'Cor do fundo errada'}, operator=True)
|
|
client.call('/operator/orders/' + card['id'] + '/proof-answer', {'result': 'ok'}, operator=True, expected=409)
|
|
board = client.call('/operator/board', operator=True)['orders']
|
|
mine = next(o for o in board if o['id'] == parent['id'])
|
|
assert mine['state'] == 'rec' and mine['proof_card']['proof_result'] == 'rejected', mine['proof_card']
|
|
assert mine['proof_card']['proof_reason'] == 'Cor do fundo errada'
|
|
assert not mine.get('contact_since'), mine
|
|
with db.connect() as c:
|
|
assert c.execute('SELECT ended_at FROM dtf_local.contact_waits WHERE order_id=%s',
|
|
(parent['id'],)).fetchone()['ended_at']
|
|
assert not [o for o in board if o['id'] == card['id']], 'an answered proof card leaves the board'
|
|
# Rejection releases the parent for corrected artwork, until a new proof card is opened.
|
|
final = upload_bytes(client, artwork(), name='LOCAL-PROOF-FINAL.png', order_id=parent['id'])
|
|
version = client.call('/operator/orders/' + parent['id'] + '/final-files',
|
|
{'version': mine['version'], 'files': [{'item_index': 0, 'upload_id': final}],
|
|
'note': 'Local proof test final'}, operator=True)['version']
|
|
# A new card, and Prova OK lets the order into the queue.
|
|
again = client.call('/operator/orders/' + parent['id'] + '/proof-card', {}, operator=True)
|
|
client.call('/operator/orders/' + parent['id'] + '/proof-card', {}, operator=True, expected=409)
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s", (again['id'],))
|
|
client.call('/operator/orders/' + again['id'] + '/proof-answer', {'result': 'ok'}, operator=True)
|
|
mine = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == parent['id'])
|
|
assert mine['proof_ok_at'] and mine['proof_card']['proof_result'] == 'ok' and mine['state'] == 'tra', mine
|
|
print('PASS: an order with a proof waits for its proof card, which is answered OK or rejected in Revisão')
|
|
|
|
# Prova OK is the parent's check: the full print file Prumo already made
|
|
# becomes the parent final and the parent enters Arte conferida (0.1).
|
|
readable = upload_bytes(client, artwork(), name='LOCAL-PROOF-REAL.png')
|
|
long = loose_item(readable, copies=1)
|
|
parent = paid_order(client, long)
|
|
# A proof card for a small order, as the panel can open one; the parent
|
|
# file is only 10 cm tall, so this test does not draw a 10 m film.
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.orders SET snapshot=jsonb_set(snapshot,'{proof}','true') WHERE id=%s",
|
|
(parent['id'],))
|
|
client.call('/operator/orders/' + parent['id'] + '/proof-card', {}, operator=True)
|
|
board = client.call('/operator/board', operator=True)['orders']
|
|
mine = next(o for o in board if o['id'] == parent['id'])
|
|
card = next(o for o in board if o['id'] == mine['proof_card']['id'])
|
|
wait_print(client, parent['id'], 'ready')
|
|
wait_print(client, card['id'], 'ready')
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s", (card['id'],))
|
|
# The proof's photo, taken in Revisão, stays reachable from its order once
|
|
# the answered card leaves the board (the proof of #30, 2026-11-17).
|
|
with db.connect() as c:
|
|
c.execute('''INSERT INTO dtf_local.order_reviews(order_id,seq,upload_id,kind,width,height,created_by)
|
|
VALUES(%s,1,%s,'photo',1600,1200,'Revisor')''', (card['id'], readable))
|
|
client.call('/operator/orders/' + card['id'] + '/proof-answer', {'result': 'ok'}, operator=True)
|
|
mine = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == parent['id'])
|
|
assert [r['kind'] for r in mine['proof_card']['reviews']] == ['photo'], mine['proof_card']
|
|
view = client.call('/operator/orders/' + card['id'] + '/reviews/' + str(mine['proof_card']['reviews'][0]['id'])
|
|
+ '/view', operator=True)
|
|
assert view['url'] and view['kind'] == 'photo', view
|
|
assert mine['state'] == 'tra' and mine['final_items'] == [0], mine
|
|
assert mine['proof_ok_at'] and mine['proof_card']['proof_result'] == 'ok', mine
|
|
with db.connect() as c:
|
|
final = c.execute('''SELECT note,created_by FROM dtf_local.order_files
|
|
WHERE order_id=%s AND kind='final' AND active''', (parent['id'],)).fetchone()
|
|
assert final['created_by'] == 'Prumo' and 'prova' in final['note'].lower(), final
|
|
print('PASS: Prova OK turns Prumo\'s full file into the parent final and queues it')
|
|
|
|
# Prova OK while the parent's file is still being generated (#81, 91,5 m,
|
|
# 2026-11-24): the parent waits in Arte recebida and enters the queue on
|
|
# its own once the file is ready.
|
|
readable = upload_bytes(client, artwork(), name='LOCAL-PROOF-LATE.png')
|
|
parent = paid_order(client, loose_item(readable, copies=1))
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.orders SET snapshot=jsonb_set(snapshot,'{proof}','true') WHERE id=%s",
|
|
(parent['id'],))
|
|
card = client.call('/operator/orders/' + parent['id'] + '/proof-card', {}, operator=True)
|
|
wait_print(client, parent['id'], 'ready')
|
|
wait_print(client, card['id'], 'ready')
|
|
with db.connect() as c:
|
|
# The parent's file back to "being generated", held by a claim no worker owns.
|
|
c.execute('''UPDATE dtf_local.print_files SET status='rendering', upload_id=NULL, finished_at=NULL,
|
|
claimed_at=now(), deadline_at=now()+interval '1 hour', claim_token=%s WHERE order_id=%s''',
|
|
(str(uuid4()), parent['id']))
|
|
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)
|
|
mine = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == parent['id'])
|
|
assert mine['state'] == 'rec' and mine['proof_ok_at'] and not mine['final_items'], mine
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.print_files SET status='pending', claim_token=NULL WHERE order_id=%s",
|
|
(parent['id'],))
|
|
wait_print(client, parent['id'], 'ready')
|
|
deadline = time.monotonic() + 30
|
|
while (mine := next(o for o in client.call('/operator/board', operator=True)['orders']
|
|
if o['id'] == parent['id']))['state'] != 'tra' and time.monotonic() < deadline:
|
|
time.sleep(1)
|
|
assert mine['state'] == 'tra' and mine['final_items'] == [0], mine
|
|
with db.connect() as c:
|
|
moved = c.execute('''SELECT operator,reason FROM dtf_local.movements
|
|
WHERE order_id=%s AND to_state='tra' ORDER BY id DESC LIMIT 1''', (parent['id'],)).fetchone()
|
|
assert (moved['operator'], moved['reason']) == ('Prumo', 'Prova OK'), moved
|
|
print('PASS: a file finished after Prova OK becomes the final and queues the order')
|
|
|
|
# A CDR cannot be decoded by the worker. The designer prepares the full
|
|
# parent PNG, then the worker automatically cuts the child's proof from it.
|
|
manual_source = upload_bytes(client, b'LOCAL PRINT TEST - NOT AN IMAGE', name='MANUAL-PROOF.cdr')
|
|
manual_parent = paid_order(client, loose_item(manual_source, copies=1))
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.orders SET snapshot=jsonb_set(snapshot,'{proof}','true') WHERE id=%s",
|
|
(manual_parent['id'],))
|
|
manual_child = client.call('/operator/orders/' + manual_parent['id'] + '/proof-card', {}, operator=True)
|
|
wait_print(client, manual_child['id'], 'manual')
|
|
retry = client.call('/operator/orders/' + manual_child['id'] + '/print-files', {}, operator=True, expected=409)
|
|
assert 'pedido pai' in retry['detail'], retry
|
|
prepared = upload_bytes(client, artwork(), name='MANUAL-PROOF-FINAL.png', order_id=manual_parent['id'])
|
|
client.call('/operator/orders/' + manual_parent['id'] + '/final-files',
|
|
{'version': manual_parent['version'],
|
|
'files': [{'item_index': 0, 'upload_id': prepared}],
|
|
'note': 'PNG completo para a prova'}, operator=True)
|
|
client.call('/operator/orders/' + manual_child['id'] + '/print-files', {}, operator=True)
|
|
wait_print(client, manual_child['id'], 'ready')
|
|
proof_card = next(o for o in client.call('/operator/board', operator=True)['orders']
|
|
if o['id'] == manual_child['id'])
|
|
assert proof_card['final_items'] == [0], proof_card
|
|
print('PASS: manual parent PNG produces the child proof automatically')
|
|
|
|
# A customer cannot see or reuse another order's generated file.
|
|
other = Client()
|
|
other.call('/session')
|
|
other.call('/uploads/' + str(row['upload_id']), expected=404)
|
|
|
|
# Artwork the generator cannot read goes to hand preparation, with a reason.
|
|
manual = upload_bytes(client, b'LOCAL PRINT TEST - NOT AN IMAGE', name='LOCAL-PRINT-TEST.cdr')
|
|
order = paid_order(client, loose_item(manual, copies=1))
|
|
order, row = wait_print(client, order['id'], 'manual')
|
|
assert 'não é uma imagem' in row['detail']['reason'], row
|
|
rows = client.call('/operator/orders/' + order['id'] + '/print-files', {}, operator=True)
|
|
assert rows[0]['status'] == 'pending'
|
|
wait_print(client, order['id'], 'manual')
|
|
print('PASS: unreadable artwork is routed to hand preparation and can be retried')
|
|
|
|
# A signed, paid notification for the wrong amount does not become an order;
|
|
# it waits on the Kanban until an operator records the resolution.
|
|
# Same client, so the same operator session: operator logins share a
|
|
# 10-per-15-minutes account limit with every other suite in the run.
|
|
quote_id, total = approved_quote(client, loose_item(uid, copies=1))
|
|
event_id = 'print-test-underpaid-' + uuid4().hex
|
|
outcome = deliver({'event_id': event_id, 'reference': quote_id,
|
|
'status': 'approved', 'amount_cents': total - 1})
|
|
assert outcome['outcome'].startswith('refused'), outcome
|
|
issues = client.call('/operator/payment-events?state=open&limit=100', operator=True)['issues']
|
|
issue = next(i for i in issues if i['event_id'] == event_id)
|
|
assert client.call('/operator/board', operator=True)['payment_issues_total'] >= 1
|
|
client.call('/operator/payment-events/' + issue['id'] + '/resolve', {'note': 'no'},
|
|
operator=True, expected=422)
|
|
client.call('/operator/payment-events/' + issue['id'] + '/resolve',
|
|
{'note': 'Local test: refunded the underpayment'}, operator=True)
|
|
client.call('/operator/payment-events/' + issue['id'] + '/resolve',
|
|
{'note': 'Local test: second resolution'}, operator=True, expected=404)
|
|
issues = client.call('/operator/payment-events?state=open&limit=100', operator=True)['issues']
|
|
assert not any(i['event_id'] == event_id for i in issues)
|
|
resolved_page = client.call('/operator/payment-events?state=resolved&limit=100', operator=True)
|
|
assert resolved_page['total'] >= 1
|
|
resolved = resolved_page['issues']
|
|
done = next(i for i in resolved if i['event_id'] == event_id)
|
|
assert done['resolution'] == 'Local test: refunded the underpayment' and done['resolved_by']
|
|
print('PASS: refused paid notification is listed until an operator resolves it, then kept as history')
|
|
|
|
# The send log pages by id and filters by destination, status, event and order.
|
|
page = client.call('/operator/events?limit=2', operator=True)
|
|
assert len(page['events']) == 2 and page['total'] > 2
|
|
second = client.call('/operator/events?limit=2&offset=2', operator=True)
|
|
assert all(e['id'] < page['events'][-1]['id'] for e in second['events'])
|
|
assert second['total'] == page['total']
|
|
tiny = client.call('/operator/events?provider=tiny&event=payment_approved&status=delivered&limit=100', operator=True)
|
|
assert tiny['events'] and all(e['provider'] == 'tiny' and e['payload']['event'] == 'payment_approved'
|
|
and e['delivered_at'] for e in tiny['events'])
|
|
client.call('/operator/events?provider=email', operator=True, expected=422)
|
|
client.call('/operator/events?limit=500', operator=True, expected=422)
|
|
quotes = client.call('/operator/quotes?kind=approved&limit=1&offset=0', operator=True)
|
|
assert 'total' in quotes and len(quotes['quotes']) <= 1
|
|
finished = client.call('/operator/orders/finished?limit=1', operator=True)
|
|
if finished['orders']:
|
|
last = finished['orders'][-1]
|
|
client.call('/operator/orders/finished?before_finished_at=' + last['finished_at'].replace('+', '%2B')
|
|
+ '&before_id=' + last['id'], operator=True)
|
|
print('PASS: send log, payment history and finished orders page and filter')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|