"""Users with more than one profile (Marcus, 2026-11-26): what they may do is the sum of their profiles, and an operator's machine rules apply only to the moves that come from Operador. Run from the repository root: python3 -m unittest tests.test_profiles -v. """ import unittest from app.core.auth import has, machine_bound, machine_question, may_move, operator_only, roles_of from tests.test_moves import moves def user(*roles): return {'role': roles[0], 'roles': list(roles)} class ProfilesTest(unittest.TestCase): def test_moves_are_the_sum_of_the_profiles(self): self.assertEqual(moves(['operador', 'revisor']), moves('operador') | moves('revisor')) # Gestão and Operador: the coordination's pulls back, and the operator's moves forward. self.assertEqual(moves(['gestao', 'operador']), moves('gestao') | moves('operador')) self.assertTrue(may_move(['gestao', 'operador'], 'tra', 'imp')) self.assertFalse(may_move('gestao', 'tra', 'imp')) def test_operador_and_revisor_release_what_they_printed(self): # D-29 does not block a user with both profiles (Marcus, 2026-11-26). self.assertTrue(may_move(['operador', 'revisor'], 'rev', 'fin')) def test_the_machine_rules_follow_the_profile_that_allows_the_move(self): both = user('operador', 'revisor') self.assertTrue(machine_bound(both, 'tra', 'imp')) self.assertTrue(machine_bound(both, 'imp', 'rev')) self.assertFalse(machine_bound(both, 'rev', 'fin')) # as a Revisor, any machine self.assertFalse(machine_bound(user('gestao', 'operador'), 'imp', 'cor')) self.assertTrue(machine_bound(user('operador'), 'imp', 'rev')) self.assertFalse(machine_bound(user('admin'), 'tra', 'imp')) def test_capabilities_and_the_machine_question(self): both = user('operador', 'revisor') self.assertTrue(has(both, 'inspect') and has(both, 'print')) self.assertTrue(operator_only(both, 'print')) self.assertFalse(operator_only(user('gestao', 'operador'), 'print')) self.assertEqual(machine_question(user('operador')), 'required') self.assertEqual(machine_question(both), 'required') self.assertEqual(machine_question(user('gestao', 'operador', 'revisor')), 'optional') self.assertIsNone(machine_question(user('revisor'))) def test_a_row_from_before_the_list_has_its_one_profile(self): self.assertEqual(roles_of({'role': 'designer', 'roles': []}), ('designer',)) if __name__ == '__main__': unittest.main()