Files
dtf-system/tests/test_label.py
Cauê Faleiros 223bd61798 feat: the 10x15 label at Finalizado (Marcus 10/11, point 10)
When an order reaches Finalizado, the Kanban on the computer that opted in
(Integrações > Etiqueta 10x15) prints a 10x15 label rendered by the server:
the Tiny order number in large type (DTF-<n> when there is none), customer,
DTF · N folhas · X m, the delivery line, date and time, the Revisor and a
QR with the number. One automatic print per order (label_prints, claimed
once); Revisor, Expedição, Gestão and the administrators can reprint.
Chrome with --kiosk-printing prints without the dialog.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-11 11:32:27 -03:00

81 lines
3.7 KiB
Python

"""The 10x15 label's fields and page (Fase 2, front 10), without a database."""
import importlib.util
import unittest
from datetime import datetime, timezone
from app.label import label_fields, label_html
HAS_SEGNO = importlib.util.find_spec('segno') is not None
def order(**snapshot):
content = {'customer': {'name': 'Cliente Etiqueta', 'mail': 'cliente@example.test'},
'items': [{'billed_metres': '1.5'}, {'billed_metres': '1'}],
'destination': {'recipient': 'Loja Etiqueta'},
'freight': {'service': 'jadlog', 'description': 'Jadlog .Package'}}
content.update(snapshot)
return {'number': 42, 'snapshot': content}
FINISHED = datetime(2026, 11, 11, 17, 32, tzinfo=timezone.utc)
class LabelFieldsTest(unittest.TestCase):
def test_the_order_number_falls_back_to_dtf_when_tiny_did_not_answer(self):
fields = label_fields(order(), None, FINISHED, 'Revisor Etiqueta')
self.assertEqual(fields['code'], 'DTF-42')
self.assertEqual(fields['qr'], 'DTF-42')
fields = label_fields(order(), '98765', FINISHED, 'Revisor Etiqueta')
self.assertEqual(fields['code'], '98765')
self.assertEqual(fields['qr'], '98765')
def test_customer_sheets_and_billed_metres(self):
fields = label_fields(order(), '98765', FINISHED, 'Revisor Etiqueta')
self.assertEqual(fields['customer'], 'Cliente Etiqueta')
self.assertEqual(fields['sheets'], 2)
self.assertEqual(fields['metres'], '2,50')
self.assertEqual(fields['finished_at'], '11/11/2026 14:32')
self.assertEqual(fields['revisor'], 'Revisor Etiqueta')
def test_pickup_shipping_interno_and_junto_com_a_roupa(self):
pickup = order(destination=None, freight={'service': 'pickup'})
self.assertEqual(label_fields(pickup, None, FINISHED, None)['delivery'], 'Retirada')
self.assertEqual(label_fields(order(), None, FINISHED, None)['delivery'],
'Envio · Jadlog .Package')
self.assertEqual(label_fields(order(kind='interno'), None, FINISHED, None)['delivery'], 'Interno')
self.assertEqual(label_fields(order(with_order='4321'), None, FINISHED, None)['delivery'],
'Junto com pedido de roupa nº 4321')
# The internal customer's name is the one on the label.
self.assertEqual(label_fields(order(kind='interno', destination=None), None, FINISHED, None)['customer'],
'Cliente Etiqueta')
class LabelHtmlTest(unittest.TestCase):
@unittest.skipUnless(HAS_SEGNO, 'segno is installed with the API image')
def test_the_page_is_sized_for_the_10x15_label(self):
fields = label_fields(order(), '98765', FINISHED, 'Revisor Etiqueta')
page = label_html(fields)
self.assertIn('@page { size: 100mm 150mm; margin: 0 }', page)
self.assertIn('98765', page)
self.assertIn('Cliente Etiqueta', page)
self.assertIn('DTF · 2 folhas · 2,50 m', page)
self.assertIn('Envio · Jadlog .Package', page)
self.assertIn('Finalizado em 11/11/2026 14:32', page)
self.assertIn('Revisor: Revisor Etiqueta', page)
self.assertIn('<svg', page)
# The viewBox lets the CSS print the QR at 30 mm; a fixed pixel width
# would leave the modules tiny.
self.assertIn('viewBox=', page)
@unittest.skipUnless(HAS_SEGNO, 'segno is installed with the API image')
def test_the_customer_name_is_escaped(self):
fields = label_fields(order(customer={'name': '<b>Loja</b>', 'mail': 'x@example.test'}),
None, FINISHED, None)
page = label_html(fields)
self.assertIn('&lt;b&gt;Loja&lt;/b&gt;', page)
self.assertNotIn('<b>Loja</b>', page)
if __name__ == '__main__':
unittest.main()