Beispiel #1
0
def test_channel_removeowner_ok():
    data = getdata()
    host = get_host()
    user_admin = data.users_group[0]
    user1 = data.users_group[1]
    channel = ch_create(data, user_admin.token, '12345', True)

    ch_join_leave(data, user1.token, channel['channel_id'], 'join')

    ch_add_remove_owner(data, user_admin.token, channel['channel_id'],
                        user1.u_id, 'add')
    ch_add_remove_owner(data, user_admin.token, channel['channel_id'],
                        user1.u_id, 'remove')

    channel_profile = ch_details(data, user_admin.token, channel['channel_id'],
                                 host)
    owner_list = channel_profile["owner_members"]
    # if user1["u_id"] is in the owner list
    # Means channel_removeowner is not working
    exist = 0
    if user1.u_id not in owner_list:
        exist = 1
    assert exist == 1

    assert owner_list[0]['u_id'] == user_admin.u_id
Beispiel #2
0
def test_channel_addowner_ok():
    data = getdata()
    host = get_host()
    user = data.users_group[0]
    channel = ch_create(data, user.token, '12345', True)
    user2 = data.users_group[2]
    ch_join_leave(data, user2.token, channel['channel_id'], 'join')

    ch_add_remove_owner(data, user.token, channel['channel_id'], user2.u_id,
                        'add')
    channel_profile = ch_details(data, user.token, channel['channel_id'], host)
    owner_list = channel_profile['owner_members']
    # Checking there is two owner in this channel
    assert owner_list[0]['u_id'] == user.u_id
    assert owner_list[1]['u_id'] == user2.u_id
Beispiel #3
0
def test_channel_removeowner_bad():
    data = getdata()
    user_admin = data.users_group[0]
    user1 = data.users_group[1]
    user2 = data.users_group[2]
    channel = ch_create(data, user_admin.token, '12345', True)

    ch_join_leave(data, user1.token, channel['channel_id'], 'join')
    ch_join_leave(data, user2.token, channel['channel_id'], 'join')

    ch_add_remove_owner(data, user_admin.token, channel['channel_id'],
                        user1.u_id, 'remove')
    # ValueError
    invalid_ch_id = channel['channel_id'] - 123
    res1 = ch_add_remove_owner(data, user_admin.token, invalid_ch_id,
                               user1.u_id, 'remove')
    assert res1 == {'ValueError': 'Invalid Channel ID'}

    res2 = ch_add_remove_owner(data, user_admin.token, channel['channel_id'],
                               user2.u_id, 'remove')
    assert res2 == {'ValueError': 'User is not an owner of the channel'}
    ch_add_remove_owner(data, user_admin.token, channel['channel_id'],
                        user1.u_id, 'remove')
    # AccessError
    res3 = ch_add_remove_owner(data, user2.token, channel['channel_id'],
                               user1.u_id, 'remove')
    assert res3 == {
        'AccessError': 'User is not an owner of the slackr or \
this channel'
    }
Beispiel #4
0
def channel_removeowner():
    global data

    channel_id, token, u_id = do_get(request.form,
                                     ['channel_id', 'token', 'u_id'])
    result = ch_add_remove_owner(data, token, int(channel_id), int(u_id),
                                 'remove')
    catch_error_and_return(result)
    save()

    return dumps(result)
Beispiel #5
0
def test_channel_leave_ok():
    data = getdata()
    host = get_host()
    user = data.users_group[0]
    user1 = data.users_group[1]
    # it takes in data, token, channel_name and is_public and return channel_id
    channel = ch_create(data, user.token, '12345', True)
    # user1 join to the channel
    ch_join_leave(data, user1.token, channel['channel_id'], 'join')
    # add user1 to be the owner of the channel
    ch_add_remove_owner(data, user.token, channel['channel_id'], user1.u_id,
                        'add')
    # user1 leave the channel
    ch_join_leave(data, user1.token, channel['channel_id'], 'leave')

    # Check the member in channel
    channel_profile = ch_details(data, user.token, channel['channel_id'], host)
    owner_list = channel_profile['owner_members']
    member_list = channel_profile['all_members']
    assert len(owner_list) == 1
    assert len(member_list) == 1
Beispiel #6
0
def channel_addowner():
    global data

    token = request.form.get('token')
    channel_id = int(request.form.get('channel_id'))
    u_id = int(request.form.get('u_id'))
    addowner = ch_add_remove_owner(data, token, channel_id, u_id, 'add')
    if 'ValueError' in addowner:
        raise ValueError(description=addowner['ValueError'])
    elif 'AccessError' in addowner:
        raise AccessError(description=addowner['AccessError'])

    save()
    return dumps(addowner)