One line per item, code size quantity reference. Lines with errors are listed with the line and the reason and mounted only after "Montar sem essas N linhas". A reference is drawn 3 mm high right under the stamp, with 1 cm to the next piece on that side; the list is always Interno and the Prumo report names the skipped lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
6.6 KiB
Python
131 lines
6.6 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_pasted_list_says_how_many_lines_were_mounted(self):
|
||
order = self.order()
|
||
order['snapshot']['batch'] = {'lines': 3, 'skipped': []}
|
||
lines = report(order, {'u1': {'name': 'arte.pdf'}})
|
||
text = '\n'.join(lines)
|
||
self.assertIn('Lista colada: 3 linhas montadas', text)
|
||
self.assertNotIn('puladas', text)
|
||
# Before the item lines: the designer reads the list first.
|
||
self.assertLess(text.index('Lista colada'), text.index('Formato detectado'))
|
||
|
||
def test_pasted_list_lists_the_skipped_lines(self):
|
||
order = self.order()
|
||
order['snapshot']['batch'] = {'lines': 2, 'skipped': [
|
||
{'line': 4, 'text': 'NX.999 Z 1 REF', 'reason': 'tamanho não existe na tabela'},
|
||
{'line': 7, 'text': 'NX.226 C 0', 'reason': 'quantidade de 1 a 9999'}]}
|
||
lines = report(order, {'u1': {'name': 'arte.pdf'}})
|
||
text = '\n'.join(lines)
|
||
self.assertIn('Lista colada: 2 linhas montadas, 2 puladas', text)
|
||
self.assertIn('Linha 4 pulada (tamanho não existe na tabela): NX.999 Z 1 REF', text)
|
||
self.assertIn('Linha 7 pulada (quantidade de 1 a 9999): NX.226 C 0', text)
|
||
self.assertLess(text.index('Lista colada'), text.index('Linha 4 pulada'))
|
||
self.assertLess(text.index('Linha 7 pulada'), text.index('Formato detectado'))
|
||
|
||
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()
|