Files
dtf-system/tests/test_moves.py
Cauê Faleiros 2c80de0c0a feat: Montar creates the invoiced order card (front 7a.2b)
The montador sends each stamp to storage, splits the list into items of
at most 20 sources and 4000 copies, packs each one with the Site's engine
and creates the order in Arte recebida: typed customer, pickup, the Site's
table price, payment 'faturado', origin dropflow for Expedição and
atendimento otherwise. Until Dropstar decides, these orders do not go to
Tiny and the customer gets no paid e-mail. Vendedor and Expedição may now
upload through the operator upload routes (can_any).

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

92 lines
4.7 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_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()