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 testManyPrincipalsOneRole(self):
     role1 = defineRole('Role One', 'Role #1').id
     prin1 = self._make_principal()
     prin2 = self._make_principal('Principal 2', 'Principal Two')
     principalRoleManager.assignRoleToPrincipal(role1, prin1)
     principalRoleManager.assignRoleToPrincipal(role1, prin2)
     principals = principalRoleManager.getPrincipalsForRole(role1)
     self.assertEqual(len(principals), 2)
     self.assertTrue((prin1, Allow) in principals)
     self.assertTrue((prin2, Allow) in principals)
 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),
                      [])