Files
dtf-system/tests/treatment_gate_test.py
Cauê Faleiros dedcbb6aad feat: Ajuste Fino priced per art, with the offer under each Prumo warning (Marcus 10/11, point 1)
The designer treatment becomes Ajuste Fino, priced per art with a batch
band set in the Site tab (e.g. R$ 9,90, from 10 arts R$ 6,90). Under each
art the Prumo warns about, the Site offers 'Quer que um designer resolva?
Ajuste Fino'; the cart keeps 'Ajuste Fino em todas as artes'. The server
counts the chosen arts, Tiny gets the line with that quantity, the card
shows 'Ajuste Fino · N artes'. Old carts asking the treatment for the
whole order keep working.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-11 14:21:14 -03:00

39 lines
2.0 KiB
Python

"""A paid treatment needs a designer-prepared final before the print queue.
Run against the local stack: SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost
python -m tests.treatment_gate_test
"""
from app.core import db
from tests.print_file_test import artwork, loose_item, paid_order, wait_print
from tests.smoke_test import Client, upload_bytes
def run():
client = Client()
client.call('/session')
original = upload_bytes(client, artwork(), name='LOCAL-TREATMENT-ORIGINAL.png')
order = paid_order(client, loose_item(original, copies=1))
_, generated = wait_print(client, order['id'], 'ready')
# The local price is normally zero. Mark this paid fixture as having bought
# treatment to exercise the production gate, not the checkout price rule.
with db.connect() as c:
c.execute("""UPDATE dtf_local.orders SET snapshot=jsonb_set(snapshot,'{treatment}',
'{"cents":990,"hours":24}'::jsonb) WHERE id=%s""", (order['id'],))
approved = client.call('/operator/orders/' + order['id'] + '/final-files',
{'version': order['version'], 'files': [{'item_index': 0, 'upload_id': generated['upload_id']}],
'note': 'Gerado pelo Prumo'}, operator=True)
blocked = client.call('/operator/orders/' + order['id'] + '/move',
{'state': 'tra', 'version': approved['version']}, operator=True, expected=409)
assert 'Ajuste Fino pago' in blocked['detail'], blocked
prepared = upload_bytes(client, artwork(), name='LOCAL-TREATMENT-FINAL.png', order_id=order['id'])
approved = client.call('/operator/orders/' + order['id'] + '/final-files',
{'version': approved['version'], 'files': [{'item_index': 0, 'upload_id': prepared}],
'note': 'PNG tratado pelo designer'}, operator=True)
client.call('/operator/orders/' + order['id'] + '/move',
{'state': 'tra', 'version': approved['version']}, operator=True)
print('PASS: generated artwork cannot satisfy paid Ajuste Fino; designer PNG opens the print queue')
if __name__ == '__main__':
run()