Files
dtf-system/tests/test_prumo.py
Cauê Faleiros 5aafd9ee91
All checks were successful
Build and deploy / Publish images (push) Successful in 1m5s
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 5m7s
Build and deploy / Secret scan and release gate (push) Successful in 6s
fix: review of phase-2 stage 0 and fronts 5, 6 and 11
- A paid treatment adds its 24 h to Arte recebida's acceptable time, on
  the card and in Números (fronts 5 and 11).
- TINY_PRODUCT_TREATMENT is a required Tiny setting once the treatment
  has a price, instead of every treated order failing at the Tiny.
- A quote reads each PDF once: Files caches the header and the DPI.
- A proof made from the parent's final split into parts uses the part
  that holds the finest stroke, not the last one (0.1).
- Prumo report: one format line per item, the time from the claim (kept
  on the finished print file), and the stroke class in customer words.
- The Site says the Prumo checks the art, and a too-tall PNG no longer
  says "Este PDF".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:45:43 -03:00

84 lines
4.0 KiB
Python

"""The Prumo report: only what happened, in the order it happened (front 6)."""
import unittest
from datetime import datetime, timedelta, timezone
from app.prumo import customer_summary, report
class PrumoReportTests(unittest.TestCase):
def order(self):
item = {
'mode': 'avulsa', 'billed_metres': '1.30', 'metres': '1.30',
'uploads': ['u1'], 'source_dpi': 96, 'residue_accepted': 3,
'residue_accepted_at': '2026-11-05T17:32:00+00:00',
'stroke_px': 6, 'stroke_class': 'C2', 'stroke_choice': 'measured',
'production': {'height_cm': '130', 'placements': [
{'rotation_degrees': 0}, {'rotation_degrees': 90}]},
}
started = datetime(2026, 11, 5, 14, 0, tzinfo=timezone.utc)
return {'snapshot': {'items': [item]}, 'print_files': [{
'item_index': 0, 'status': 'ready', 'created_at': started - timedelta(minutes=5),
'claimed_at': started, 'finished_at': started + timedelta(seconds=41),
'detail': {'format': 'png', 'dpi': 300, 'parts': [
{'from_cm': '0', 'to_cm': '15'}, {'from_cm': '15', 'to_cm': '16'}]},
}]}
def test_card_report_reads_the_decisions(self):
lines = report(self.order(), {'u1': {'name': 'arte.pdf', 'original_name': 'arte.cdr'}})
text = '\n'.join(lines)
self.assertIn('Chegou CDR, era PDF por dentro', text)
self.assertIn('PDF → PNG 300 DPI', text)
self.assertIn('Resolução detectada: 96 DPI', text)
self.assertIn('3 pontos < 2 mm — cliente aceitou', text)
self.assertIn('2 artes, 1 girada', text)
self.assertIn('Menor traço 6 px → C2', text)
self.assertIn('cliente escolheu imprimir em C1', text)
self.assertIn('2 partes (15,00 + 1,00)', text)
self.assertIn('Prumo levou 41 s', text)
self.assertNotIn('Prumo levou 341 s', text)
def test_without_a_claim_time_the_generation_line_is_hidden(self):
order = self.order()
del order['print_files'][0]['claimed_at']
text = '\n'.join(report(order, {'u1': {'name': 'arte.pdf', 'original_name': 'arte.cdr'}}))
self.assertNotIn('Prumo levou', text)
def test_one_format_line_per_item(self):
order = self.order()
item = order['snapshot']['items'][0]
item['uploads'] = ['u1', 'u2', 'u3']
uploads = {uid: {'name': f'arte-{uid}.png'} for uid in item['uploads']}
text = '\n'.join(report(order, uploads))
self.assertEqual(text.count('Formato detectado'), 1)
self.assertIn('Formato detectado: PNG (3 arquivos)', text)
# Mixed formats name them once, sorted, and the per-file changes stay.
uploads['u2'] = {'name': 'arte-u2.pdf', 'original_name': 'arte-u2.cdr'}
mixed = '\n'.join(report(order, uploads))
self.assertEqual(mixed.count('Formatos detectados'), 1)
self.assertIn('Formatos detectados: PDF, PNG', mixed)
self.assertIn('Chegou CDR, era PDF por dentro', mixed)
def test_customer_summary_is_plain_language(self):
lines = customer_summary(self.order()['snapshot']['items'])
text = ' '.join(lines)
self.assertIn('96 DPI', text)
self.assertIn('3 pontinhos', text)
self.assertIn('Sua arte tem traços médios; a impressão foi ajustada para eles.', text)
self.assertNotIn('O traço mais fino foi medido em C2.', text)
self.assertIn('C1', text)
self.assertIn('será preparado', text)
self.assertNotIn('foi ampliada', text)
def test_unfinished_job_does_not_claim_a_conversion_or_background_check(self):
order = self.order()
order['print_files'] = [{'item_index': 0, 'status': 'manual', 'detail': {}}]
lines = report(order, {'u1': {'name': 'arte.pdf', 'original_name': 'arte.cdr'}})
text = '\n'.join(lines)
self.assertIn('Arquivo exige preparo manual', text)
self.assertNotIn('PDF → PNG', text)
self.assertNotIn('Fundo transparente', text)
if __name__ == '__main__':
unittest.main()