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:
@@ -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)
|
||||
|
||||
@@ -131,7 +131,7 @@ def item_spec(mode, metres, grade, uid):
|
||||
return {'mode':mode,'metres':str(metres),'grade':grade,'uploads':[uid],
|
||||
'production':{'version':2,'film_width_cm':film_width,'height_cm':length_cm,
|
||||
'sources':[{'upload_id':uid,
|
||||
'kind':'sheet' if mode in ('file','uvfile') else 'artwork',
|
||||
'kind':'sheet' if mode in ('file','uvfile','premium') else 'artwork',
|
||||
'width_cm':film_width,'length_cm':length_cm,'copies':1,
|
||||
'rotation_degrees':0,'mirrored':False,'measurement':'customer'}],
|
||||
'placements':[{'source_index':0,'copy_index':0,'x_cm':0,'y_cm':0,
|
||||
|
||||
26
tests/test_hotfolder.py
Normal file
26
tests/test_hotfolder.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""The machine hot folder class (Fase 2, front 3), without a database."""
|
||||
import unittest
|
||||
|
||||
from app.hotfolder import PREMIUM, contraction, folder_class
|
||||
|
||||
|
||||
def order(mode, stroke_class='C2', chosen=None):
|
||||
return {'snapshot': {'items': [{'mode': mode, 'stroke_class': stroke_class}]},
|
||||
'contraction': {'0': {'class': chosen}} if chosen else {}}
|
||||
|
||||
|
||||
class FolderClassTest(unittest.TestCase):
|
||||
def test_premium_always_goes_to_its_own_folder(self):
|
||||
# Marcus, 2026-11-10: every premium item, whatever its contraction class.
|
||||
self.assertEqual(folder_class(order('premium', 'C3'), 0), PREMIUM)
|
||||
self.assertEqual(folder_class(order('premium', 'C1', chosen='C2'), 0), PREMIUM)
|
||||
|
||||
def test_a_recorded_contraction_class_still_wins_for_other_products(self):
|
||||
self.assertEqual(folder_class(order('file', 'C1', chosen='C2'), 0), 'C2')
|
||||
self.assertEqual(folder_class(order('file'), 0), 'C2')
|
||||
self.assertIsNone(contraction(order('file', None), 0))
|
||||
self.assertIsNone(folder_class(order('file', None), 0))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2,8 +2,8 @@
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
|
||||
from app.machine_log import (ALIGN_AFTER_FILM_METRES, CLEAN_EVERY_METRES, estimate,
|
||||
one_decimal, supply_low)
|
||||
from app.machine_log import (ALIGN_AFTER_FILM_METRES, CLEAN_EVERY_METRES, DEFAULT_MINIMUMS,
|
||||
estimate, minimum_for, one_decimal, supply_low)
|
||||
|
||||
|
||||
class EstimateTest(unittest.TestCase):
|
||||
@@ -38,6 +38,22 @@ class EstimateTest(unittest.TestCase):
|
||||
self.assertEqual(CLEAN_EVERY_METRES, Decimal('10'))
|
||||
self.assertEqual(ALIGN_AFTER_FILM_METRES, Decimal('20'))
|
||||
|
||||
def test_a_machine_without_typed_minimums_alerts_at_dropstars_defaults(self):
|
||||
# Marcus, 2026-11-10: 1 roll of film, 1 L of each ink, 5 kg of powder.
|
||||
self.assertEqual(DEFAULT_MINIMUMS, {'film': Decimal('1'), 'ink_c': Decimal('1'),
|
||||
'ink_m': Decimal('1'), 'ink_y': Decimal('1'),
|
||||
'ink_k': Decimal('1'), 'ink_w': Decimal('1'),
|
||||
'powder': Decimal('5')})
|
||||
for item, default in DEFAULT_MINIMUMS.items():
|
||||
with self.subTest(item=item):
|
||||
minimum = minimum_for({}, item)
|
||||
self.assertEqual(minimum, default)
|
||||
value = estimate([Decimal('1'), Decimal('1')], [Decimal('10')],
|
||||
Decimal('9'), minimum)
|
||||
self.assertTrue(supply_low(value))
|
||||
# A minimum Gestão typed still wins over the default.
|
||||
self.assertEqual(minimum_for({'film': Decimal('0')}, 'film'), Decimal('0'))
|
||||
|
||||
|
||||
class AlertTextTest(unittest.TestCase):
|
||||
def test_one_decimal_uses_a_comma(self):
|
||||
|
||||
@@ -34,8 +34,9 @@ class PricingTests(unittest.TestCase):
|
||||
|
||||
def test_one_price_per_product(self):
|
||||
# Dropstar, 2026-10-23: textile R$ 19,90 ready sheet and R$ 21,90 loose
|
||||
# art; UV R$ 79,90 and R$ 89,90.
|
||||
self.assertEqual(PRICES, {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990})
|
||||
# art; UV R$ 79,90 and R$ 89,90. Premium R$ 39,90 (2026-11-10).
|
||||
self.assertEqual(PRICES, {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990,
|
||||
'premium': 3990})
|
||||
self.assertEqual(price('avulsa', '2.75', 90)['total_cents'], 6132)
|
||||
|
||||
def test_the_grade_never_changes_the_price(self):
|
||||
|
||||
@@ -794,6 +794,9 @@ class DefaultSkuTests(unittest.TestCase):
|
||||
self.assertEqual(tiny.mode_codes('file'), tiny.sku_codes('DTFIMP.TX'))
|
||||
self.assertEqual(tiny.mode_codes('avulsa'), tiny.sku_codes('DTFIMP.TX'))
|
||||
self.assertEqual(tiny.mode_codes('uv'), ['DTFIMP.UV.1MT', 'DTFIMP.UV.010CM'])
|
||||
# Premium's own catalogue: DTFP.TX.100CM per metre (front 3).
|
||||
self.assertEqual(tiny.mode_codes('premium'), tiny.sku_codes('DTFP.TX'))
|
||||
self.assertIn('DTFP.TX.100CM', tiny.mode_codes('premium'))
|
||||
self.assertEqual(tiny.required_settings(), ['TINY_CLIENT_ID', 'TINY_CLIENT_SECRET', 'TINY_REDIRECT_URI'])
|
||||
with mock.patch.dict(os.environ, {'TINY_SKU10_UV_FOLHA': 'UV.X'}):
|
||||
self.assertEqual(tiny.mode_codes('uvfile'), ['UV.X'])
|
||||
|
||||
Reference in New Issue
Block a user