示例#1
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'
    }
示例#2
0
def generate_data():
    test_data = Data()
    user_admin = register(test_data, '*****@*****.**', 'password',
                          'name_first1', 'name_last', 'http://127.0.0.1:5555/')
    user_channel_owner = register(test_data, '*****@*****.**', 'password',
                                  'name_first2', 'name_last',
                                  'http://127.0.0.1:5555/')
    user_in_channel = register(test_data, '*****@*****.**', 'password',
                               'name_first4', 'name_last',
                               'http://127.0.0.1:5555/')
    user_notin_channel = register(test_data, '*****@*****.**', 'password',
                                  'name_first3', 'name_last',
                                  'http://127.0.0.1:5555/')

    channel = ch_create(test_data, user_channel_owner['token'], 'test_channel',
                        True)
    ch_join_leave(test_data, user_admin['token'], channel['channel_id'],
                  'join')
    ch_join_leave(test_data, user_in_channel['token'], channel['channel_id'],
                  'join')

    send_message(test_data, user_in_channel['token'], channel['channel_id'],
                 'test3')
    send_message(test_data, user_channel_owner['token'], channel['channel_id'],
                 'test2')
    send_message(test_data, user_admin['token'], channel['channel_id'], 'test')

    return test_data
示例#3
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
示例#4
0
def test_channel_join_ok():
    data = getdata()
    host = get_host()
    user = data.users_group[0]
    channel = ch_create(data, user.token, '12345', True)
    user2 = data.users_group[1]
    ch_join_leave(data, user2.token, channel['channel_id'], 'join')
    channel_profile = ch_details(data, user2.token, channel['channel_id'],
                                 host)

    # Check the new user has join the channel
    member_list = channel_profile["all_members"]
    assert member_list[0]['u_id'] == user.u_id
    assert member_list[1]['u_id'] == user2.u_id
示例#5
0
def getdata():
    data = Data()
    ch_owner = register(data, '*****@*****.**', 'testtest', 'test', 'test',
                        'http://127.0.0.1:5555/')
    ch_member = register(data, '*****@*****.**', 'test2test2', 'test2',
                         'test2', 'http://127.0.0.1:5555/')
    register(data, '*****@*****.**', 'tests2', 'not in channel', 'test',
             'http://127.0.0.1:5555/')
    channel1 = ch_create(data, ch_owner['token'], 'ch_test', True)
    ch_join_leave(data, ch_member['token'], channel1['channel_id'], 'join')
    # data, token, channel_id, message, time_create=datetime.now()
    send_message(data, ch_owner['token'], channel1['channel_id'], 'test')
    send_message(data, ch_member['token'], channel1['channel_id'], 'test2')
    return data
示例#6
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
示例#7
0
def test_channel_join_bad():
    data = getdata()
    user = data.users_group[0]
    channel = ch_create(data, user.token, '12345', True)
    user2 = data.users_group[1]
    # ValueError
    res1 = ch_join_leave(data, user2.token, channel['channel_id'] - 123,
                         'join')
    assert res1 == {'ValueError': 'Channel ID is invalid'}

    # AccessError
    channel2 = ch_create(data, user.token, '12345', False)
    res2 = ch_join_leave(data, user2.token, channel2['channel_id'], 'join')
    assert res2 == {'AccessError': 'The channel is private'}

    res3 = ch_join_leave(data, user.token, channel['channel_id'], 'join')
    assert res3 == {'AccessError': 'Already a member of that channel'}
示例#8
0
def test_channel_leave_bad():
    data = getdata()
    user = data.users_group[0]
    # it takes in data, token, channel_name and is_public and return channel_id
    ch_create(data, user.token, '12345', True)

    res = ch_join_leave(data, user.token, 10, 'leave')
    assert res == {'ValueError': 'Channel ID is invalid'}
示例#9
0
def channel_join():
    global data

    channel_id, token = do_get(request.form, ['channel_id', 'token'])
    result = ch_join_leave(data, token, int(channel_id), 'join')
    catch_error_and_return(result)
    save()

    return dumps(result)
示例#10
0
def channel_leave():
    global data

    channel_id = int(request.form.get('channel_id'))
    token = request.form.get('token')
    output = ch_join_leave(data, token, channel_id, 'leave')
    if 'ValueError' in output:
        raise ValueError(description=output['ValueError'])
    save()

    return dumps(output)
示例#11
0
def get_data():
    test_data = Data()
    user_chowner = register(test_data, '*****@*****.**', 'password',
                            'name_first1', 'name_last',
                            'http://127.0.0.1:5555/')
    user_inch = register(test_data, '*****@*****.**', 'password',
                         'name_first2', 'name_last', 'http://127.0.0.1:5555/')
    register(test_data, '*****@*****.**', 'password', 'name_first3',
             'name_last', 'http://127.0.0.1:5555/')
    channel = ch_create(test_data, user_chowner['token'], 'test_channel', True)
    ch_join_leave(test_data, user_inch['token'], channel['channel_id'], 'join')
    message_inch = send_message(test_data, user_inch['token'],
                                channel['channel_id'], 'test2')
    message_chowner = send_message(test_data, user_chowner['token'],
                                   channel['channel_id'], 'test')
    react_unreact(test_data, user_inch['token'], message_inch['message_id'], 1,
                  'react')
    react_unreact(test_data, user_inch['token'], message_chowner['message_id'],
                  1, 'react')
    ch_create(test_data, user_chowner['token'], 'test_channel2', True)
    return test_data
示例#12
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
示例#13
0
def channel_join():
    global data

    token = request.form.get('token')
    channel_id = int(request.form.get('channel_id'))
    join = ch_join_leave(data, token, channel_id, 'join')
    if 'ValueError' in join:
        raise ValueError(description=join['ValueError'])
    elif 'AccessError' in join:
        raise AccessError(description=join['AccessError'])
    save()

    return dumps(join)
示例#14
0
def test_unpin_bad():
    data = generate_data()
    user_admin, user_owner, user_in_channel, user_notin_channel = getting_user(
        data)
    channel = getting_channel(data)
    message_admin = getting_message(data)[0]

    # Invalid input
    assert pin_unpin(data, user_admin.token, 100, 'unpin') == {
        'ValueError': 'message_id is not a valid message'
    }

    assert pin_unpin(data, user_owner.token, message_admin.message_id,
                     'unpin') == {
                         'ValueError': 'The authorised user is not an admin'
                     }

    assert pin_unpin(data, user_notin_channel.token, message_admin.message_id,
                     'unpin') == {
                         'AccessError':
                         'The authorised user is not \
a member of the channel that the message is within'
                     }

    assert pin_unpin(data, user_admin.token, message_admin.message_id,
                     'unpin') == {
                         "ValueError":
                         "Message with ID message_id is already unpinned"
                     }

    # admin leave the channel
    ch_join_leave(data, user_admin.token, channel.channel_id, 'leave')
    assert pin_unpin(data, user_admin.token, message_admin.message_id,
                     'unpin') == {
                         'AccessError':
                         'The authorised user is not a member of the channel \
that the message is within'
                     }