Ejemplo n.º 1
0
def test_message_edit_not_owner_or_sender():
    dict = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    token = dict["token"]
    u_id = dict["u_id"]
    channels.channels_create(token, "Test_channel", True)
    message.message_send(token, "1", "test") == { 'message_id': 1,}
    channel.channel_removeowner(token, "1", "1")
    with pytest.raises(AccessError)
Ejemplo n.º 2
0
def channel_removeowner_owner(channel_init):
    channel_addowner(channel_init[0]['token'], channel_init[2],
                     channel_init[3]['u_id'])
    result = channel_removeowner(channel_init[3]['token'], channel_init[2],
                                 channel_init[0]['u_id'])
    result = channel_removeowner(channel_init[0]['token'], channel_init[2],
                                 channel_init[3]['u_id'])
    assert isinstance(result, dict)
Ejemplo n.º 3
0
def test_message_edit_not_owner_but_sender():
    dict = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    token = dict["token"]
    u_id = dict["u_id"]
    channels.channels_create(token, "Test_channel", True)
    message.message_send(token, "1", "test") == { 'message_id': 1,}
    channel.channel_removeowner(token, "1", "1")
    assert message.message_edit(token, "1", "Sender") == {}
Ejemplo n.º 4
0
def test_remove_the_only_owner():
    clear()
    user_A, user_B = register_n_users(2)
    public_channel = channels_create(user_A["token"], "public_channel", True)
    channel_join(user_B["token"], public_channel["channel_id"])
    channel_removeowner(user_A["token"], public_channel["channel_id"], user_A["u_id"])
    details = channel_details(user_B["token"], public_channel["channel_id"])
    expected_owner_ids = [user_B["u_id"]]
    assert_contains_users_id(details["owner_members"], expected_owner_ids)
Ejemplo n.º 5
0
def test_channel_removeowner_invalid_token():
    boyu_dict, _, weiqiang_dict, _, _ = initialise_data()
    team_pears = channels_create(boyu_dict['token'], "teamPears", True)
    team_pears_id = team_pears['channel_id']
    channel_addowner(boyu_dict['token'], team_pears_id, weiqiang_dict['u_id'])
    channel_removeowner(weiqiang_dict['token'], team_pears_id,
                        boyu_dict['u_id'])
    with pytest.raises(AccessError):
        assert channel_addowner("invalid_token", team_pears_id,
                                boyu_dict['u_id'])
Ejemplo n.º 6
0
def channel_removeowner():
    '''
    Route that removes a user as an owner from a channel
    '''
    payload = request.get_json()
    token = payload['token']
    channel_id = payload['channel_id']
    u_id = payload['u_id']
    channel.channel_removeowner(token, channel_id, u_id)
    return dumps({})
Ejemplo n.º 7
0
def test_remove_owner_with_invalid_channel_id():
    clear()
    user_A, user_B = register_n_users(2)
    public_channel = channels_create(user_A["token"], "public_channel", True)
    channel_join(user_B["token"], public_channel["channel_id"])
    channel_addowner(user_A["token"], public_channel["channel_id"], user_B["u_id"])

    with pytest.raises(InputError):
        invalid_channel_id = 233
        channel_removeowner(user_A["token"], invalid_channel_id, user_B["u_id"])
Ejemplo n.º 8
0
def test_remove_owner_by_non_owner():
    clear()
    user_A, user_B = register_n_users(2)
    public_channel = channels_create(user_A["token"], "public_channel", True)
    channel_join(user_B["token"], public_channel["channel_id"])

    with pytest.raises(AccessError):
        channel_removeowner(
            user_B["token"], public_channel["channel_id"], user_A["u_id"]
        )
Ejemplo n.º 9
0
def test_message_edit_not_owner_or_sender():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    member = auth.auth_register("*****@*****.**", "123456", "Sinha1",
                                "Nawa1")
    channels.channels_create(owner['token'], "Test_channel", True)
    message.message_send(owner['token'], 1, "test")
    channel.channel_removeowner(owner['token'], 1, 1)
    with pytest.raises(AccessError):
        message.message_edit(member['token'], 1, "Wrong message id")
Ejemplo n.º 10
0
def channel_removeowner():
    """
    Function channel removeowner route
    """
    remove_details = request.get_json()

    channel.channel_removeowner(remove_details["token"],
                                int(remove_details["channel_id"]),
                                int(remove_details["u_id"]))
    return dumps({})
Ejemplo n.º 11
0
def test_removeowner_invalid_channel():
    '''
    Testing when channel is invalid.
    '''
    clear()
    user = auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    user_token = user.get("token")
    user_id = user.get("u_id")

    with pytest.raises(InputError):
        channel_removeowner(user_token, "channel_id", user_id)
Ejemplo n.º 12
0
def test_channel_removeowner_invalid_token(reset, create_public_channel):
    '''
    Removing an owner as an unauthorized user
    '''

    # creating a public channel
    channel_id, owner_info = create_public_channel
    # testing using an invalid token raises an exception
    with pytest.raises(AccessError):
        channel_removeowner('I am not a valid token', channel_id['channel_id'],
                            owner_info['u_id'])
Ejemplo n.º 13
0
def test_remove_owner_with_the_only_member():
    clear()
    # register a owner and remove its owner
    user_A = register_n_users(1)
    public_channel = channels_create(user_A["token"], "public_channel", True)
    channel_removeowner(user_A["token"], public_channel["channel_id"], user_A["u_id"])

    # if a owner is the only member of a channel, we expect him leaving the channel after
    # remove owner, so he won't have authority to access the channel
    with pytest.raises(AccessError):
        channel_details(user_A["token"], public_channel["channel_id"])
Ejemplo n.º 14
0
def test_removeowner_not_member():
    """
    Tests if channel_removeowner raises InputError when u_id is not a member (and not an owner)
    """
    user1 = auth.auth_register("*****@*****.**", "password", "Lord",
                               "Voldemort")
    user2 = auth.auth_register("*****@*****.**", "password", "Tom", "Riddle")

    c_id_dict = channels.channels_create(user1["token"], "test_channel", True)
    with pytest.raises(error.InputError):
        channel.channel_removeowner(user1["token"], c_id_dict["channel_id"],
                                    user2["token"])
Ejemplo n.º 15
0
def test_removeowner_invalid_channel_id():
    '''
    Testing when channel_id is invalid.
    '''
    clear()
    user = auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    user_token = user.get("token")
    channels_return = channels_create(user_token, "username", True)
    channel_id = channels_return.get("u_id")
    
    with pytest.raises(InputError):
        channel_removeowner(user_token, channel_id, "invalid_id")
Ejemplo n.º 16
0
def test_channel_removeowner():
    clear()
    info = auth.auth_register("*****@*****.**", "ihfeh3hgi00d", "Bill", "Gates")
    channels.channels_create(info['token'], 'validchannelname', True)
    secondinfo = auth.auth_register("*****@*****.**", "ttteh3hgi00d", "Billy", "Gale")
    second_channel_id = channels.channels_create(info['token'], 'secondchannelname', True)
    channel.channel_join(secondinfo['token'], second_channel_id['channel_id'])
    second_u_id = auth.auth_u_id_from_token(secondinfo['token'])
    channel.channel_addowner(info['token'], second_channel_id['channel_id'], second_u_id)
    assert len(data['channels'][1]['owners']) == 2
    channel.channel_removeowner(info['token'], second_channel_id['channel_id'], second_u_id)
    assert len(data['channels'][1]['owners']) == 1
Ejemplo n.º 17
0
def test_not_owner():
    '''test for user is not an owner of channel'''
    reset_data()
    owner = auth_register("*****@*****.**", "avengers", "Natasha",
                          "Romanova")
    test_channel = channels.channels_create(owner['token'], "Basement", True)
    channel_id = test_channel['channel_id']
    member = auth_register("*****@*****.**", "helloworld", "Cool", "Man")
    channel.channel_join(member['token'], channel_id)

    with pytest.raises(InputError):
        channel.channel_removeowner(owner['token'], channel_id, member['u_id'])
Ejemplo n.º 18
0
def test_removeowner_not_owner():
    """
    Tests if channel_removeowner raises an InputError when u_id is not an owner
    """
    user1 = auth.auth_register("*****@*****.**", "password", "Callum",
                               "Jones")
    user2 = auth.auth_register("*****@*****.**", "password", "Jason", "Lin")

    c_id_dict = channels.channels_create(user1["token"], "test_channel", True)
    channel.channel_join(user2["token"], c_id_dict["channel_id"])
    with pytest.raises(error.InputError):
        channel.channel_removeowner(user1["token"], c_id_dict["channel_id"],
                                    user2["u_id"])
Ejemplo n.º 19
0
def test_channel_removeowner_u_id_not_owner():
    """Testing removing an owner who doesnt have a valid u_id"""
    clear()
    inviter_user = auth_register("*****@*****.**", "password3", "Skater",
                                 "Pro")
    invitee_user = auth_register("*****@*****.**", "password3", "Donald",
                                 "Trump")
    new_channel = channels_create(inviter_user["token"], "testing_channel_id",
                                  False)
    channel_invite(inviter_user["token"], 1, invitee_user["u_id"])
    with pytest.raises(InputError):
        channel_removeowner(inviter_user["token"], new_channel["channel_id"],
                            invitee_user["u_id"])
Ejemplo n.º 20
0
def removeowner():
    '''
    A route to call channel_removeowner
    '''
    payload = request.get_json()

    if not payload['token'] or not payload['channel_id'] or not payload['u_id']:
        raise RequestError(description="Missing data in request body")

    channel.channel_removeowner(payload['token'], int(payload['channel_id']),
                                int(payload['u_id']))

    return json.dumps({})
Ejemplo n.º 21
0
def test_channel_removeowner_as_non_member(reset, create_public_channel,
                                           create_user1):
    '''
    Removing an owner without a member of the channel
    '''
    # creating a public channel
    channel_id, owner_info = create_public_channel
    # creating normal users
    user_info = create_user1
    # trying to make a remove a user as a non member
    with pytest.raises(Exception):
        channel_removeowner(user_info['token'], channel_id['channel_id'],
                            owner_info['u_id'])
Ejemplo n.º 22
0
def test_channel_kick():
    '''
    Testing the channel_kick function
    '''
    clear()
    owner = auth_register('*****@*****.**', 'password', 'Bob', 'Smith')
    channel = channels_create(owner['token'], 'Test channel', True)
    user = auth_register('*****@*****.**', 'password', 'Jess', 'Chen')
    channel_join(user['token'], channel['channel_id'])

    # Authorised user does not have a valid token
    with pytest.raises(AccessError):
        channel_kick('', channel['channel_id'], user['u_id'])

    # Old user does not have a valid token
    with pytest.raises(AccessError):
        channel_kick(owner['token'], channel['channel_id'], 100)

    # Channel ID is not a valid channel
    with pytest.raises(InputError):
        channel_kick(owner['token'], channel['channel_id'] + 100, user['u_id'])

    # Authorised user is not an owner
    with pytest.raises(AccessError):
        channel_kick(user['token'], channel['channel_id'], owner['u_id'])

    # Old user is an owner
    channel_addowner(owner['token'], channel['channel_id'], user['u_id'])
    with pytest.raises(InputError):
        channel_kick(owner['token'], channel['channel_id'], user['u_id'])

    # Remove old user as an owner (so they are now just a member)
    channel_removeowner(owner['token'], channel['channel_id'], user['u_id'])

    details = channel_details(owner['token'], channel['channel_id'])
    assert len(details['all_members']) == 2

    # Authorised user can now remove old user
    channel_kick(owner['token'], channel['channel_id'], user['u_id'])

    details = channel_details(owner['token'], channel['channel_id'])
    assert len(details['all_members']) == 1

    # Removing someone who is already removed (no longer a member)
    with pytest.raises(InputError):
        channel_kick(owner['token'], channel['channel_id'], user['u_id'])

    # Removed user cannot kick
    with pytest.raises(AccessError):
        channel_kick(user['token'], channel['channel_id'], owner['u_id'])
Ejemplo n.º 23
0
def test_invalid_user_remove():
    '''
    Testing when channel_remove is invalid.
    '''
    clear()
    user2 = auth_register("*****@*****.**", 'password', 'abcd2', 'efgh2')
    user_token2 = user2.get("token")
    channel = channels_create(user_token2, "Channel1", True)
    channel.get("channel_id")

    user_id = 123123
    
    with pytest.raises(InputError):
        channel_removeowner(user_token2, "channel_id", user_id)
Ejemplo n.º 24
0
def test_channel_removeowner_admin_last_owner_with_no_members():
    clear()
    admin, usera = register_n_users(2, include_admin=True)

    # user a creates a channel
    channel_id = channels_create(usera["token"], "",
                                 is_public=True)["channel_id"]
    # admin removes him from his channel
    channel_removeowner(admin["token"], channel_id, usera["u_id"])

    with pytest.raises(AccessError):
        # usera can't access the channel anymore, because he is not a member
        # (there are no members in the channel anymore)
        channel_details(usera["token"], channel_id)
Ejemplo n.º 25
0
def test_channel_removeowner_invalid_channel(reset, create_public_channel,
                                             create_user1):
    '''
    Assuming 22222 is an invalid channel id
    '''

    # creating a public channel
    channel_id, owner_info = create_public_channel
    # creating normal users
    user_info = create_user1
    channel_addowner(owner_info['token'], channel_id['channel_id'],
                     user_info['u_id'])
    with pytest.raises(InputError):
        # removing a user from an invalid channel
        channel_removeowner(owner_info['token'], 22222, user_info['u_id'])
Ejemplo n.º 26
0
def test_channel_removeowner_no_owner(reset, create_public_channel,
                                      create_user1):
    '''
    trying to remove ownership from a user who is not an owner
    '''

    # creating a public channel
    channel_id, owner_info = create_public_channel
    # creating normal users
    user_info = create_user1

    with pytest.raises(InputError):
        # removing a user from an invalid channel
        channel_removeowner(owner_info['token'], channel_id['channel_id'],
                            user_info['u_id'])
Ejemplo n.º 27
0
def test_channel_removeowner_as_non_owner(reset, create_public_channel,
                                          create_user1):
    '''
    Removing an owner who happens to be a slackr owner as a general member
    '''
    # creating a public channel
    channel_id, owner_info = create_public_channel
    # creating normal users
    user_info = create_user1
    # joining as a general member and trying to removing another user as an
    # owner
    channel_join(user_info['token'], channel_id['channel_id'])
    with pytest.raises(AccessError):
        channel_removeowner(user_info['token'], channel_id['channel_id'],
                            owner_info['u_id'])
Ejemplo n.º 28
0
def test_channel_delete_owner_of_flockr():
    boyu_dict, wenyao_dict, _, _, _ = initialise_data()

    team_mandarin = channels_create(wenyao_dict['token'], "teamMandarin", True)
    team_mandarin_id = team_mandarin['channel_id']
    channel_invite(wenyao_dict['token'], team_mandarin_id, boyu_dict['u_id'])
    channel_removeowner(boyu_dict['token'], team_mandarin_id,
                        wenyao_dict['u_id'])
    details = channel_details(boyu_dict['token'],
                              team_mandarin_id)['owner_members']
    u_id_list = []
    for owner in details:
        u_id_list.append(owner['u_id'])

    assert wenyao_dict['u_id'] not in u_id_list
Ejemplo n.º 29
0
def test_flockr_owner():
    '''
    Testing functionality for Flockr owner
    '''
    clear()
    flockr_owner = auth_register('*****@*****.**', 'password', 'Big', 'Boss')
    admin = auth_register('*****@*****.**', 'password', 'Channel', 'Boss')
    user = auth_register('*****@*****.**', 'password', 'Average', 'Jonas')

    # Admin creates channel
    private_channel = channels_create(admin['token'], 'Test Channel', False)

    # Flockr owner has to join as member first, like normal user
    with pytest.raises(AccessError):
        channel_addowner(admin['token'], private_channel['channel_id'],
                         user['u_id'])

    with pytest.raises(AccessError):
        channel_addowner(admin['token'], private_channel['channel_id'],
                         flockr_owner['u_id'])

    # Flockr owner can't invite or add/remove owner if they haven't joined the channel as a member
    with pytest.raises(AccessError):
        channel_invite(flockr_owner['token'], private_channel['channel_id'],
                       user['u_id'])
    channel_invite(admin['token'], private_channel['channel_id'], user['u_id'])
    with pytest.raises(AccessError):
        channel_addowner(flockr_owner['token'], private_channel['channel_id'],
                         user['u_id'])
    channel_addowner(admin['token'], private_channel['channel_id'],
                     user['u_id'])
    with pytest.raises(AccessError):
        channel_removeowner(flockr_owner['token'],
                            private_channel['channel_id'], user['u_id'])
    channel_leave(user['token'], private_channel['channel_id'])

    # Flockr owner can join private channels, but regular users can't
    with pytest.raises(AccessError):
        channel_join(user['token'], private_channel['channel_id'])
    channel_join(flockr_owner['token'], private_channel['channel_id'])

    # Flockr owner can invite/add_owner/remove_owner once joined
    channel_invite(flockr_owner['token'], private_channel['channel_id'],
                   user['u_id'])
    channel_addowner(flockr_owner['token'], private_channel['channel_id'],
                     user['u_id'])
    channel_removeowner(flockr_owner['token'], private_channel['channel_id'],
                        user['u_id'])
def test_channel_removeowner_invalid_channel():
    clear()
    user_0 = create_one_test_user()
    public_channel = 4
    with pytest.raises(error.InputError):
        assert channel_removeowner(user_0['token'], public_channel,
                                   user_0['u_id']) == {}