Beispiel #1
0
def test_user_remove_messages_removed(
        reset, create_public_channel, make_user_cd):
    '''
    Testing if the users messages are removed
    '''
    # creating a public channel
    channel_id, owner_info = create_public_channel

    # creating user
    user_info = make_user_cd
    # joining and sending a message
    channel_join(user_info['token'], channel_id['channel_id'])
    message_send(user_info['token'], channel_id['channel_id'], 'HelloWorld')
    print(
        channel_messages(
            owner_info['token'],
            channel_id['channel_id'],
            start=0))

    # removing user
    user_remove(owner_info['token'], user_info['u_id'])
    # should be empty
    messages = channel_messages(
        owner_info['token'],
        channel_id['channel_id'],
        start=0)
    assert len(messages['messages']) == 1
Beispiel #2
0
def test_user_remove_own_self(reset, make_user_ab):
    '''
    Testing user cannot remove himself
    '''
    # creating admin
    admin_info = make_user_ab
    with pytest.raises(InputError):
        user_remove(admin_info['token'], admin_info['u_id'])
Beispiel #3
0
def test_user_remove_no_user(reset, create_public_channel, make_user_ab):
    '''
    Testing removing a non-existent user
    '''
    # creating a public channel
    _, owner_info = create_public_channel
    with pytest.raises(InputError):
        user_remove(owner_info['token'], owner_info['u_id'] + 1)
Beispiel #4
0
def test_user_remove_all_details(reset, make_user_ab, make_user_cd):
    '''
    Testing that no details are left after removal
    '''
    # creating admin and user
    admin_info = make_user_ab
    user_info = make_user_cd
    user_remove(admin_info['token'], user_info['u_id'])
    with pytest.raises(InputError):
        user_profile(admin_info['token'], user_info['u_id'])
Beispiel #5
0
def test_user_remove_not_admin(
        reset, make_user_ab, make_user_cd, make_user_ef):
    '''
    A reguler member tries to remove user
    '''
    # creating users
    user1_info = make_user_cd
    user2_info = make_user_ef

    with pytest.raises(AccessError):
        user_remove(user1_info['token'], user2_info['u_id'])
Beispiel #6
0
def test_user_remove_invalid_token(reset, create_public_channel, make_user_ab):
    '''
    Invalid token raises AccessError
    '''
    # creating a public channel
    _, owner_info = create_public_channel
    # create user
    user_info = make_user_ab

    with pytest.raises(AccessError):
        user_remove(owner_info['token'] + 'a', user_info['u_id'])
Beispiel #7
0
def user_remove():
    '''
    A wrapper for other.user_remove()
    '''
    token = request.args.get('token')
    u_id = request.args.get('u_id')
    if not token or not u_id:
        raise RequestError(description='Missing data in request body')

    other.user_remove(token, int(u_id))
    return json.dumps({})
Beispiel #8
0
def test_user_remove_removed_from_channel(
        reset, create_public_channel, make_user_cd):
    '''
    Checking if user is actually removed from all subscribed channels
    '''
    # creating a public channel
    channel_id, owner_info = create_public_channel

    # creating user
    user_info = make_user_cd
    # joining
    channel_join(user_info['token'], channel_id['channel_id'])
    # removing user
    user_remove(owner_info['token'], user_info['u_id'])
    # getting the details of the channel
    ch_details = channel_details(owner_info['token'], channel_id['channel_id'])
    # The reason we assume it is 2 is because we have a hangman bot in each
    # channel
    assert len(ch_details['all_members']) == 2