Files
dtf-system/tests/test_prumo.py
Cauê Faleiros 7fc091a1bd feat: a PNG that records 200 DPI or more offers its own size, Manter, and the Prumo says if it was kept (Rodada 5, A1)
The Site reads the pHYs chunk of a loose art; at 200 DPI or more the
size in the file is the default width and a Manter button sits before
the table sizes (also when the art is turned 90 degrees). The source
carries saved_width_cm and saved_dpi, used only by the Prumo report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:11:21 -03:00

108 lines
5.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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_saved_png_size_says_whether_the_customer_kept_it(self):
order = self.order()
item = order['snapshot']['items'][0]
item['production']['sources'] = [
{'width_cm': '28.0', 'length_cm': '35.2',
'saved_width_cm': '28.0', 'saved_dpi': 300},
{'width_cm': '20', 'length_cm': '25',
'saved_width_cm': '15', 'saved_dpi': 240},
]
text = '\n'.join(report(order, {'u1': {'name': 'arte.pdf'}}))
self.assertIn('Arte 1: tamanho lido do arquivo 28,0 × 35,2 cm (300 DPI), mantido', text)
self.assertIn('Arte 2: tamanho lido do arquivo 15,0 × 18,8 cm (240 DPI), '
'alterado pelo cliente para 20,0 cm', text)
# Turned 90°: the art's own width is the length along the film.
item['production']['sources'] = [
{'width_cm': '35.2', 'length_cm': '28.0', 'rotation_degrees': 90,
'saved_width_cm': '28.0', 'saved_dpi': 300}]
text = '\n'.join(report(order, {'u1': {'name': 'arte.pdf'}}))
self.assertIn('Arte 1: tamanho lido do arquivo 28,0 × 35,2 cm (300 DPI), mantido', text)
def test_without_a_saved_png_size_no_line_is_added(self):
text = '\n'.join(report(self.order(), {'u1': {'name': 'arte.pdf'}}))
self.assertNotIn('tamanho lido do arquivo', 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()