Files
dtf-system/tests/test_moves.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

101 lines
5.3 KiB
Python

"""Who moves which card on the Kanban: Dropstar's flow of 2026-10-23."""
import unittest
from unittest import mock
from app import payments
from app.core import auth
from app.core.auth import CAPABILITIES, ROLES, may_move, may_reorder
from app.runtime import BACK, STATES, TRANSITIONS
def moves(role):
return {(a, b) for a, nexts in TRANSITIONS.items() for b in nexts if may_move(role, a, b)}
class MovesTest(unittest.TestCase):
def test_the_board(self):
# Fila de impressão left: Arte conferida is the queue; Revisão before Finalizado.
self.assertEqual(list(STATES), ['rec', 'tra', 'imp', 'cor', 'rev', 'fin'])
self.assertEqual(BACK, {'tra': 'rec', 'imp': 'tra', 'rev': 'imp', 'fin': 'rev'})
self.assertIn('revisor', ROLES)
def test_each_profile_moves_its_part(self):
self.assertEqual(moves('designer'), {('rec', 'tra'), ('rec', 'cor'), ('tra', 'cor'), ('cor', 'rec'), ('cor', 'tra')})
self.assertEqual(moves('operador'), {('tra', 'imp'), ('imp', 'rev')})
self.assertEqual(moves('revisor'), {('rev', 'fin')})
self.assertEqual(moves('vendedor'), set())
# Gestão, the coordination, pulls back and never forward (D-20): Correção
# from any stage, and steps back. Admin, Dropstar's login, moves forward too.
self.assertEqual(moves('gestao'), {('rec', 'cor'), ('tra', 'cor'), ('imp', 'cor'), ('rev', 'cor')})
for pair in (('tra', 'imp'), ('rec', 'tra'), ('cor', 'rev'), ('cor', 'tra'), ('imp', 'rev')):
self.assertFalse(may_move('gestao', *pair), pair)
self.assertTrue(may_move('admin', *pair), pair)
def test_the_revisor_and_the_administrator_release_to_finalizado(self):
for role in ROLES:
self.assertEqual(may_move(role, 'rev', 'fin'), role in ('revisor', 'admin', 'superadmin'), role)
def test_a_step_back_belongs_to_whoever_makes_the_move_it_undoes(self):
self.assertTrue(may_move('operador', 'rev', 'imp', back=True))
self.assertTrue(may_move('operador', 'imp', 'tra', back=True))
self.assertFalse(may_move('operador', 'tra', 'rec', back=True))
self.assertTrue(may_move('designer', 'tra', 'rec', back=True))
self.assertTrue(may_move('revisor', 'fin', 'rev', back=True))
self.assertTrue(may_move('gestao', 'fin', 'rev', back=True))
self.assertFalse(may_move('vendedor', 'tra', 'rec', back=True))
def test_expedicao_moves_nothing(self):
# The new shipping profile assembles sheets (Fase 2, front 7) and reads
# the board; it moves no card and orders no column.
self.assertIn('expedicao', ROLES)
self.assertEqual(moves('expedicao'), set())
self.assertEqual([s for s in STATES if may_reorder('expedicao', s)], [])
def test_the_montador_is_open_to_exactly_five_profiles(self):
self.assertEqual(CAPABILITIES['assemble'],
{'superadmin', 'admin', 'gestao', 'vendedor', 'expedicao'})
def test_the_label_is_printed_by_these_profiles(self):
# Marcus, 2026-11-10: the Revisor who releases the card, Expedição and
# Gestão; the designer, the operator and the seller do not print it.
self.assertEqual(CAPABILITIES['label'],
{'superadmin', 'admin', 'gestao', 'revisor', 'expedicao'})
for role in ROLES:
self.assertEqual(role in CAPABILITIES['label'],
role in ('superadmin', 'admin', 'gestao', 'revisor', 'expedicao'), role)
def test_a_column_is_ordered_by_whoever_takes_its_cards_forward(self):
self.assertEqual([s for s in STATES if may_reorder('operador', s)], ['tra', 'imp'])
self.assertEqual([s for s in STATES if may_reorder('designer', s)], ['rec', 'cor'])
self.assertEqual([s for s in STATES if may_reorder('revisor', s)], ['rev'])
self.assertEqual([s for s in STATES if may_reorder('vendedor', s)], [])
self.assertTrue(all(may_reorder('gestao', s) for s in STATES))
class CanAnyTest(unittest.TestCase):
def test_a_profile_with_any_of_the_capabilities_gets_through(self):
# The montador's stamp uploads: deliver or assemble (Fase 2, front 7).
for role, allowed in (('operador', True), ('expedicao', True), ('vendedor', True),
('designer', True), ('financeiro', False)):
with mock.patch.object(auth, 'signed_in',
return_value={'role': role, 'email': role + '@example.test'}):
route = auth.can_any('deliver', 'assemble')
if allowed:
self.assertEqual(route(None), role + '@example.test')
else:
with self.assertRaises(auth.HTTPException):
route(None)
class InvoicedOrderTest(unittest.TestCase):
def test_an_invoiced_montador_order_is_held_out_of_tiny(self):
self.assertEqual(payments.INVOICED_METHOD, 'faturado')
# It is not one of the Cotações "registrar" methods.
self.assertNotIn(payments.INVOICED_METHOD, payments.OUTSIDE_METHODS)
self.assertFalse(payments.in_tiny({'payment': {'provider': 'manual', 'method': 'faturado'}}))
self.assertTrue(payments.in_tiny({'payment': {'provider': 'manual', 'method': 'pix'}}))
if __name__ == '__main__':
unittest.main()