Exemplo n.º 1
0
    def test_only_in_role(self, role, target):
        role.add_users(self.user)
        cache = RoleCache(self.user)
        self.assertTrue(cache.has_role(*target))

        for other_role, other_target in self.ROLES:
            if other_role == role:
                continue

            self.assertFalse(cache.has_role(*other_target))
Exemplo n.º 2
0
def get_user_roles(user_id):
    """
    Returns a list of all roles that this user has.
    :param user_id: The id of the selected user.
    :return: All roles for all courses that this user has.
    """
    user = _get_user(user_id)
    if not hasattr(user, '_roles'):
        user._roles = RoleCache(user)
    role_cache = user._roles
    return role_cache._roles
Exemplo n.º 3
0
def get_user_roles(username):
    """
    Returns a list of all roles that this user has.
    :param username: The id of the selected user.
    :return: All roles for all courses that this user has.
    """
    # pylint: disable=protected-access
    user = _get_user(username)
    if not hasattr(user, '_roles'):
        user._roles = RoleCache(user)
    role_cache = user._roles
    return role_cache._roles
Exemplo n.º 4
0
 def test_empty_cache(self, role, target):
     cache = RoleCache(self.user)
     self.assertFalse(cache.has_role(*target))