def test_has_permissions_all_multiple_permissions(self): """ Test the has_permissions_all() method if a role has the requested permission (and others). Expected result: `True` when requesting the set permissions. """ role = Role('Administrator') role._permissions = (Permission.EditRole | Permission.EditUser).value self.assertTrue(role.has_permissions_all(Permission.EditRole)) self.assertTrue(role.has_permissions_all(Permission.EditUser)) self.assertTrue(role.has_permissions_all(Permission.EditRole, Permission.EditUser, Permission(0)))
def test_has_permissions_all_empty_permission(self): """ Test the has_permissions_all() method with the empty permission. Expected result: `False`. """ role = Role('Administrator') db.session.add(role) db.session.commit() self.assertEqual(0, role._permissions) self.assertFalse(role.has_permissions_all(Permission(0))) role._permissions = Permission.EditRole.value self.assertFalse(role.has_permissions_all(Permission(0)))
def test_has_permissions_all_multiple_permissions(self): """ Test the has_permissions_all() method if a role has the requested permission (and others). Expected result: `True` when requesting the set permissions. """ role = Role('Administrator') role._permissions = (Permission.EditRole | Permission.EditUser).value self.assertTrue(role.has_permissions_all(Permission.EditRole)) self.assertTrue(role.has_permissions_all(Permission.EditUser)) self.assertTrue( role.has_permissions_all(Permission.EditRole, Permission.EditUser, Permission(0)))
def test_has_permissions_all_empty_permission(self): """ Test the has_permissions_all() method with the empty permission. Expected result: `False`. """ role = Role('Administrator') db.session.add(role) db.session.commit() self.assertEqual(0, role._permissions) self.assertTrue(role.has_permissions_all(Permission(0))) role.permissions = Permission.EditRole self.assertTrue(role.has_permissions_all(Permission(0)))
def test_has_permissions_all_single_permission(self): """ Test the has_permissions_all() method if a role has the requested permission (and only this one). Expected result: `True` when requesting this permission, `False` otherwise. """ role = Role('Administrator') role.permissions = Permission.EditRole self.assertTrue(role.has_permissions_all(Permission.EditRole)) self.assertFalse(role.has_permissions_all(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse( role.has_permissions_all(Permission.EditRole | Permission.EditUser)) role.permissions = Permission.EditUser self.assertFalse(role.has_permissions_all(Permission.EditRole)) self.assertTrue(role.has_permissions_all(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse( role.has_permissions_all(Permission.EditRole | Permission.EditUser))
def test_has_permissions_all_no_permissions(self): """ Test the has_permissions_all() method if a role does not have any permissions. Expected result: `False`. """ role = Role('Administrator') db.session.add(role) db.session.commit() self.assertEqual(0, role._permissions) self.assertFalse(role.has_permissions_all(Permission.EditRole)) self.assertFalse(role.has_permissions_all(Permission.EditUser))
def test_has_permissions_all_no_permissions(self): """ Test the has_permissions_all() method if a role does not have any permissions. Expected result: `False`. """ role = Role('Administrator') db.session.add(role) db.session.commit() self.assertEqual(0, role._permissions) self.assertFalse(role.has_permissions_all(Permission.EditRole)) self.assertFalse(role.has_permissions_all(Permission.EditUser))
def test_has_permissions_all_single_permission(self): """ Test the has_permissions_all() method if a role has the request permission (and only this one). Expected result: `True` when requesting this permission, `False` otherwise. """ role = Role('Administrator') role._permissions = Permission.EditRole.value self.assertTrue(role.has_permissions_all(Permission.EditRole)) self.assertFalse(role.has_permissions_all(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse(role.has_permissions_all(Permission.EditRole | Permission.EditUser)) role._permissions = Permission.EditUser.value self.assertFalse(role.has_permissions_all(Permission.EditRole)) self.assertTrue(role.has_permissions_all(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse(role.has_permissions_all(Permission.EditRole | Permission.EditUser))