def testPrincipalRoleDeny(self): role = defineRole('ARole', 'A Role').id principal = self._make_principal() principalRoleManager.removeRoleFromPrincipal(role, principal) self.assertEqual(principalRoleManager.getPrincipalsForRole(role), [(principal, Deny)]) self.assertEqual(principalRoleManager.getRolesForPrincipal(principal), [(role, Deny)])
def testPrincipalRoleAllow(self): role = defineRole('ARole', 'A Role').id principal = self._make_principal() principalRoleManager.assignRoleToPrincipal(role, principal) self.assertEqual(principalRoleManager.getPrincipalsForRole(role), [(principal, Allow)]) self.assertEqual(principalRoleManager.getRolesForPrincipal(principal), [(role, Allow)])
def test_RolePrincipalMap(self): principals = principal_role_mgr.getPrincipalsForRole("zope.Bar") roles = principal_role_mgr.getRolesForPrincipal("zope.Blah") self.assertEqual(len(principals), 1) self.assertTrue(("zope.Blah", Deny) in principals) self.assertEqual(len(roles), 1) self.assertTrue(("zope.Bar", Deny) in roles)
def testManyRolesOnePrincipal(self): role1 = defineRole('Role One', 'Role #1').id role2 = defineRole('Role Two', 'Role #2').id prin1 = self._make_principal() principalRoleManager.assignRoleToPrincipal(role1, prin1) principalRoleManager.assignRoleToPrincipal(role2, prin1) roles = principalRoleManager.getRolesForPrincipal(prin1) self.assertEqual(len(roles), 2) self.assertTrue((role1, Allow) in roles) self.assertTrue((role2, Allow) in roles)
def testPrincipalRoleUnset(self): role = defineRole('ARole', 'A Role').id principal = self._make_principal() principalRoleManager.removeRoleFromPrincipal(role, principal) principalRoleManager.unsetRoleForPrincipal(role, principal) self.assertEqual(principalRoleManager.getPrincipalsForRole(role), []) self.assertEqual(principalRoleManager.getRolesForPrincipal(principal), []) self.assertEqual(principalRoleManager.getSetting(principal, role), Unset) self.assertEqual(principalRoleManager.getSetting(principal, role, 1), 1)
def testUnboundPrincipalRole(self): role = defineRole('ARole', 'A Role').id principal = self._make_principal() self.assertEqual(principalRoleManager.getPrincipalsForRole(role), []) self.assertEqual(principalRoleManager.getRolesForPrincipal(principal), [])