All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m43s
Replaces 7111995 (only 57,0 cm entered; a whole order of 56,5-56,9 cm
sheets was refused, DTF-WEB-2C). Marcus's rules, for Arquivo por metro,
Premium (57 cm) and UV (27 cm):
1. A known width up to the film (PNG recording 200 DPI or more, or a PDF
page) enters at its real size, centred, billed by its real height.
2. Narrower: his warning before the cart, confirmation required
(Imprimir no tamanho real / Enviar outro arquivo); recorded in the
Prumo report ("cliente confirmou folha de 35,8 cm no tamanho real") and
shown in the cart and payment summaries.
3. Wider than the film: refused with his message.
4. Unknown width: taken as the film's, DPI from the pixels; 200 or more
with a confirmation, under 200 refused with the artes avulsas hint.
Within 0,1 cm of the film counts as the film. The server checks it all
again at checkout (sheet_width_issue, centred placement, size_confirmed).
Also ops.stretched_sheets: the ready-sheet orders since 16/10 laid out
wider than their real width (number, real width, factor), for Marcus.
Contract: output/revisao/contrato-folha-real.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
145 lines
7.3 KiB
Python
145 lines
7.3 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_a_confirmed_narrow_sheet_is_reported(self):
|
||
order = self.order()
|
||
item = order['snapshot']['items'][0]
|
||
item['mode'] = 'file'
|
||
item['size_confirmed_at'] = '2026-11-05T17:32:00+00:00'
|
||
item['production']['film_width_cm'] = 57
|
||
item['production']['sources'] = [
|
||
{'width_cm': '35.79', 'length_cm': '40', 'size_confirmed': True},
|
||
{'width_cm': '57', 'length_cm': '30', 'size_confirmed': True},
|
||
]
|
||
text = '\n'.join(report(order, {'u1': {'name': 'folha.png'}}))
|
||
self.assertIn('Folha 1: cliente confirmou folha de 35,8 cm no tamanho real às 14:32', text)
|
||
self.assertNotIn('Folha 2: cliente confirmou', text)
|
||
|
||
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()
|