feat: Premium built and switched off; default machine minimums (front 3, Marcus 10/11)

Premium (8 passadas, R$ 39,90/m, SKU DTFP.TX.100CM) is a fifth textile
ready-sheet product: priced on the server and the Site, a hidden fifth card,
a PREMIUM hot-folder class, its Tiny SKU, and a products row created
disabled by a migration until Dropstar says 'testado'. A machine with no
typed minimum now alerts at Dropstar's fixed minimums: 1 roll of film, 1 L
of each ink, 5 kg of powder.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 10:52:08 -03:00
parent e6197d6e40
commit a9a4b61d99
25 changed files with 202 additions and 49 deletions

View File

@@ -3,22 +3,35 @@
Run against the local stack: SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost
python -m tests.site_admin_test
"""
import io
import secrets
from datetime import datetime, timedelta, timezone
from uuid import uuid4
from PIL import Image, ImageDraw
from app.core import db
from tests.print_file_test import artwork
from tests.smoke_test import Client, item_spec, upload_bytes
PASSWORD = 'senha-de-teste-123'
UV = 'uv'
PREMIUM = 'premium'
def quote(client, item, mail):
def premium_sheet():
"""A 57 cm wide sheet above 96 DPI at that width, so the server accepts it."""
image = Image.new('RGBA', (2400, 800), (0, 0, 0, 0))
ImageDraw.Draw(image).rectangle([40, 40, 2360, 760], fill=(220, 30, 60, 255))
out = io.BytesIO()
image.save(out, 'PNG', dpi=(300, 300))
return out.getvalue()
def quote(client, item, mail, expected=200):
return client.call('/quotes', {'request_key': str(uuid4()),
'customer': {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': mail},
'items': [item], 'freight': {'service': 'pickup'}})
'items': [item], 'freight': {'service': 'pickup'}}, expected=expected)
def run():
@@ -34,9 +47,30 @@ def run():
prices, user = [], None
try:
products = manager.call('/operator/site/products')['products']
assert {product['id'] for product in products} == {'file', 'avulsa', 'uvfile', 'uv', 'tratamento'}
assert {product['id'] for product in products} == \
{'file', 'avulsa', 'uvfile', 'uv', 'premium', 'tratamento'}
assert all(product['unit'] in ('metro', 'pedido') and product['title'] for product in products)
# Front 3: Premium is listed and starts switched off (Marcus, 2026-11-10).
premium_entry = next(product for product in products if product['id'] == PREMIUM)
assert premium_entry['enabled'] is False, premium_entry
assert premium_entry['title'] == 'Têxtil Premium · 8 passadas', premium_entry
assert client.call('/session')['products'][PREMIUM]['enabled'] is False
premium_item = {**item_spec(PREMIUM, '1', 0, upload_bytes(
client, premium_sheet(), name='LOCAL-SITE-PREMIUM.png')),
'quality_status': 'warning', 'quality_acknowledged': True}
refused = quote(client, premium_item, mail, expected=422)
assert refused['detail'] == 'Este produto não está à venda agora.', refused
manager.call(f'/operator/site/products/{PREMIUM}', {'enabled': True})
assert client.call('/session')['products'][PREMIUM]['enabled'] is True
created = quote(client, premium_item, mail)
assert created['status'] == 'approved', created
approved = client.call('/quotes/' + created['id'])['approved']
assert approved['items'][0]['mode'] == PREMIUM, approved
assert approved['items'][0]['unit_cents'] == 3990, approved
assert approved['total_cents'] == 3990, approved
manager.call(f'/operator/site/products/{PREMIUM}', {'enabled': False})
manager.call(f'/operator/site/products/{UV}', {'enabled': True})
uid = upload_bytes(client, artwork(), name='LOCAL-SITE-ADMIN.png')
item = {**item_spec('uv', '1', 0, uid), 'quality_status': 'warning', 'quality_acknowledged': True}
@@ -123,13 +157,15 @@ def run():
staff.call(f'/operator/site/products/{UV}', {'enabled': True}, expected=403)
staff.call(f'/operator/site/products/{UV}/prices', {'unit_cents': 1000}, expected=403)
staff.call(f'/operator/site/prices/{made["id"]}/cancel', {}, expected=403)
print('PASS: the Site tab switches a product off and refuses quotes, schedules and cancels prices,'
' charges the new price, and refuses a non-manage profile')
print('PASS: the Site tab switches a product off and refuses quotes, lists Premium switched off'
' and accepts it once enabled, schedules and cancels prices, charges the new price,'
' and refuses a non-manage profile')
finally:
with db.connect() as c:
if prices:
c.execute('DELETE FROM dtf_local.product_prices WHERE id=ANY(%s::bigint[])', (prices,))
c.execute("UPDATE dtf_local.products SET enabled=true WHERE id=%s", (UV,))
c.execute("UPDATE dtf_local.products SET enabled=false WHERE id=%s", (PREMIUM,))
if user:
try:
manager.call('/operator/users/' + str(user['id']) + '/delete', {}, expected=200)