Пример #1
0
    def test_has_permissions_one_of_multiple_permissions(self):
        """
            Test the has_permissions_one_of() 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_one_of(Permission.EditRole))
        self.assertTrue(role.has_permissions_one_of(Permission.EditUser))
        self.assertTrue(role.has_permissions_one_of(Permission.EditRole, Permission.EditUser, Permission(0)))
Пример #2
0
    def test_has_permissions_one_of_empty_permission(self):
        """
            Test the has_permissions_one_of() 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_one_of(Permission(0)))

        role._permissions = Permission.EditRole.value
        self.assertFalse(role.has_permissions_one_of(Permission(0)))
Пример #3
0
    def test_has_permissions_one_of_multiple_permissions(self):
        """
            Test the has_permissions_one_of() 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
        self.assertTrue(role.has_permissions_one_of(Permission.EditRole))
        self.assertTrue(role.has_permissions_one_of(Permission.EditUser))
        self.assertTrue(
            role.has_permissions_one_of(Permission.EditRole,
                                        Permission.EditUser, Permission(0)))
Пример #4
0
    def test_has_permissions_one_of_empty_permission(self):
        """
            Test the has_permissions_one_of() 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_one_of(Permission(0)))

        role.permissions = Permission.EditRole
        self.assertTrue(role.has_permissions_one_of(Permission(0)))
Пример #5
0
    def test_has_permissions_one_of_single_permission(self):
        """
            Test the has_permissions_one_of() 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
        self.assertTrue(role.has_permissions_one_of(Permission.EditRole))
        self.assertFalse(role.has_permissions_one_of(Permission.EditUser))

        # If a combination of multiple permissions is requested, the role does not have this permission.
        self.assertFalse(
            role.has_permissions_one_of(Permission.EditRole
                                        | Permission.EditUser))

        role.permissions = Permission.EditUser
        self.assertFalse(role.has_permissions_one_of(Permission.EditRole))
        self.assertTrue(role.has_permissions_one_of(Permission.EditUser))

        # If a combination of multiple permissions is requested, the role does not have this permission.
        self.assertFalse(
            role.has_permissions_one_of(Permission.EditRole
                                        | Permission.EditUser))
Пример #6
0
    def test_has_permissions_one_of_no_permissions(self):
        """
            Test the has_permissions_one_of() 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_one_of(Permission.EditRole))
        self.assertFalse(role.has_permissions_one_of(Permission.EditUser))
Пример #7
0
    def test_has_permissions_one_of_no_permissions(self):
        """
            Test the has_permissions_one_of() 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_one_of(Permission.EditRole))
        self.assertFalse(role.has_permissions_one_of(Permission.EditUser))
Пример #8
0
    def test_has_permissions_one_of_single_permission(self):
        """
            Test the has_permissions_one_of() 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_one_of(Permission.EditRole))
        self.assertFalse(role.has_permissions_one_of(Permission.EditUser))

        # If a combination of multiple permissions is requested, the role does not have this permission.
        self.assertFalse(role.has_permissions_one_of(Permission.EditRole | Permission.EditUser))

        role._permissions = Permission.EditUser.value
        self.assertFalse(role.has_permissions_one_of(Permission.EditRole))
        self.assertTrue(role.has_permissions_one_of(Permission.EditUser))

        # If a combination of multiple permissions is requested, the role does not have this permission.
        self.assertFalse(role.has_permissions_one_of(Permission.EditRole | Permission.EditUser))