feat: review photo or video in Revisão (front 2)
All checks were successful
Build and deploy / Validate source (push) Successful in 8s
Build and deploy / Integration suite on a real stack (push) Successful in 6m4s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m6s
All checks were successful
Build and deploy / Validate source (push) Successful in 8s
Build and deploy / Integration suite on a real stack (push) Successful in 6m4s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m6s
In Revisão the card gets "Revisar": a photo or a video of up to 30 s of the printed sheet, from the computer's or the phone's camera in the browser, or a file already recorded. It is attached to the order as DTF-<n>-revisao-<seq> with when and who, kept 180 days, and copied by the computers with the order folders to Kanban/Revisões/. A photo needs 1600 px on its longer side. An order above 1 m cannot reach Finalizado without one. In Finalizado the customer's order page shows the photo. The Revisor, Gestão and the administrators take it (capability "inspect"). Dialogs opened from a card's face or the board (Revisar, Editar tempos) now show over the page when the order panel is closed; inside the closed panel they were invisible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -250,6 +250,24 @@ try{
|
||||
await waitFor(async()=>(await savedFiles('1. Arte recebida')).some(n=>n.startsWith(early)&&!n.endsWith('.baixando')),'final file saved in Arte recebida',45000);
|
||||
assert.equal((await savedFiles('2. Arte conferida')).some(n=>n.startsWith(early)),false);
|
||||
}
|
||||
if(state==='fin'){
|
||||
// Above 1 m Finalizado needs the review photo (app/reviews.py). Take one
|
||||
// with a canvas in the page and send it as the Revisor's dialog does.
|
||||
const metres=await kanban.eval(`board.orders.find(o=>o.id==='${oid}').snapshot.items.reduce((t,i)=>t+Number(i.billed_metres),0)`);
|
||||
if(metres>1){
|
||||
await kanban.eval(`(async()=>{
|
||||
const order=board.orders.find(o=>o.id==='${oid}');
|
||||
const canvas=document.createElement('canvas');canvas.width=2000;canvas.height=1500;
|
||||
const ctx=canvas.getContext('2d');ctx.fillStyle='#c04030';ctx.fillRect(0,0,2000,1500);
|
||||
const blob=await new Promise(ok=>canvas.toBlob(ok,'image/jpeg',0.9));
|
||||
const file=new File([blob],'revisao.jpg',{type:'image/jpeg'});
|
||||
const uid=await dtfUpload(file,{api,startPath:'/orders/'+order.id+'/reviews/uploads',scope:'operator:review:'+order.id+':browser',progress:()=>{}});
|
||||
await api('/orders/'+order.id+'/reviews',{upload_id:uid});
|
||||
await load();
|
||||
})()`);
|
||||
await waitFor(()=>kanban.eval(`(board.orders.find(o=>o.id==='${oid}').reviews||[]).some(r=>r.kind==='photo')`),'review photo attached');
|
||||
}
|
||||
}
|
||||
await waitFor(()=>kanban.eval(`!!document.querySelector('[data-order="${oid}"] [data-move="${state}"]')`),'move to '+title);
|
||||
await kanban.click(`[data-order="${oid}"] [data-move="${state}"]`);
|
||||
await waitFor(()=>kanban.eval(`board.orders.find(o=>o.id==='${oid}').state==='${state}'`),'transition '+state);
|
||||
@@ -296,7 +314,7 @@ try{
|
||||
await kanban.eval('syncFolder(true)');
|
||||
await waitFor(async()=>!(await folders()).includes('3. Finalizado'),'old Finalizado folder removed',30000);
|
||||
const tree=await folders();
|
||||
for(const name of ['1. Arte recebida','2. Arte conferida','3. Imprimindo','4. Revisão','5. Finalizado','Recibos'])
|
||||
for(const name of ['1. Arte recebida','2. Arte conferida','3. Imprimindo','4. Revisão','5. Finalizado','Recibos','Revisões'])
|
||||
assert.ok(tree.includes(name),name+' missing from '+tree.join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
123
tests/review_media_test.py
Normal file
123
tests/review_media_test.py
Normal file
@@ -0,0 +1,123 @@
|
||||
"""The review photo or video attached to an order in Revisão (Fase 2, front 2).
|
||||
|
||||
Run against the local stack:
|
||||
SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost python -m tests.review_media_test
|
||||
"""
|
||||
from io import BytesIO
|
||||
from urllib.request import Request, urlopen
|
||||
from uuid import uuid4
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from tests.smoke_test import (Client, approved_quote, final_png_bytes, item_spec, review_photo,
|
||||
upload_bytes, wait_scan)
|
||||
|
||||
|
||||
def jpeg(width, height):
|
||||
out = BytesIO()
|
||||
Image.new('RGB', (width, height), (190, 60, 50)).save(out, 'JPEG', quality=80)
|
||||
return out.getvalue()
|
||||
|
||||
|
||||
def run():
|
||||
customer = Client()
|
||||
customer.call('/session')
|
||||
original = upload_bytes(customer, b'LOCAL REVIEW ORIGINAL')
|
||||
item = item_spec('file', '1.01', 0, original)
|
||||
profile = {'cnpj': '11222333000181', 'zap': '11999999999',
|
||||
'mail': 'review-' + uuid4().hex[:8] + '@example.test'}
|
||||
quote = customer.call('/quotes', {'request_key': str(uuid4()), 'customer': profile,
|
||||
'items': [item], 'freight': {'service': 'pickup'}})
|
||||
approved_quote(customer, quote, [item])
|
||||
order = customer.call('/orders/dev-paid', {'quote_id': quote['id']})
|
||||
oid, number = order['id'], order['number']
|
||||
|
||||
final = upload_bytes(customer, final_png_bytes('review final'), name='LOCAL-REVIEW-FINAL.png', order_id=oid)
|
||||
version = customer.call('/operator/orders/' + oid + '/final-files',
|
||||
{'version': 0, 'note': 'Conferido',
|
||||
'files': [{'item_index': 0, 'upload_id': final}]}, operator=True)['version']
|
||||
|
||||
machine = None
|
||||
|
||||
def move(state, version):
|
||||
nonlocal machine
|
||||
body = {'state': state, 'version': version, 'reason': ''}
|
||||
if state == 'imp':
|
||||
if machine is None:
|
||||
machine = customer.call('/operator/machines',
|
||||
{'name': 'Review ' + uuid4().hex[:6], 'products': ['textil']},
|
||||
operator=True)['id']
|
||||
body['machine_id'] = machine
|
||||
return customer.call('/operator/orders/' + oid + '/move', body, operator=True)['version']
|
||||
|
||||
for state in ('tra', 'imp', 'rev'):
|
||||
version = move(state, version)
|
||||
|
||||
def upload_raw(name, content):
|
||||
start = customer.call('/operator/orders/' + oid + '/reviews/uploads',
|
||||
{'name': name, 'size': len(content)}, operator=True)
|
||||
uid = start['id']
|
||||
url = customer.call('/operator/uploads/' + uid + '/parts/1', {}, operator=True)['url']
|
||||
with urlopen(Request(url, data=content, method='PUT'), timeout=30) as response:
|
||||
assert response.status == 200
|
||||
customer.call('/operator/uploads/' + uid + '/complete', {}, operator=True)
|
||||
wait_scan(customer, uid, operator=True)
|
||||
return uid
|
||||
|
||||
def add_raw(uid, expected=200):
|
||||
return customer.call('/operator/orders/' + oid + '/reviews', {'upload_id': uid},
|
||||
operator=True, expected=expected)
|
||||
|
||||
# Above 1 m without a photo the order does not reach Finalizado.
|
||||
customer.call('/operator/orders/' + oid + '/move', {'state': 'fin', 'version': version},
|
||||
operator=True, expected=409)
|
||||
|
||||
# A photo below 1600 px on the longer side is refused.
|
||||
small = upload_raw('LOCAL-SMALL.jpg', jpeg(800, 600))
|
||||
add_raw(small, expected=422)
|
||||
|
||||
# The extension must match the content: a PNG named .jpg is refused.
|
||||
fake = upload_raw('LOCAL-FAKE.jpg', final_png_bytes('fake'))
|
||||
add_raw(fake, expected=422)
|
||||
|
||||
# A real 2000x1500 JPEG becomes DTF-<n>-revisao-1.jpg.
|
||||
row = review_photo(customer, oid)
|
||||
assert row['seq'] == 1 and row['kind'] == 'photo', row
|
||||
assert row['name'] == 'DTF-%d-revisao-1.jpg' % number, row
|
||||
|
||||
board = customer.call('/operator/board', operator=True)
|
||||
saved = next(o for o in board['orders'] if o['id'] == oid)
|
||||
assert [(r['seq'], r['kind'], r['name']) for r in saved['reviews']] == [(1, 'photo', row['name'])], saved['reviews']
|
||||
|
||||
folder = customer.call('/operator/queue/folder', {'early': True}, operator=True)
|
||||
entry = next(r for r in folder['reviews'] if r['upload_id'] == row['upload_id'])
|
||||
assert entry['name'] == row['name'] and entry['order'] == oid and entry['number'] == number, entry
|
||||
|
||||
# The customer sees no photo while the order is still in Revisão.
|
||||
assert customer.call('/customer/orders/' + oid)['reviews'] == []
|
||||
|
||||
# A second review can be removed only while the order is in Revisão.
|
||||
second = review_photo(customer, oid)
|
||||
assert second['seq'] == 2, second
|
||||
customer.call('/operator/orders/' + oid + '/reviews/' + str(second['id']) + '/remove', {},
|
||||
operator=True)
|
||||
|
||||
# With the photo the order finishes, and the customer then sees it.
|
||||
version = move('fin', version)
|
||||
detail = customer.call('/customer/orders/' + oid)
|
||||
assert detail['state'] == 'fin'
|
||||
assert [(r['id'], r['name']) for r in detail['reviews']] == [(row['id'], row['name'])], detail['reviews']
|
||||
view = customer.call('/customer/orders/' + oid + '/reviews/' + str(row['id']) + '/view')
|
||||
assert view['kind'] == 'photo' and view['name'] == row['name']
|
||||
with urlopen(view['url'], timeout=30) as response:
|
||||
assert Image.open(BytesIO(response.read())).size == (2000, 1500)
|
||||
|
||||
# Once Finalizado, a review can no longer be removed.
|
||||
customer.call('/operator/orders/' + oid + '/reviews/' + str(row['id']) + '/remove', {},
|
||||
operator=True, expected=409)
|
||||
|
||||
print('PASS: review photo upload, signature and size checks, the 1 m rule, the folder and the customer view')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
@@ -105,6 +105,26 @@ def upload_bytes(client, content, name='LOCAL-TEST.cdr', order_id=None, expected
|
||||
wait_scan(client,uid,operator,expected_scan)
|
||||
return uid
|
||||
|
||||
def review_photo(client, order_id):
|
||||
"""A 2000x1500 JPEG attached as the order's review photo, in Revisão.
|
||||
|
||||
The same transport site_video_test uses: start the operator upload, PUT the
|
||||
single part, complete it, wait for the scan, then POST the review."""
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
out=BytesIO()
|
||||
Image.new('RGB',(2000,1500),(200,80,40)).save(out,'JPEG',quality=85)
|
||||
content=out.getvalue()
|
||||
start=client.call('/operator/orders/'+order_id+'/reviews/uploads',
|
||||
{'name':'revisao.jpg','size':len(content)},operator=True)
|
||||
uid=start['id']
|
||||
url=client.call('/operator/uploads/'+uid+'/parts/1',{},operator=True)['url']
|
||||
with urlopen(Request(url,data=content,method='PUT'),timeout=30) as response:
|
||||
assert response.status==200
|
||||
client.call('/operator/uploads/'+uid+'/complete',{},operator=True)
|
||||
wait_scan(client,uid,operator=True)
|
||||
return client.call('/operator/orders/'+order_id+'/reviews',{'upload_id':uid},operator=True)
|
||||
|
||||
def item_spec(mode, metres, grade, uid):
|
||||
film_width=27 if mode in ('uvfile','uv') else 57
|
||||
length_cm=float(metres)*100
|
||||
@@ -304,6 +324,8 @@ def run():
|
||||
if machine is None:
|
||||
machine=client.call('/operator/machines',{'name':'Smoke '+uuid4().hex[:6],'products':['textil']},operator=True)['id']
|
||||
body['machine_id']=machine
|
||||
# Above 1 m Finalizado needs the review photo (app/reviews.py).
|
||||
if state=='fin':review_photo(client,oid)
|
||||
moved=client.call('/operator/orders/'+oid+'/move',body,operator=True)
|
||||
version+=1;assert moved['version']==version
|
||||
client.call('/operator/orders/'+oid+'/move',{'state':'rec','version':0},operator=True,expected=409)
|
||||
@@ -315,6 +337,7 @@ def run():
|
||||
client.call('/operator/orders/'+oid+'/move',{'state':'imp','version':version},operator=True,expected=409)
|
||||
back=client.call('/operator/orders/'+oid+'/move',{'state':'rev','version':version,'reason':'Movido por engano'},operator=True)
|
||||
assert back['state']=='rev';version+=1
|
||||
review_photo(client,oid)
|
||||
client.call('/operator/orders/'+oid+'/move',{'state':'fin','version':version},operator=True);version+=1
|
||||
history=client.call('/operator/orders/'+oid+'/history',operator=True)
|
||||
assert len(history)==8 and history[-2]['back'] and history[-2]['reason']=='Movido por engano' and not history[-1]['back']
|
||||
|
||||
@@ -11,7 +11,7 @@ from psycopg.types.json import Jsonb
|
||||
|
||||
from app import payments, proof
|
||||
from app.core import db
|
||||
from tests.smoke_test import BASE, Client, with_host
|
||||
from tests.smoke_test import BASE, Client, with_host, review_photo
|
||||
|
||||
PASSWORD = 'senha-de-teste-123'
|
||||
|
||||
@@ -203,7 +203,7 @@ def run():
|
||||
'password': PASSWORD})
|
||||
reviewer = signed_in(emails['revisor'])
|
||||
me = reviewer.call('/operator/me')
|
||||
assert me['can'] == ['deliver', 'view'] and sorted(me['moves']) == [['fin', 'rev'], ['rev', 'fin']] and me['reorder'] == ['rev'], me
|
||||
assert me['can'] == ['deliver', 'inspect', 'view'] and sorted(me['moves']) == [['fin', 'rev'], ['rev', 'fin']] and me['reorder'] == ['rev'], me
|
||||
reviewer.call(f'/operator/orders/{textil_o}/move', {'state': 'tra', 'version': 0, 'reason': ''}, expected=403)
|
||||
assert reviewer.call(f'/operator/orders/{uv_o}/move', {'state': 'fin', 'version': printed['version'],
|
||||
'reason': ''})['state'] == 'fin'
|
||||
@@ -274,6 +274,8 @@ def run():
|
||||
version = su.call(f'/operator/orders/{long_o}/proof', {}, operator=True)['version']
|
||||
board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']}
|
||||
assert board[str(long_o)]['proof_ok_at'] and board[str(long_o)]['proof_ok_by']
|
||||
# Above 1 m Finalizado also needs the review photo (app/reviews.py).
|
||||
review_photo(su, str(long_o))
|
||||
su.call(f'/operator/orders/{long_o}/move', {'state': 'fin', 'version': version, 'reason': ''}, operator=True)
|
||||
# Up to 10 m, nothing to wait for.
|
||||
with db.connect() as c:
|
||||
@@ -281,6 +283,8 @@ def run():
|
||||
made.append((short_q, short_o))
|
||||
c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s", (short_o,))
|
||||
version = next(o for o in su.call('/operator/board', operator=True)['orders'] if o['id'] == str(short_o))['version']
|
||||
# 10 m is above the 1 m review photo rule just the same.
|
||||
review_photo(su, str(short_o))
|
||||
su.call(f'/operator/orders/{short_o}/move', {'state': 'fin', 'version': version, 'reason': ''}, operator=True)
|
||||
# Asked for at checkout: the paid order arrives waiting for the customer's word.
|
||||
with db.connect() as c:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os
|
||||
from uuid import uuid4
|
||||
from urllib.request import urlopen
|
||||
from tests.smoke_test import Client, approved_quote, upload_bytes, item_spec, register, final_png_bytes
|
||||
from tests.smoke_test import Client, approved_quote, upload_bytes, item_spec, register, final_png_bytes, review_photo
|
||||
|
||||
def run():
|
||||
customer=Client();other=Client();customer.call('/session');other.call('/session')
|
||||
@@ -111,7 +111,10 @@ def run():
|
||||
assert treated()=={'items':[0],'by':operator_email}, treated()
|
||||
stats=customer.call('/operator/stats?days=7',operator=True)['treated']
|
||||
assert stats['orders']>=1 and any(t['orders']>=1 for t in stats['by']), stats
|
||||
for state in ('tra','imp','rev','fin'):version=move(state,version)
|
||||
for state in ('tra','imp','rev','fin'):
|
||||
# Above 1 m Finalizado needs the review photo (app/reviews.py).
|
||||
if state=='fin':review_photo(customer,oid)
|
||||
version=move(state,version)
|
||||
# In the queue the finals stay as approved.
|
||||
customer.call('/operator/orders/'+oid+'/final-files',{'version':version,'files':[{'item_index':0,'upload_id':new_final}],'note':'Too late'},operator=True,expected=409)
|
||||
detail=other.call('/customer/orders/'+oid)
|
||||
|
||||
Reference in New Issue
Block a user