Files
dtf-system/tests/grade_rules_test.py
Cauê Faleiros 857eea3379
Some checks failed
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Failing after 1m17s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped
feat: copies from the file name, the proof in the summaries, the grade off the customer's screen (Rodada 5, B3, B6, D6)
B6: "12x nome.png" enters with 12 copies, art or ready sheet (up to 200;
"1920x1080.png" is not read as copies). B3: the DPI refusal speaks per
art, the cart and payment summaries list "Prova antes de imprimir" when
chosen, and below 10 m the proof box stays, closed, saying the rule.
D6: the Ajuste Fino refusal no longer shows the grade number (Site and
server); the unused motivoNota helper is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:28:24 -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 está abaixo da resolução mínima, então '
'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()