Exemplo n.º 1
0
    def test_is_only_role_allowed_to_edit_roles(self):
        """
            Test if a role is the only one allowed to edit roles.

            Expected result: `True` if it is, `False` otherwise.
        """
        # First check if the role is not allowed to edit roles.
        name = 'Administrator'
        permission = Permission.EditRole
        role = Role(name=name)
        db.session.add(role)
        db.session.commit()
        self.assertFalse(role.is_only_role_allowed_to_edit_roles())

        # Add the permission. Now it should be the only one.
        role.permissions = permission
        db.session.commit()
        self.assertTrue(role.is_only_role_allowed_to_edit_roles())

        # Add another role with the required permission.
        other_role = Role(name='Guest')
        other_role.permissions = permission
        db.session.add(other_role)
        db.session.commit()

        self.assertFalse(role.is_only_role_allowed_to_edit_roles())
Exemplo n.º 2
0
    def test_is_only_role_allowed_to_edit_roles(self):
        """
            Test if a role is the only one allowed to edit roles.

            Expected result: `True` if it is, `False` otherwise.
        """

        # First check if the role is not allowed to edit roles.
        name = 'Administrator'
        permission = Permission.EditRole
        role = Role(name=name)
        db.session.add(role)
        db.session.commit()
        self.assertFalse(role.is_only_role_allowed_to_edit_roles())

        # Add the permission. Now it should be the only one.
        role.permissions = permission
        db.session.commit()
        self.assertTrue(role.is_only_role_allowed_to_edit_roles())

        # Add another role with the required permission.
        other_role = Role(name='Guest')
        other_role.permissions = permission
        db.session.add(other_role)
        db.session.commit()

        self.assertFalse(role.is_only_role_allowed_to_edit_roles())
Exemplo n.º 3
0
    def test_permissions_set_permission_no_edit_role_only_role(self):
        """
            Test setting permissions with giving permissions that do not include the permission to edit roles if this
            is the only role allowed to edit roles.

            Expected result: The permission to edit roles is set automatically.
        """
        role = Role('Administrator')
        role.permissions = Permission.EditRole
        db.session.add(role)
        db.session.commit()

        self.assertTrue(role.is_only_role_allowed_to_edit_roles())

        role.permissions = Permission.EditUser
        self.assertEqual(Permission.EditUser | Permission.EditRole, role.permissions)
Exemplo n.º 4
0
    def test_permissions_set_permission_no_edit_role_only_role(self):
        """
            Test setting permissions with giving permissions that do not include the permission to edit roles if this
            is the only role allowed to edit roles.

            Expected result: The permission to edit roles is set automatically.
        """

        role = Role('Administrator')
        role.permissions = Permission.EditRole
        db.session.add(role)
        db.session.commit()

        self.assertTrue(role.is_only_role_allowed_to_edit_roles())

        role.permissions = Permission.EditUser
        self.assertEqual(Permission.EditUser | Permission.EditRole,
                         role.permissions)
Exemplo n.º 5
0
    def test_permissions_set_permission_no_edit_role_other_roles(self):
        """
            Test setting permissions with giving permissions that do not include the permission to edit roles if there
            are also other roles allowed to edit roles.

            Expected result: The permission to edit roles is not set.
        """
        other_role = Role('Guest')
        other_role.permissions = Permission.EditRole
        db.session.add(other_role)

        role = Role('Administrator')
        role.permissions = Permission.EditRole
        db.session.add(role)
        db.session.commit()

        self.assertFalse(role.is_only_role_allowed_to_edit_roles())

        new_permissions = Permission.EditUser
        role.permissions = new_permissions
        self.assertEqual(new_permissions, role.permissions)
Exemplo n.º 6
0
    def test_permissions_set_permission_no_edit_role_other_roles(self):
        """
            Test setting permissions with giving permissions that do not include the permission to edit roles if there
            are also other roles allowed to edit roles.

            Expected result: The permission to edit roles is not set.
        """

        other_role = Role('Guest')
        other_role.permissions = Permission.EditRole
        db.session.add(other_role)

        role = Role('Administrator')
        role.permissions = Permission.EditRole
        db.session.add(role)
        db.session.commit()

        self.assertFalse(role.is_only_role_allowed_to_edit_roles())

        new_permissions = Permission.EditUser
        role.permissions = new_permissions
        self.assertEqual(new_permissions, role.permissions)