Files
dtf-system/tests/test_profiles.py
Cauê Faleiros 4c6e2aac4a
All checks were successful
Build and deploy / Validate source (push) Successful in 8s
Build and deploy / Integration suite on a real stack (push) Successful in 8m1s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m32s
feat: a user may have more than one profile, and may do what any of them may (Marcus, 2026-11-26)
operators.roles holds every profile, the main one first; permissions, moves,
the column order and the machine question are the sum. The operator's machine
rules apply only to the moves Operador alone allows, so an Operador who is also
Revisor releases any sheet (D-29 does not block, Marcus). Usuários gets
"Outros perfis" chips next to the main profile.

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

54 lines
2.5 KiB
Python

"""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()