Files
dtf-system/tests/grade_rules_test.py
Cauê Faleiros bb6fb14b1a
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
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
fix: the server refuses stacked pieces and files laid out at other proportions, and never cuts a strip with ink
The price came from the layout the browser sent, checked only in part:
- Pieces on top of each other passed: 100 copies stacked in one place bill
  10 cm and print over each other. The layout validator now refuses any
  overlap.
- A file laid out at proportions it does not have (a 5 m sheet sent as
  10 cm) was found only by the print file, after payment. The quote now
  checks each raster file's proportions from the bytes it already reads.
- The empty strips the Site cuts from a ready sheet were cut on its word.
  The print file now reads them: a strip with ink sends the item to hand
  preparation with the reason, instead of printing the art cut off.

Test fixtures that laid real images out at impossible proportions now keep
the image's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 15:56:00 -03:00

84 lines
3.5 KiB
Python

"""The art grade rules: the designer warning and the required treatment (8.5).
Run against the local stack: SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost
python -m tests.grade_rules_test
"""
import secrets
from uuid import uuid4
from app.core import db
from tests.print_file_test import artwork
from tests.smoke_test import Client, item_spec, upload_bytes
def quote_body(item, treatment, mail):
body = {'request_key': str(uuid4()),
'customer': {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': mail},
'items': [item], 'freight': {'service': 'pickup'}}
if treatment:
body['treatment'] = True
return body
def run():
tag = secrets.token_hex(4)
mail = f'grade-{tag}@example.test'
client = Client()
client.call('/session')
manager = Client()
manager.call('/session')
manager.call('/operator/me', operator=True)
manager = manager.operator_client
price_id = quote_id = upload_id = None
rules_set = False
treatment_enabled = True
try:
products = {row['id']: row for row in manager.call('/operator/site/products')['products']}
treatment_enabled = products['tratamento']['enabled']
manager.call('/operator/site/products/tratamento', {'enabled': True})
price_id = manager.call('/operator/site/products/tratamento/prices', {'unit_cents': 1000})['id']
manager.call('/operator/site/grade-rules', {'aviso': 100, 'tratamento': 100})
rules_set = True
rules = manager.call('/operator/site/grade-rules')
assert rules['aviso'] == 100 and rules['tratamento'] == 100, rules
assert rules['treatment_offered'] is True, rules
upload_id = upload_bytes(client, artwork(), name=f'LOCAL-GRADE-{tag}.png')
item = {**item_spec('uv', '1', 50, upload_id, aspect=2),
'quality_status': 'warning', 'quality_acknowledged': True}
refused = client.call('/quotes', quote_body(item, False, mail), expected=422)
assert refused['detail'] == ('Sua arte tem nota 50: para imprimir com qualidade, '
'o Ajuste Fino é obrigatório neste pedido.'), refused
made = client.call('/quotes', quote_body(item, True, mail))
quote_id = made['id']
assert made['status'] == 'approved', made
approved = client.call('/quotes/' + quote_id)['approved']
assert approved['grade_flags'] == {'aviso': 50, 'tratamento': 50}, approved
assert approved['treatment'] == {'cents': 1000, 'hours': 24, 'arts': 1,
'unit_cents': 1000}, approved
assert approved['total_cents'] == 9990, approved
print('PASS: the grade rule requires Ajuste Fino and flags the order with the worst grade')
finally:
if rules_set:
try:
manager.call('/operator/site/grade-rules', {'aviso': None, 'tratamento': None})
except Exception:
pass
with db.connect() as c:
if quote_id:
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (quote_id,))
if price_id:
c.execute('DELETE FROM dtf_local.product_prices WHERE id=%s', (price_id,))
if upload_id:
c.execute('DELETE FROM dtf_local.uploads WHERE id=%s', (upload_id,))
try:
manager.call('/operator/site/products/tratamento', {'enabled': treatment_enabled})
except Exception:
pass
if __name__ == '__main__':
run()