def test_has_permission_empty_permission(self): """ Test the has_permission() method if a role with the empty permission. Expected result: `True`. """ role = Role('Administrator') db.session.add(role) db.session.commit() self.assertEqual(0, role._permissions) self.assertTrue(role.has_permission(Permission(0))) role.permissions = Permission.EditRole self.assertTrue(role.has_permission(Permission(0)))
def test_has_permission_no_permissions(self): """ Test the has_permission() 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_permission(Permission.EditRole)) self.assertFalse(role.has_permission(Permission.EditUser))
def test_has_permission_no_permissions(self): """ Test the has_permission() 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_permission(Permission.EditRole)) self.assertFalse(role.has_permission(Permission.EditUser))
def test_has_permission_single_permission(self): """ Test the has_permission() 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_permission(Permission.EditRole)) self.assertFalse(role.has_permission(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse(role.has_permission(Permission.EditRole | Permission.EditUser)) role._permissions = Permission.EditUser.value self.assertFalse(role.has_permission(Permission.EditRole)) self.assertTrue(role.has_permission(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse(role.has_permission(Permission.EditRole | Permission.EditUser))
def test_has_permission_single_permission(self): """ Test the has_permission() 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_permission(Permission.EditRole)) self.assertFalse(role.has_permission(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse( role.has_permission(Permission.EditRole | Permission.EditUser)) role._permissions = Permission.EditUser.value self.assertFalse(role.has_permission(Permission.EditRole)) self.assertTrue(role.has_permission(Permission.EditUser)) # If a combination of multiple permissions is requested, the role does not have this permission. self.assertFalse( role.has_permission(Permission.EditRole | Permission.EditUser))