def test_1_user_group_name():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    group1 = UserGroup("test_group1", hallo1)
    perm4 = PermissionMask()
    group1.permission_mask = perm4
    hallo1.add_user_group(group1)
    # Get permissions of specified user group
    data = perm_cont.find_permission_mask(["user_group=test_group1"], user1,
                                          chan1)
    assert data == perm4, "Did not find the correct permission mask."
def test_1_user_group_no_name():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    group1 = UserGroup("test_group1", hallo1)
    perm4 = PermissionMask()
    group1.permission_mask = perm4
    hallo1.add_user_group(group1)
    # Try to get permissions of non-existent user group
    try:
        perm_cont.find_permission_mask(["user_group=test_group2"], user1,
                                       chan1)
        assert False, "Find permission mask should have failed."
    except hallo.modules.permission_control.PermissionControlException as e:
        assert "error" in str(e).lower()
        assert "no user group exists by that name" in str(e).lower()