def test_delete_role_from_user(self):
     """Tests the function to delete a role from a user
     """
     anonymous_user = User(roles=[default_role, admin_role])
     anonymous_user.remove_role('admin')
     assert 'admin' not in [
         role.get_name() for role in anonymous_user.get_roles()
     ]
 def test_delete_user(self):
     """Tests successful deletion of user
     """
     unwanted_user = User(roles=[default_role])
     del unwanted_user
     assert 'unwanted_user' not in dir()
# -*- coding: utf-8 -*-
# @Author: Tasdik Rahman
# @GPLv3 License
# @http://tasdikrahman.me
# @https://github.com/tasdikrahman
"""Testing assignment and deletion of a Role to User
"""

from easyrbac import Role, User

default_role = Role('default')
admin_role = Role('admin')

default_user = User(roles=[default_role])
admin_user = User(roles=[admin_role, default_role])


class TestRoleAssignmentDeletion:
    def test_role_assignment(self):
        """Creates the roles which need to be assigned to users
        """
        assert [role.get_name()
                for role in default_user.get_roles()] == ['default']
        assert [role.get_name() for role in admin_user.get_roles()
                ].sort() == ['admin', 'default'].sort()

    def test_delete_role_from_user(self):
        """Tests the function to delete a role from a user
        """
        anonymous_user = User(roles=[default_role, admin_role])
        anonymous_user.remove_role('admin')
Beispiel #4
0
# -*- coding: utf-8 -*-
# @Author: Tasdik Rahman
# @GPLv3 License
# @http://tasdikrahman.me
# @https://github.com/tasdikrahman

from easyrbac import AccessControlList, User, Role

everyone_role = Role('everyone')
admin_role = Role('admin')

everyone_user = User(roles=[everyone_role])
admin_user = User(roles=[admin_role, everyone_role])

acl = AccessControlList()

acl.resource_read_rule(everyone_role, 'GET', '/api/v1/employee/1/info')
acl.resource_delete_rule(admin_role, 'DELETE', '/api/v1/employee/1/')


class TestPermissions():
    def test_read_rule_everyone(self):
        """checking resource access with the employee himself in context
        """
        for user_role in [
                role.get_name() for role in everyone_user.get_roles()
        ]:
            assert acl.is_read_allowed(user_role, 'GET',
                                       '/api/v1/employee/1/info') == True

    def test_write_rule_everyone(self):