Files
dtf-system/tests/treatment_gate_test.py
Cauê Faleiros a712c69aca
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 5m44s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m22s
fix: align proof, treatment, metrics and site videos with PDF
2026-11-06 15:27:48 -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 'Tratamento 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 treatment; designer PNG opens the print queue')
if __name__ == '__main__':
run()