feat: a ready sheet prints at its real size, centred on the film, with the customer's confirmation (Marcus, 2026-12-02)
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
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>
This commit is contained in:
@@ -162,15 +162,36 @@ try{
|
||||
else{$('inp').files=dt.files;$('inp').dispatchEvent(new Event('change',{bubbles:true}));}
|
||||
};
|
||||
// A genuine mounted sheet spans the film width with printable resolution,
|
||||
// on a transparent background; or with a solid one, or a residue dot.
|
||||
// on a transparent background; or with a solid one, or a residue dot. The
|
||||
// pHYs chunk makes its real width known, as a sheet exported at 300 DPI.
|
||||
window.comDpi=async(blob,ppm=11811)=>{
|
||||
const b=new Uint8Array(await blob.arrayBuffer());
|
||||
const crc=c=>{let x=0xffffffff;for(const v of c){x^=v;for(let k=0;k<8;k++)x=x&1?0xedb88320^(x>>>1):x>>>1;}return (x^0xffffffff)>>>0;};
|
||||
let i=8;
|
||||
while(i+8<=b.length){
|
||||
const len=((b[i]<<24)>>>0)+(b[i+1]<<16)+(b[i+2]<<8)+b[i+3];
|
||||
const tipo=String.fromCharCode(...b.slice(i+4,i+8));
|
||||
if(tipo==='IDAT'){
|
||||
const ch=new Uint8Array(21), dv=new DataView(ch.buffer);
|
||||
dv.setUint32(0,9);ch.set([0x70,0x48,0x59,0x73],4);
|
||||
dv.setUint32(8,ppm);dv.setUint32(12,ppm);ch[16]=1;
|
||||
dv.setUint32(17,crc(ch.subarray(4,17)));
|
||||
const out=new Uint8Array(b.length+21);
|
||||
out.set(b.subarray(0,i),0);out.set(ch,i);out.set(b.subarray(i),i+21);
|
||||
return new Blob([out],{type:'image/png'});
|
||||
}
|
||||
i+=12+len;
|
||||
}
|
||||
return blob;
|
||||
};
|
||||
window.sendSheet=async({fundo=false,ponto=false}={})=>{
|
||||
const cm=larguraFilme(), px=Math.ceil(cm/2.54*150);
|
||||
const cm=larguraFilme(), px=Math.ceil(cm/2.54*300);
|
||||
const c=document.createElement('canvas');c.width=px;c.height=Math.round(px*0.6);
|
||||
const ctx=c.getContext('2d');
|
||||
if(fundo){ctx.fillStyle='white';ctx.fillRect(0,0,c.width,c.height);}
|
||||
ctx.fillStyle='#222';ctx.fillRect(40,40,px/4,px/4);
|
||||
if(ponto)ctx.fillRect(Math.round(px*0.8),Math.round(c.height/2),4,4);
|
||||
const blob=await new Promise(r=>c.toBlob(r,'image/png'));
|
||||
const blob=await window.comDpi(await new Promise(r=>c.toBlob(r,'image/png')));
|
||||
const dt=new DataTransfer();dt.items.add(new File([blob],'folha-montada.png',{type:'image/png'}));
|
||||
$('inp').files=dt.files;$('inp').dispatchEvent(new Event('change',{bubbles:true}));
|
||||
};
|
||||
@@ -223,8 +244,9 @@ try{
|
||||
'files beyond the 4 GB upload limit are rejected before browser analysis');
|
||||
// A PNG above the browser's ~32k-pixel height limit cannot be checked here:
|
||||
// it is refused with a clear message instead of being accepted as 0 DPI.
|
||||
await evaluate(`(()=>{const h=new Uint8Array(33);h.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0,0,0,13,0x49,0x48,0x44,0x52]);
|
||||
await evaluate(`(()=>{const h=new Uint8Array(54);h.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0,0,0,13,0x49,0x48,0x44,0x52]);
|
||||
const v=new DataView(h.buffer);v.setUint32(16,6732);v.setUint32(20,35433);h.set([8,6,0,0,0],24);
|
||||
v.setUint32(33,9);h.set([0x70,0x48,0x59,0x73],37);v.setUint32(41,11811);v.setUint32(45,11811);h[49]=1;
|
||||
const f=new File([h],'folha-grande.png');Object.defineProperty(f,'size',{value:900*1048576});return sel([f]);})()`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'tall sheet refused');
|
||||
assert.equal(await evaluate(`folhas[0].measurementError.includes('PNG alto')`),true);
|
||||
@@ -232,34 +254,83 @@ try{
|
||||
// A ready textile sheet whose real width is known (PNG pHYs >= 200 DPI, or a
|
||||
// PDF page) must be 57 cm wide: otherwise it leaves the list and a dialog
|
||||
// names it. A hand-made PNG header with a pHYs chunk, read by its header.
|
||||
await evaluate(`window.pngLargura=async(w,ppm)=>{
|
||||
const b=new Uint8Array(54);b.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A]);
|
||||
await evaluate(`window.pngLargura=async(w,ppm,h=10339,nome='folha-larga.png')=>{
|
||||
const comDpi=ppm!=null, b=new Uint8Array(comDpi?54:33);
|
||||
b.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A]);
|
||||
const v=new DataView(b.buffer);
|
||||
v.setUint32(8,13);b.set([0x49,0x48,0x44,0x52],12);
|
||||
v.setUint32(16,w);v.setUint32(20,10339);b.set([8,6,0,0,0],24);
|
||||
v.setUint32(33,9);b.set([0x70,0x48,0x59,0x73],37);
|
||||
v.setUint32(41,ppm);v.setUint32(45,ppm);b[49]=1;
|
||||
const f=new File([b],'folha-larga.png',{type:'image/png'});
|
||||
v.setUint32(16,w);v.setUint32(20,h);b.set([8,6,0,0,0],24);
|
||||
if(comDpi){v.setUint32(33,9);b.set([0x70,0x48,0x59,0x73],37);
|
||||
v.setUint32(41,ppm);v.setUint32(45,ppm);b[49]=1;}
|
||||
const f=new File([b],nome,{type:'image/png'});
|
||||
Object.defineProperty(f,'size',{value:900*1048576});
|
||||
return sel([f]);}`);
|
||||
// S1/S2: 35,8 cm at 300 DPI enters at its real size and asks for confirmation.
|
||||
await evaluate(`pngLargura(4227,11811)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && $('larguraDlg').open`),'wrong-width sheet opens dialog');
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && $('tamanhoDlg').open`),'narrow sheet opens the size dialog');
|
||||
assert.equal(await evaluate(`$('tamanhoTit').textContent`),'folha-larga.png');
|
||||
const tamanhoTxt=await evaluate(`$('tamanhoTxt').textContent`);
|
||||
assert.match(tamanhoTxt,/35,8 cm/);
|
||||
assert.match(tamanhoTxt,/0,88 m/);
|
||||
assert.match(tamanhoTxt,/R\$ 21,90\/m/);
|
||||
assert.equal(await evaluate(`$('tamanhoOk').textContent`),'Imprimir no tamanho real');
|
||||
// While unconfirmed, "Adicionar ao carrinho" says so and adds nothing.
|
||||
assert.deepEqual(await evaluate(`(()=>{const antes=pedido.length;$('qOk').disabled=false;$('qOk').click();
|
||||
return {added:pedido.length-antes,msg:$('qmsg').textContent.includes('Confirme o tamanho')};})()`),
|
||||
{added:0,msg:true});
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`!$('tamanhoDlg').open && folhas[0]?.confirmado===true`),'narrow sheet confirmed');
|
||||
assert.ok(Math.abs(await evaluate(`folhas[0].med.larg`)-35.79)<0.02);
|
||||
assert.equal(await evaluate(`$('larguraDlg').open`),false);
|
||||
await waitFor(()=>evaluate(`itemAtual?.production?.sources[0]?.size_confirmed===true`),
|
||||
'confirmed size goes to the cart source');
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
// S3: "Enviar outro arquivo" takes the sheet out of the list.
|
||||
await evaluate(`pngLargura(4227,11811)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && $('tamanhoDlg').open`),'narrow sheet opens again');
|
||||
await click('#tamanhoOutro');
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && !$('tamanhoDlg').open`),'send another removes the sheet');
|
||||
// S6: 61,0 cm does not fit the film: it leaves and the width dialog names it.
|
||||
await evaluate(`pngLargura(7200,11811,10339,'folha-larga.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && $('larguraDlg').open`),'too-wide sheet opens the width dialog');
|
||||
assert.deepEqual(await evaluate(`({itens:$('larguraLista').children.length,
|
||||
texto:$('larguraLista').textContent})`),
|
||||
{itens:1,texto:'folha-larga.png: 35,8 cm (300 DPI)'});
|
||||
texto:$('larguraLista').textContent,titulo:$('larguraTit').textContent})`),
|
||||
{itens:1,texto:'folha-larga.png: tem 61,0 cm e não cabe em 57 cm.',
|
||||
titulo:'A folha não cabe no filme de 57 cm'});
|
||||
await click('#larguraOk');
|
||||
await waitFor(()=>evaluate(`!$('larguraDlg').open && $('larguraLista').children.length===0`),
|
||||
'width dialog closes and clears the list');
|
||||
// 6732 px at 300 DPI is 57 cm within tolerance: accepted as today.
|
||||
// S5: 6732 px at 300 DPI is 57 cm within tolerance: no dialog, real width.
|
||||
await evaluate(`pngLargura(6732,11811)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].med`),'57 cm sheet accepted');
|
||||
assert.equal(await evaluate(`$('larguraDlg').open`),false);
|
||||
assert.equal(await evaluate(`folhas[0].med.larg`),57);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].med && !$('tamanhoDlg').open && !$('larguraDlg').open`),
|
||||
'57 cm sheet accepted');
|
||||
assert.ok(Math.abs(await evaluate(`folhas[0].med.larg`)-56.998)<0.01);
|
||||
assert.equal(await evaluate(`!!folhas[0].confirmado`),false);
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
// Under 200 DPI the file says nothing about its real width: today's rule.
|
||||
await evaluate(`pngLargura(4227,3780)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].med`),'low-DPI sheet follows today rule');
|
||||
assert.equal(await evaluate(`$('larguraDlg').open`),false);
|
||||
// S7: without pHYs the width is unknown, so it assumes the film and asks.
|
||||
await evaluate(`pngLargura(6732,null,10339,'folha-sem-dpi.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && $('tamanhoDlg').open`),'unknown width opens the size dialog');
|
||||
assert.equal(await evaluate(`$('tamanhoTit').textContent`),'folha-sem-dpi.png');
|
||||
assert.match(await evaluate(`$('tamanhoTxt').textContent`),
|
||||
/57 cm de largura e 87,5 cm de altura \(300 DPI\)/);
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`folhas[0]?.confirmado===true && !$('tamanhoDlg').open`),'unknown width confirmed');
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
// S8: unknown width with less than 200 DPI is refused by resolution.
|
||||
await evaluate(`pngLargura(2154,null,10339,'folha-baixa.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && $('avisoTipo').textContent.includes('abaixo do mínimo de 200')`),
|
||||
'unknown width under 200 DPI is refused');
|
||||
assert.match(await evaluate(`$('avisoTipo').textContent`),/artes avulsas/);
|
||||
// S13: several sheets needing a dialog are answered one at a time, in order.
|
||||
await evaluate(`pngLargura(4227,11811,10339,'folha-a.png')`);
|
||||
await waitFor(()=>evaluate(`$('tamanhoDlg').open && $('tamanhoTit').textContent==='folha-a.png'`),'first sheet in order');
|
||||
await evaluate(`pngLargura(4300,11811,10339,'folha-b.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===2`),'second sheet queued');
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`$('tamanhoDlg').open && $('tamanhoTit').textContent==='folha-b.png'`),'second sheet next');
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`!$('tamanhoDlg').open && folhas.length===2 && folhas.every(x=>x.confirmado)`),
|
||||
'each sheet answered on its own');
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
await evaluate(`pickTipo('avulsa')`);
|
||||
assert.equal(await evaluate('modo'),'avulsa');
|
||||
@@ -458,11 +529,9 @@ try{
|
||||
// Parsed geometry honors inherited MediaBox, CropBox, rotation and UserUnit.
|
||||
// Extra pages and unreadable PDFs must never fall through to manual pricing.
|
||||
const pdfFile=(data,name='sheet.pdf')=>`new File([Uint8Array.from(atob(${data}),c=>c.charCodeAt(0))],${JSON.stringify(name)},{type:'application/pdf'})`;
|
||||
// Geometry alone: measured under UV, where the 57 cm rule does not apply.
|
||||
const rotated=await evaluate(`(async()=>{const m=modo;modo='uvfile';
|
||||
try{return await medirFolha(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))});}
|
||||
finally{modo=m;}})()`);
|
||||
assert.deepEqual(rotated,{larg:50.8,alt:25.4,fonte:'página do PDF · UserUnit 2'});
|
||||
// A 50,8 cm page on the 57 cm film: real size, asking for confirmation.
|
||||
const rotated=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))})`);
|
||||
assert.deepEqual(rotated,{larg:50.8,alt:25.4,fonte:'página do PDF · UserUnit 2',confirmar:'estreita'});
|
||||
const rendered=await evaluate(`rasterizarPdf(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))},50.8,25.4).then(r=>({ok:!!r.tela,error:r.erro||null}))`);
|
||||
assert.deepEqual(rendered,{ok:true,error:null});
|
||||
// A PDF sheet gets the same ink map, rendered in strips: a blank page is all transparent.
|
||||
@@ -475,13 +544,17 @@ try{
|
||||
assert.equal(beyondSpec.rejected,true);assert.match(beyondSpec.reason,/508 cm/);
|
||||
const broken=await evaluate(`medirFolha(new File(['broken'],'broken.pdf',{type:'application/pdf'}))`);
|
||||
assert.equal(broken.rejected,true);
|
||||
// A PDF page is a known real width too: 30 cm is refused, 57 cm is accepted.
|
||||
// A PDF page is a known real width too: 30 cm enters narrow with confirmation,
|
||||
// 57 cm enters as the film, and 60 cm does not fit.
|
||||
const pdfWide=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 850.394 360]'}))})`);
|
||||
assert.equal(!!pdfWide.larguraErrada,true);
|
||||
assert.ok(Math.abs(pdfWide.larguraErrada.cm-30)<0.01);
|
||||
assert.equal(pdfWide.larguraErrada.dpi,null);
|
||||
assert.equal(pdfWide.confirmar,'estreita');
|
||||
assert.ok(Math.abs(pdfWide.larg-30)<0.01);
|
||||
const pdfTooWide=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 1700.787 360]'}))})`);
|
||||
assert.equal(!!pdfTooWide.largaDemais,true);
|
||||
assert.ok(Math.abs(pdfTooWide.largaDemais.cm-60)<0.01);
|
||||
const pdfOk=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 1615.748 360]'}))})`);
|
||||
assert.ok(Math.abs(pdfOk.larg-57)<0.01);
|
||||
assert.equal(pdfOk.confirmar,undefined);
|
||||
await click('#bVoltar');await click('[data-modo="file"]');
|
||||
await evaluate(`sel([${pdfFile(pdfData({pages:2}),'two-pages.pdf')}])`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'multipage PDF refusal');
|
||||
|
||||
@@ -11,6 +11,17 @@ from psycopg.types.json import Jsonb
|
||||
|
||||
from app.core import db
|
||||
from tests.print_file_test import artwork
|
||||
|
||||
|
||||
def uv_sheet():
|
||||
"""A UV ready sheet 27 x 13,5 cm at 300 DPI, inked inside a margin."""
|
||||
import io
|
||||
from PIL import Image, ImageDraw
|
||||
image = Image.new('RGBA', (3189, 1595), (0, 0, 0, 0))
|
||||
ImageDraw.Draw(image).rectangle([40, 40, 3149, 1555], fill=(220, 30, 60, 255))
|
||||
out = io.BytesIO()
|
||||
image.save(out, 'PNG', dpi=(300, 300))
|
||||
return out.getvalue()
|
||||
from tests.smoke_test import Client, item_spec, upload_bytes
|
||||
|
||||
|
||||
@@ -36,9 +47,13 @@ def run():
|
||||
early_id = None
|
||||
order_id = None
|
||||
upload_id = None
|
||||
sheet_id = None
|
||||
try:
|
||||
upload_id = upload_bytes(client, artwork(), name=f'LOCAL-COUPON-{tag}.png')
|
||||
sheet = {**item_spec('uvfile', '1', 0, upload_id, aspect=2),
|
||||
# The UV ready sheet is its own 27 cm file at 300 DPI: the art above is
|
||||
# 13,5 cm, and laid out at 27 cm it would be a stretched sheet.
|
||||
sheet_id = upload_bytes(client, uv_sheet(), name=f'LOCAL-COUPON-SHEET-{tag}.png')
|
||||
sheet = {**item_spec('uvfile', '1', 0, sheet_id, aspect=2),
|
||||
'quality_status': 'warning', 'quality_acknowledged': True}
|
||||
# The sheet is the customer's own file, not one someone opens by hand.
|
||||
sheet['production']['sources'][0]['measurement'] = 'file'
|
||||
@@ -155,8 +170,9 @@ def run():
|
||||
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (early_id,))
|
||||
if coupon_id:
|
||||
c.execute('DELETE FROM dtf_local.coupons WHERE id=%s', (coupon_id,))
|
||||
if upload_id:
|
||||
c.execute('DELETE FROM dtf_local.uploads WHERE id=%s', (upload_id,))
|
||||
for uid in (upload_id, sheet_id):
|
||||
if uid:
|
||||
c.execute('DELETE FROM dtf_local.uploads WHERE id=%s', (uid,))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -243,58 +243,98 @@ class ProportionTests(unittest.TestCase):
|
||||
|
||||
|
||||
class SheetWidthTests(unittest.TestCase):
|
||||
"""A 57 cm ready sheet must really be 57 cm wide where the file tells
|
||||
(contrato-largura-folha.md), or the cart is refused."""
|
||||
"""A ready sheet prints at its real size, centred on the film
|
||||
(contrato-folha-real.md, Server V1–V5)."""
|
||||
|
||||
def cart(self, mode, name, width_cm=57):
|
||||
source = {'upload_id': name, 'kind': 'sheet', 'width_cm': width_cm}
|
||||
def cart(self, mode, name, width_cm=57, **source):
|
||||
source = {'upload_id': name, 'kind': 'sheet', 'width_cm': width_cm,
|
||||
'measurement': 'file', **source}
|
||||
return [{'mode': mode, 'production': {'sources': [source]}}], {name: {'name': name}}
|
||||
|
||||
def test_a_narrow_png_is_refused(self):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png')
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('35,8 cm', issue)
|
||||
self.assertIn('300 DPI', issue)
|
||||
def test_an_unknown_sheet_is_laid_out_at_the_film_width(self):
|
||||
# Rule 4: no DPI recorded, the sheet is taken as 57 cm; another width is a stretched layout.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (6732, 100))})
|
||||
items, rows = self.cart('file', 'sheet.png', width_cm=40, size_confirmed=True)
|
||||
self.assertIn('foi montada com 40,0 cm, mas tem 57 cm', grade_check.sheet_width_issue(files, items, rows))
|
||||
|
||||
def test_a_wide_png_is_refused(self):
|
||||
def test_a_narrow_known_sheet_asks_for_confirmation(self):
|
||||
# V3: 4227 px at 300 DPI is 35,8 cm, below the 57 cm film.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png', width_cm=35.79)
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('confirme a folha 1 de 35,8 cm no tamanho real', issue)
|
||||
|
||||
def test_a_confirmed_narrow_sheet_passes(self):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png', width_cm=35.79, size_confirmed=True)
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows))
|
||||
|
||||
def test_a_stretched_sheet_must_be_mounted_again(self):
|
||||
# V2: the source says 57 cm, the file measures 35,8 cm.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png', width_cm=57)
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('foi montada com 57,0 cm, mas tem 35,8 cm', issue)
|
||||
|
||||
def test_a_sheet_wider_than_the_film_is_refused(self):
|
||||
# V1: 7200 px at 300 DPI is 61,0 cm.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (7200, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png')
|
||||
self.assertIn('61,0 cm', grade_check.sheet_width_issue(files, items, rows))
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('61,0 cm', issue)
|
||||
self.assertIn('não cabe', issue)
|
||||
|
||||
def test_sheet_width_rounding_boundaries(self):
|
||||
for width_px, refused in ((6732, False), (6721, False), (6720, True)):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (width_px, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png')
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
if refused:
|
||||
self.assertIn('56,9 cm', issue)
|
||||
else:
|
||||
self.assertIsNone(issue, width_px)
|
||||
def test_a_sheet_within_tolerance_of_the_film_passes(self):
|
||||
# 6732 px at 300 DPI is 56,998 cm: within 0,1 cm of the film, no dialog.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (6732, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png', width_cm=56.998)
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows))
|
||||
|
||||
def test_png_under_trusted_dpi_passes(self):
|
||||
for options in ({}, {'dpi': (96, 96)}, {'dpi': (150, 150)}):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), **options)})
|
||||
items, rows = self.cart('file', 'sheet.png')
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows), options)
|
||||
def test_an_unknown_width_is_taken_as_the_film(self):
|
||||
# V5: no pHYs, 6732 px over 57 cm is 300 effective DPI.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (6732, 100))})
|
||||
items, rows = self.cart('file', 'sheet.png')
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('confirme a folha 1 de 57 cm antes de pagar', issue)
|
||||
items, rows = self.cart('file', 'sheet.png', size_confirmed=True)
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows))
|
||||
|
||||
def test_only_the_57_cm_modes_are_checked(self):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('premium', 'sheet.png')
|
||||
self.assertIn('35,8 cm', grade_check.sheet_width_issue(files, items, rows))
|
||||
for mode in ('uvfile', 'avulsa'):
|
||||
items, rows = self.cart(mode, 'sheet.png')
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows), mode)
|
||||
def test_an_unknown_width_under_the_minimum_dpi_is_refused(self):
|
||||
# V4: 2154 px over 57 cm is 96 effective DPI.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (2154, 100))})
|
||||
items, rows = self.cart('file', 'sheet.png')
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('96 DPI em 57 cm', issue)
|
||||
|
||||
def test_a_pdf_width_is_checked(self):
|
||||
def test_uv_uses_the_27_cm_film(self):
|
||||
# 2362 px at 300 DPI is 20,0 cm on the 27 cm UV film.
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (2362, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('uvfile', 'sheet.png', width_cm=20)
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('confirme a folha 1 de 20,0 cm no tamanho real', issue)
|
||||
|
||||
def test_a_narrow_pdf_asks_for_confirmation(self):
|
||||
files = FakeFiles({})
|
||||
items, rows = self.cart('file', 'sheet.pdf', width_cm=30)
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('30,0 cm', issue)
|
||||
self.assertNotIn('DPI', issue)
|
||||
for width_cm in (57, '56.95'):
|
||||
items, rows = self.cart('file', 'sheet.pdf', width_cm=width_cm)
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows), width_cm)
|
||||
self.assertIn('confirme a folha 1 de 30,0 cm no tamanho real', issue)
|
||||
|
||||
def test_a_pdf_wider_than_the_film_is_refused(self):
|
||||
files = FakeFiles({})
|
||||
items, rows = self.cart('file', 'sheet.pdf', width_cm=60)
|
||||
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||
self.assertIn('não cabe', issue)
|
||||
self.assertIn('60,0 cm', issue)
|
||||
|
||||
def test_customer_measured_sheets_pass(self):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('file', 'sheet.png', width_cm=35.79, measurement='customer')
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows))
|
||||
|
||||
def test_loose_art_is_not_checked(self):
|
||||
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||
items, rows = self.cart('avulsa', 'sheet.png', width_cm=35.79)
|
||||
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows))
|
||||
|
||||
def test_png_saved_dpi(self):
|
||||
head = encoded('PNG', (4227, 100), dpi=(300, 300))
|
||||
|
||||
@@ -105,6 +105,20 @@ class PrumoReportTests(unittest.TestCase):
|
||||
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)
|
||||
|
||||
@@ -39,6 +39,31 @@ class SheetGapTests(unittest.TestCase):
|
||||
self.assertEqual(str(caught.exception), SHEET_GAP_CHANGED)
|
||||
|
||||
|
||||
class CentredSheetTests(unittest.TestCase):
|
||||
"""A narrower ready sheet prints at its real size, centred on the film
|
||||
(Marcus, 2026-12-02, contrato-folha-real.md V7)."""
|
||||
|
||||
def narrow_sheet(self, x_cm):
|
||||
upload = str(uuid4())
|
||||
width, film, length = 35.79, 57, 20
|
||||
return Item.model_validate({
|
||||
'mode': 'file', 'metres': str(length / 100), 'grade': 100, 'uploads': [upload],
|
||||
'quality_status': 'ok', 'quality_acknowledged': False,
|
||||
'production': {'version': 3, 'film_width_cm': film, 'height_cm': length,
|
||||
'sources': [{'upload_id': upload, 'kind': 'sheet', 'width_cm': width,
|
||||
'length_cm': length, 'copies': 1, 'measurement': 'file'}],
|
||||
'placements': [{'source_index': 0, 'copy_index': 0, 'x_cm': x_cm,
|
||||
'y_cm': 0, 'width_cm': width, 'length_cm': length,
|
||||
'rotation_degrees': 0, 'mirrored': False}]}})
|
||||
|
||||
def test_a_narrow_sheet_is_centred(self):
|
||||
self.narrow_sheet((57 - 35.79) / 2)
|
||||
|
||||
def test_a_narrow_sheet_away_from_the_centre_is_refused(self):
|
||||
with self.assertRaises(ValueError):
|
||||
self.narrow_sheet(0)
|
||||
|
||||
|
||||
def loose(xs_ys):
|
||||
upload = str(uuid4())
|
||||
placements = [{'source_index': 0, 'copy_index': i, 'x_cm': x, 'y_cm': y, 'width_cm': 20, 'length_cm': 10,
|
||||
|
||||
83
tests/test_stretched_sheets.py
Normal file
83
tests/test_stretched_sheets.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""ops.stretched_sheets lists the ready sheets laid out wider than they are."""
|
||||
import io
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from ops import stretched_sheets
|
||||
|
||||
|
||||
def png(width, dpi=None):
|
||||
out = io.BytesIO()
|
||||
Image.new('RGBA', (width, 10)).save(out, 'PNG', **({'dpi': (dpi, dpi)} if dpi else {}))
|
||||
return out.getvalue()
|
||||
|
||||
|
||||
class Storage:
|
||||
bucket = 'b'
|
||||
|
||||
def __init__(self, blobs):
|
||||
self.blobs = blobs
|
||||
self.client = self
|
||||
|
||||
def get_object(self, Bucket, Key, Range):
|
||||
return {'Body': io.BytesIO(self.blobs[Key])}
|
||||
|
||||
|
||||
class Result:
|
||||
def __init__(self, rows):
|
||||
self.rows = rows
|
||||
|
||||
def fetchall(self):
|
||||
return self.rows
|
||||
|
||||
def fetchone(self):
|
||||
return self.rows[0] if self.rows else None
|
||||
|
||||
|
||||
class Connection:
|
||||
def __init__(self, orders, uploads):
|
||||
self.orders, self.uploads = orders, uploads
|
||||
|
||||
def execute(self, sql, params):
|
||||
if 'FROM dtf_local.orders' in sql:
|
||||
return Result(self.orders)
|
||||
return Result([self.uploads[params[0]]] if params[0] in self.uploads else [])
|
||||
|
||||
|
||||
def order(number, mode='file', width=57, upload='u', provider='mercadopago'):
|
||||
return {'id': number, 'number': number, 'payment': {'provider': provider}, 'created_at': None,
|
||||
'snapshot': {'items': [{'mode': mode, 'production': {'sources': [
|
||||
{'upload_id': upload, 'kind': 'sheet' if mode != 'avulsa' else 'artwork',
|
||||
'measurement': 'file', 'width_cm': width}]}}]}}
|
||||
|
||||
|
||||
class StretchedSheetsTests(unittest.TestCase):
|
||||
def run_with(self, orders, uploads, blobs):
|
||||
@contextmanager
|
||||
def connect():
|
||||
yield Connection(orders, uploads)
|
||||
lines = []
|
||||
stretched, unknown = stretched_sheets.main([], out=lines.append, storage=Storage(blobs), connect=connect)
|
||||
return stretched, unknown, lines
|
||||
|
||||
def test_only_sheets_laid_out_at_another_width_are_listed(self):
|
||||
uploads = {name: {'name': f'{name}.png', 'object_key': name, 'purged_at': None}
|
||||
for name in ('narrow', 'right', 'nodpi', 'gone', 'loose', 'test')}
|
||||
uploads['gone']['purged_at'] = '2026-11-20'
|
||||
blobs = {'narrow': png(4227, 300), 'right': png(6732, 300), 'nodpi': png(4227),
|
||||
'loose': png(1000, 300), 'test': png(4227, 300)}
|
||||
orders = [order(177, upload='narrow'), order(178, upload='right'), order(179, upload='nodpi'),
|
||||
order(180, upload='gone'), order(181, mode='avulsa', upload='loose'),
|
||||
order(182, upload='test', provider='teste')]
|
||||
stretched, unknown, lines = self.run_with(orders, uploads, blobs)
|
||||
self.assertEqual([row[0] for row in stretched], [177])
|
||||
self.assertIn('largura real 35,8 cm · montada com 57,0 cm · fator 1,59', '\n'.join(lines))
|
||||
self.assertEqual(len(unknown), 2)
|
||||
self.assertTrue(any('#179' in line and 'não grava o DPI' in line for line in unknown))
|
||||
self.assertTrue(any('#180' in line and 'apagado' in line for line in unknown))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -48,10 +48,13 @@ def item_with(uploads):
|
||||
'mode': 'file', 'metres': round(height / 100, 4), 'grade': 100, 'uploads': uploads,
|
||||
'production': {
|
||||
'version': 3, 'film_width_cm': 57, 'height_cm': height,
|
||||
# Measured by the customer (as a CDR's typed length): this test counts
|
||||
# sheets; the real-size rule (contrato-folha-real.md) is not its business.
|
||||
'sources': [{'upload_id': uid, 'kind': 'sheet', 'width_cm': 0.5, 'length_cm': 0.25,
|
||||
'copies': 1, 'rotation_degrees': 0, 'mirrored': False,
|
||||
'measurement': 'file'} for uid in uploads],
|
||||
'placements': [{'source_index': index, 'copy_index': 0, 'x_cm': 0,
|
||||
'measurement': 'customer'} for uid in uploads],
|
||||
# A sheet narrower than the film is centred on it.
|
||||
'placements': [{'source_index': index, 'copy_index': 0, 'x_cm': 28.25,
|
||||
'y_cm': round(index * step, 4), 'width_cm': 0.5, 'length_cm': 0.25,
|
||||
'rotation_degrees': 0, 'mirrored': False} for index in range(count)]},
|
||||
'quality_status': 'ok', 'quality_acknowledged': False, 'residue_accepted': 0}
|
||||
|
||||
Reference in New Issue
Block a user