예제 #1
0
def test_channel_user_leave():
    """Tests user leave in channel.py for an owner."""
    clear()
    new_user_1 = auth_register("*****@*****.**", "maccas19201",
                               "Travis", "Scott")
    new_user_2 = auth_register("*****@*****.**", "asheshTheGod912192",
                               "Ashesh", "God")
    new_channel = channels_create(new_user_1["token"], "Spooky Sesh", False)
    channel_addowner(new_user_1["token"], new_channel["channel_id"],
                     new_user_2["u_id"])
    channel_leave(new_user_2["token"], new_channel["channel_id"])
    channel_info = channel_details(new_user_1["token"],
                                   new_channel["channel_id"])
    assert channel_info == {
        'name':
        'Spooky Sesh',
        'owner_members': [{
            'u_id': 0,
            'name_first': 'Travis',
            'name_last': 'Scott',
            'profile_img_url': ''
        }],
        'all_members': [{
            'u_id': 0,
            'name_first': 'Travis',
            'name_last': 'Scott',
            'profile_img_url': ''
        }]
    }
예제 #2
0
def test_addowner_channel():
    """
    Tests if channel_addowner works if user is a channel owner but not a Slackr owner
    """
    user1 = auth.auth_register("*****@*****.**", "password", "Earthworm",
                               "Jim")
    user2 = auth.auth_register("*****@*****.**", "password", "Gabe",
                               "Newell")
    user3 = auth.auth_register("*****@*****.**", "Potions", "Harry",
                               "Potter")

    # user2 creates a channel, they should be the only owner
    c_id_dict = channels.channels_create(user2["token"], "test_channel", True)
    channel.channel_join(user3["token"], c_id_dict["channel_id"])
    details_before = channel.channel_details(user2["token"],
                                             c_id_dict["channel_id"])
    assert details_before["owner_members"][0]["u_id"] == user2["u_id"]
    assert len(details_before["owner_members"]) == 1

    # user2 makes user3 an owner, channel_details should now show two owners
    channel.channel_addowner(user2["token"], c_id_dict["channel_id"],
                             user3["u_id"])
    details_after = channel.channel_details(user2["token"],
                                            c_id_dict["channel_id"])
    assert len(details_after["owner_members"]) == 2
    assert details_after["owner_members"][0]["u_id"] == user2["u_id"]
    assert details_after["owner_members"][1]["u_id"] == user3["u_id"]

    # user1 (admin) joins the channel, he should be owner
    channel.channel_join(user1["token"], c_id_dict["channel_id"])
    details_admin = channel.channel_details(user1["token"],
                                            c_id_dict["channel_id"])
    assert len(details_admin["owner_members"]) == 3
    assert details_admin["owner_members"][2]["u_id"] == user1["u_id"]
예제 #3
0
def test_removeowner_no_owner():
    """
    Tests if channel_removeowner raises an AccessError
    when the user is not an owner of the channel/Slackr
    i.e. test if AccessError raised if user is not an owner of BOTH
    """
    user1 = auth.auth_register("*****@*****.**", "password", "Crazy", "Frog")
    user2 = auth.auth_register("*****@*****.**", "password", "Gummy", "Bear")
    user3 = auth.auth_register("*****@*****.**", "password", "Gummy", "Bear")
    user4 = auth.auth_register("*****@*****.**", "password", "Gummy", "Bear")

    # USER1 is owner of channel and slackr
    # USER2 is not owner of either.

    c_id_dict = channels.channels_create(user1["token"], "test_channel", True)
    channel.channel_join(user2["token"], c_id_dict["channel_id"])
    channel.channel_join(user3["token"], c_id_dict["channel_id"])
    channel.channel_join(user4["token"], c_id_dict["channel_id"])
    channel.channel_addowner(user1['token'], c_id_dict['channel_id'],
                             user4['u_id'])
    with pytest.raises(error.AccessError):
        channel.channel_removeowner(user2["token"], c_id_dict["channel_id"],
                                    user1["u_id"])
    with pytest.raises(error.AccessError):
        channel.channel_removeowner(user3["token"], c_id_dict["channel_id"],
                                    user4["u_id"])
예제 #4
0
def test_addowner_slackr():
    """
    Tests if channel_addowner works if Slackr owner who is not a channel owner tries to use it
    """
    user1 = auth.auth_register("*****@*****.**", "password", "Severus",
                               "Snape")
    user2 = auth.auth_register("*****@*****.**", "password", "Albus",
                               "Dumbledore")
    user3 = auth.auth_register("*****@*****.**", "Potions", "Harry",
                               "Potter")

    c_id_dict = channels.channels_create(user2["token"], "test_channel", True)
    channel.channel_join(user1["token"], c_id_dict["channel_id"])
    channel.channel_join(user3["token"], c_id_dict["channel_id"])

    details_before = channel.channel_details(user2["token"],
                                             c_id_dict["channel_id"])
    assert details_before["owner_members"][0]["u_id"] == user2["u_id"]
    assert details_before["owner_members"][1]["u_id"] == user1["u_id"]
    assert len(details_before["owner_members"]) == 2
    assert len(details_before["all_members"]) == 3
    assert details_before["all_members"][2]["u_id"] == user3["u_id"]

    channel.channel_addowner(user1["token"], c_id_dict["channel_id"],
                             user3["u_id"])
    details_after = channel.channel_details(user2["token"],
                                            c_id_dict["channel_id"])
    assert len(details_after["owner_members"]) == 3
    assert details_after["owner_members"][0]["u_id"] == user2["u_id"]
    assert details_after["owner_members"][1]["u_id"] == user1["u_id"]
    assert details_after["owner_members"][2]["u_id"] == user3["u_id"]
예제 #5
0
def test_addowner_nvid():
    """
    Tests if channel_addowner raises an InputError when channel id is not valid
    """
    user = auth.auth_register("*****@*****.**", "password", "Kazuma", "Sato")
    with pytest.raises(error.InputError):
        channel.channel_addowner(user["token"], 100, user["u_id"])
예제 #6
0
def c_add_owner():
    """ This is a flask wrapper for the channel_addowner function

    Parameters:
        No parameters
    
    Returns:
        (dictionary): Empty dictionary
    """
    #Request information
    data = request.get_json()

    token = data['token']
    u_id = data['u_id']
    channel_id = data['channel_id']

    if not channel_check(channel_id):
        raise InputError(description="Channel is invalid")

    if check_if_user_in_channel_owner_uid(u_id, channel_id):
        raise InputError(description="User already owner of channel")

    if check_if_user_in_channel_owner(token, channel_id):
        raise AccessError(description="User already owner of channel")

    channel_addowner(token, channel_id, u_id)
    return dumps({})
예제 #7
0
def test_channel_addowner_invalid_channel(channel_init):
    '''
    test_channel_addowner_invalid_channel
    '''
    with pytest.raises(InputError):
        #Test with valid user
        channel_addowner(channel_init[0]['token'], "", channel_init[1]['u_id'])
예제 #8
0
def test_channel_addowner_owner_of_channel():
    boyu_dict, _, weiqiang_dict, _, _ = initialise_data()

    team_pineapple = channels_create(boyu_dict['token'], "teamPineapple", True)
    team_pineapple_id = team_pineapple['channel_id']
    channel_addowner(boyu_dict['token'], team_pineapple_id,
                     weiqiang_dict['u_id'])
    details = channel_details(weiqiang_dict['token'], team_pineapple_id)
    assert details == {
        'name':
        'teamPineapple',
        'owner_members': [{
            'u_id': boyu_dict['u_id'],
            'name_first': 'Boyu',
            'name_last': 'Cai',
            'profile_img_url': '',
        }, {
            'u_id': weiqiang_dict['u_id'],
            'name_first': 'Weiqiang',
            'name_last': 'Zhuang',
            'profile_img_url': '',
        }],
        'all_members': [{
            'u_id': boyu_dict['u_id'],
            'name_first': 'Boyu',
            'name_last': 'Cai',
            'profile_img_url': '',
        }, {
            'u_id': weiqiang_dict['u_id'],
            'name_first': 'Weiqiang',
            'name_last': 'Zhuang',
            'profile_img_url': '',
        }],
    }
def test_channel_removeowner():
    '''
    # valid test, it would work well
    # register user1, user2 and user3
    # user2 creates channel1 and invites user1 and user3
    # user2 add user1(automatically) and user3 as owners
    # user2 remove user3 owner permission
    # user2 remove user1 owner permission(cannot happen since user1 is
    #                                     the owner of flockr)
    '''
    clear()
    u1_id = auth.auth_register('*****@*****.**', 'password', 'user1_name',
                               'user1_name')['u_id']
    auth.auth_login('*****@*****.**', 'password')
    u2_id = auth.auth_register('*****@*****.**', 'password', 'user2_name',
                               'user2_name')['u_id']
    token_2 = auth.auth_login('*****@*****.**', 'password')['token']
    u3_id = auth.auth_register('*****@*****.**', 'password', 'user3_name',
                               'user3_name')['u_id']
    auth.auth_login('*****@*****.**', 'password')

    channel_id = channels_create(token_2, 'channel name', True)['channel_id']
    channel.channel_invite(token_2, channel_id, u1_id)
    channel.channel_invite(token_2, channel_id, u3_id)
    assert u1_id not in channels[0]['owner_members']
    assert u2_id in channels[0]['owner_members']
    assert u3_id not in channels[0]['owner_members']

    channel.channel_addowner(token_2, channel_id, u3_id)
    assert u3_id in channels[0]['owner_members']
    channel.channel_removeowner(token_2, channel_id, u3_id)
    assert u3_id not in channels[0]['owner_members']
예제 #10
0
def test_channel_add_owner():
    results = auth_register("*****@*****.**", '123!Asdf', 'John', 'Smith')
    results = auth_login('*****@*****.**', '123!Asdf')
    token1 = results['token']

    results2 = auth_register('*****@*****.**', 'zxc123asd', 'Bob',
                             'Builder')
    results2 = auth_login('*****@*****.**', 'zxc123asd')
    u_id2 = results2['u_id']
    token2 = results2['token']

    channel_info3 = channels_create(token1, 'Slakrs', True)

    channel_addowner(token1, channel_info3, u_id2)

    owners = channel_details(token2, channel_info3)['owner_members']

    print(channel_details(token2, channel_info3))
    print(owners[0]['u_id'])

    is_owner = 0
    j = 0

    for i in owners:
        if u_id2 == owners[j]['u_id']:
            is_owner = 1
        j = +1

    assert is_owner == 1
예제 #11
0
def test_details_returns_correct_output_for_owner():
    '''
    Testing if channel_details works for owners.
    '''
    clear()
    user = auth_register("*****@*****.**", 'password', 'abcd', 'efgh')
    user_token = user.get("token")
    
    user2 = auth_register("*****@*****.**", 'erenyaegar', 'ijklm', 'nopqrs')
    user_token2 = user2.get("token")
    user_id2 = user2.get('u_id')

    user3 = auth_register("*****@*****.**", 'erenyaegar', 'James', 'nopqrs')
    user_token3 = user3.get("token")
    user3.get('u_id')

    channel = channels_create(user_token, "Channel1", True)
    channel_id = channel.get("channel_id")
    channel_join(user_token2, channel_id)
    channel_join(user_token3, channel_id)
    channel_addowner(user_token, channel_id, user_id2)
    details_channel = channel_details(user_token, channel_id)
    assert len(details_channel.get("owner_members")) == 2
    assert details_channel["owner_members"][0]["name_first"] == 'abcd'
    assert details_channel["owner_members"][1]["name_first"] == 'ijklm'
    assert len(details_channel.get("all_members")) == 3
    assert details_channel["all_members"][0]["name_first"] == 'abcd'
    assert details_channel["all_members"][1]["name_first"] == 'ijklm'
    assert details_channel["all_members"][2]["name_first"] == 'James'
def test_channel_addowner_notowner():
    '''
    Test case for trying to make someone an owner while not being an owner
    '''
    clear()
    #Registering a user
    register = auth_register('*****@*****.**', '123abc!@#', 'Hayden',
                             'Everest', None)
    #Storing token generated from registration process in a variable for easy access
    creator_token = register['token']
    #Using the registered user to create a channel
    new_channel = channels_create(creator_token, "Testing Channel", True)
    #Storing channel_id generated from channel creation in a variable for easy access
    channel_id = new_channel['channel_id']

    register1 = auth_register('*****@*****.**', '123abc!@#',
                              'Howard', 'Everdun', None)
    nonowner_u_id = register1['u_id']
    nonowner_token = register1['token']

    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert nonowner_u_id not in channel['owners']
    with pytest.raises(AccessError):
        channel_addowner(nonowner_token, channel_id, nonowner_u_id)

    clear()
예제 #13
0
def test_addowner_inputerror_invalid_user():
    '''
        #change function name from "test_addowner_InputError_invalid_user" to
        #"test_addowner_inputerror_invalid_user"
        #invalid test of user id and u_id is already an owner of the channel
        # register user1 and user2
        # user1 create channel1
        # user1 invites user2
        # user1 add user1 as an owner(add himself)
        # user1 add user2 as an owner twice
    '''
    clear()
    u1_id = auth.auth_register('*****@*****.**', 'password', 'user1_name',
                               'user1_name')['u_id']
    token_1 = auth.auth_login('*****@*****.**', 'password')['token']
    u2_id = auth.auth_register('*****@*****.**', 'password', 'user2_name',
                               'user2_name')['u_id']
    auth.auth_login('*****@*****.**', 'password')
    channel_id = channels_create(token_1, 'channel_name', True)['channel_id']
    channel.channel_invite(token_1, channel_id, u2_id)
    # user1 add himself as an owner
    with pytest.raises(InputError):
        assert channel.channel_addowner(token_1, channel_id, u1_id)
    # user1 add user2 as an owner twice
    channel.channel_addowner(token_1, channel_id, u2_id)
    with pytest.raises(InputError):
        assert channel.channel_addowner(token_1, channel_id, u2_id)
    # given u_id does not refer to a valid user
    with pytest.raises(InputError):
        assert channel.channel_addowner(token_1, channel_id, 0)
    assert u1_id in channels[0]['owner_members']
    assert u2_id in channels[0]['owner_members']
예제 #14
0
def test_channel_removeowner_user_not_channel_owner(auth_fixture):
    '''
    Test case when authorised user is not an owner of the channel and is not an owner of the slackr
    '''
    (server_data, auth_fixture) = auth_fixture
    # get user data
    token1 = auth_fixture[1]['token']
    token3 = auth_fixture[3]['token']
    uid2 = auth_fixture[2]['u_id']
    uid3 = auth_fixture[3]['u_id']

    # create channels with 1 user (user 1 is owner)
    pub_channel_id = channels_create(server_data, token1, 'New_Channel', True)['channel_id']
    priv_channel_id = channels_create(server_data, token1, 'Priv_Channel', False)['channel_id']

    # user2 joins as owner
    channel_addowner(server_data, token1, pub_channel_id, uid2) 
    channel_addowner(server_data, token1, priv_channel_id, uid2) 

    # user3 join channels as member
    channel_invite(server_data, token1, pub_channel_id, uid3)
    channel_invite(server_data, token1, priv_channel_id, uid3)

    # user3 tries to remove user2 from ownership
    with pytest.raises(AccessError) as error_raise:
        channel_removeowner(server_data, token3, pub_channel_id, uid2)

    with pytest.raises(AccessError) as error_raise:
        channel_removeowner(server_data, token3, priv_channel_id, uid2) 
예제 #15
0
def test_channel_addowner_except():
    reset()
    # InputError:
    #   Channel ID is not a valid channel
    u_id, token = get_user("user1")
    owner_id, owner_token = get_user("user2")
    not_owner_id, not_owner_token = get_user("user3")

    # Create a channel with user's token, hence they are already the owner
    channel_id = channels.channels_create(owner_token, "Example Channel",
                                          True)['channel_id']

    with pytest.raises(InputError) as e:
        assert channel.channel_addowner(owner_token, 0, u_id)
    #with pytest.raises(InputError) as e:
    #    assert channel.channel_addowner(owner_token,"somestring",u_id)

    #   When user with user id u_id is already an owner of the channel
    with pytest.raises(InputError) as e:
        assert channel.channel_addowner(owner_token, channel_id, owner_id)

    # Access Error:
    #   The authorised user is not an owner of the slackr, or an owner of this channel
    # Create a private user, who is not an owner of the previously made channel "Example Channel"

    with pytest.raises(AccessError) as e:
        assert channel.channel_addowner(not_owner_token, channel_id, u_id)
예제 #16
0
def test_channel_addowner_user_slackr_owner(auth_fixture):
    '''
    Test case when authorised user is an owner of the slackr
    '''
    (server_data, auth_fixture) = auth_fixture
    # get user details
    tokenslackr = auth_fixture[0]['token']
    token1 = auth_fixture[1]['token']
    token2 = auth_fixture[2]['token']
    u_id2 = auth_fixture[2]['u_id']

    # create channels with 1 user (user 1 is owner)
    channel_id1 = channels_create(server_data, token1, 'New_Channel',
                                  True)['channel_id']
    channel_id2 = channels_create(server_data, token1, 'Another_Channel',
                                  True)['channel_id']

    # add user2 as member to channel1
    channel_invite(server_data, token1, channel_id1, u_id2)

    # slackrowner adds user2 as owner for channel1 (which user2 is a member of) and channel2 (which user2 is not a member of)
    channel_addowner(server_data, tokenslackr, channel_id1, u_id2)
    channel_addowner(server_data, tokenslackr, channel_id2, u_id2)

    # get details of channels
    user2_channel_det1 = channel_details(server_data, token2,
                                         channel_id1)['owner_members']
    user2_channel_det2 = channel_details(server_data, token2,
                                         channel_id2)['owner_members']

    # check that user2 is an owner for both channels
    assert any(True for i in user2_channel_det1 if i['u_id'] == u_id2)
    assert any(True for i in user2_channel_det2 if i['u_id'] == u_id2)
예제 #17
0
def test_channel_addowner_already_member():
    boyu_dict, _, weiqiang_dict, _, _ = initialise_data()

    team_avocado = channels_create(boyu_dict['token'], "teamAvocado", True)
    team_avocado_id = team_avocado['channel_id']
    channel_invite(boyu_dict['token'], team_avocado_id, weiqiang_dict['u_id'])
    channel_addowner(boyu_dict['token'], team_avocado_id,
                     weiqiang_dict['u_id'])
    details = channel_details(weiqiang_dict['token'], team_avocado_id)
    assert details == {
        'name':
        'teamAvocado',
        'owner_members': [{
            'u_id': boyu_dict['u_id'],
            'name_first': 'Boyu',
            'name_last': 'Cai',
            'profile_img_url': '',
        }, {
            'u_id': weiqiang_dict['u_id'],
            'name_first': 'Weiqiang',
            'name_last': 'Zhuang',
            'profile_img_url': '',
        }],
        'all_members': [{
            'u_id': boyu_dict['u_id'],
            'name_first': 'Boyu',
            'name_last': 'Cai',
            'profile_img_url': '',
        }, {
            'u_id': weiqiang_dict['u_id'],
            'name_first': 'Weiqiang',
            'name_last': 'Zhuang',
            'profile_img_url': '',
        }],
    }
예제 #18
0
def test_channel_delete_owner_of_channel():
    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'])
    details = channel_details(weiqiang_dict['token'], team_pears_id)
    # check the values returned by channel_details
    assert details == {
        'name':
        'teamPears',
        'owner_members': [{
            'u_id': weiqiang_dict['u_id'],
            'name_first': 'Weiqiang',
            'name_last': 'Zhuang',
            'profile_img_url': '',
        }],
        'all_members': [{
            'u_id': boyu_dict['u_id'],
            'name_first': 'Boyu',
            'name_last': 'Cai',
            'profile_img_url': '',
        }, {
            'u_id': weiqiang_dict['u_id'],
            'name_first': 'Weiqiang',
            'name_last': 'Zhuang',
            'profile_img_url': '',
        }],
    }
예제 #19
0
def addowner_channel():
    data = request.get_json()
    token = str(data['token'])
    channel_id = int(data['channel_id'])
    u_id = int(data['u_id'])
    channel_addowner(token, channel_id, u_id)
    return dumps({})
def initialisation():
    clear()
    Benjamin = auth_register("*****@*****.**", "password", "Benjamin", "Long")  # ID = 0
    Ross = auth_register("*****@*****.**", "password", "Ross", "Short")             # ID = 1
    Alex = auth_register("*****@*****.**", "password", "Alex", "Smith")             # ID = 2

    channel_id0 = channels_create(Benjamin['token'], "Channel0", True)  # ID = 0
    channel_id1 = channels_create(Ross['token'], "Channel1", True)     # ID = 1
    channel_id2 = channels_create(Benjamin['token'], "Channel2", True)  # ID = 2
    channel_id3 = channels_create(Benjamin['token'], "Channel3", True)  # ID = 3

    # Everyone is in channel 0
    channel_invite(Benjamin['token'], channel_id0['channel_id'], Ross['u_id'])
    channel_invite(Benjamin['token'], channel_id0['channel_id'], Alex['u_id'])

    # Ross and Alex are in channel 1 but not Benjamin
    channel_invite(Ross['token'], channel_id1['channel_id'], Alex['u_id'])

    # Ben + Ross == Owner
    channel_invite(Benjamin['token'], channel_id2['channel_id'], Ross['u_id'])
    channel_invite(Benjamin['token'], channel_id2['channel_id'], Alex['u_id'])
    channel_addowner(Benjamin['token'],channel_id2['channel_id'], Ross['u_id'])

    # Ben is only member and owner of channel 3

    return Benjamin, Ross, Alex, channel_id0, channel_id1, channel_id2, channel_id3
예제 #21
0
def test_channel_removeowner_good(reset, create_public_channel, create_user1):
    '''
    Assuming addowner works fine, we test removing a message after ownership is removed
    '''

    # creating a public channel
    channel_id, owner_info = create_public_channel
    # creating normal users
    user_info = create_user1
    # sending a message that we will test deleting afterwards
    msg_id = message_send(owner_info['token'], channel_id['channel_id'],
                          "First owner's Message 1!")
    msg_id2 = message_send(owner_info['token'], channel_id['channel_id'],
                           "First owner's  Message 2!")
    # adding general user as an owner to the channel
    channel_addowner(owner_info['token'], channel_id['channel_id'],
                     user_info['u_id'])
    # trying to remove a message to check if addowner works
    message_remove(user_info['token'], msg_id2['message_id'])
    messages = channel_messages(owner_info['token'], channel_id['channel_id'],
                                0)
    assert len(messages['messages']) == 2
    # removing user from being an owner
    channel_removeowner(owner_info['token'], channel_id['channel_id'],
                        user_info['u_id'])
    # trying to remove a message as a user, it should produce AccessError
    with pytest.raises(AccessError):
        message_remove(user_info['token'], msg_id['message_id'])
예제 #22
0
def test_channel_removeowner_owner():
    '''
    Tests removing an owner
    '''
    clear()
    #Registering a user
    register = auth_register('*****@*****.**', '123abc!@#', 'Hayden',
                             'Everest', None)
    #Storing token generated from registration process in a variable for easy access
    owner_token = register['token']
    #Registering another user
    register1 = auth_register('*****@*****.**', '123abc!@#',
                              'Jordan', 'Fitch', None)
    #Storing u_id generated from registration process in a variable for easy access
    nonowner_u_id = register1['u_id']
    #Using the registered user to create a channel
    new_channel = channels_create(owner_token, "Testing Channel", True)

    #Storing channel_id generated from channel creation in a variable for easy access
    channel_id = new_channel['channel_id']

    channel_addowner(owner_token, channel_id, nonowner_u_id)
    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert len(channel['owners']) == 2

    channel_removeowner(owner_token, channel_id, nonowner_u_id)

    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert len(channel['owners']) == 1
    clear()
예제 #23
0
def test_permissions_removeowner():
    '''
    If permissions updated then no errors raised when removing.
    '''
    clear()
    #flock owner
    user_1 = auth_register("*****@*****.**", "passwordOne", "Firstone", "Lastone")
    user_1_token = user_1.get('token')

    #change permissions to flock owner
    user_2 = auth_register("*****@*****.**", "passwordTwo", "Firsttwo", "Lasttwo")
    user_2_id = user_2.get('u_id')
    user_2_token = user_2.get('token')

    #add as channel owner
    user_3 = auth_register("*****@*****.**", "passwordOne", "Firstone", "Lastone")
    user_3_id = user_3.get('u_id')

    #make user 2 become owner
    admin_userpermission_change(user_1_token, user_2_id, 1)

    channel = channels_create(user_1_token, "channel1", True)
    
    channel1_id = channel.get("channel_id") 

    channel_join(user_2_token, channel1_id)

    channel_addowner(user_1_token, channel1_id, user_3_id)

    channel_removeowner(user_2_token, channel1_id, user_3_id)
예제 #24
0
def test_channel_addowner_user_not_channel_owner(auth_fixture):
    '''
    Test case when authorised user is not an owner of the channel or not an owner of slack
    '''
    (server_data, auth_fixture) = auth_fixture
    # get user data
    token1 = auth_fixture[1]['token']
    token2 = auth_fixture[2]['token']
    u_id2 = auth_fixture[2]['u_id']
    u_id3 = auth_fixture[3]['u_id']

    # create channels with 1 user (user 1 is owner)
    pub_channel_id = channels_create(server_data, token1, 'New_Channel',
                                     True)['channel_id']
    priv_channel_id = channels_create(server_data, token1, 'Priv_Channel',
                                      False)['channel_id']

    # user2 and user3 join channels
    channel_invite(server_data, token1, pub_channel_id, u_id2)
    channel_invite(server_data, token1, pub_channel_id, u_id3)
    channel_invite(server_data, token1, priv_channel_id, u_id2)
    channel_invite(server_data, token1, priv_channel_id, u_id3)

    # user2 (non slack or channel owner) tries to add user3 as an owner
    with pytest.raises(AccessError) as error_raise:
        channel_addowner(server_data, token2, pub_channel_id, u_id3)

    with pytest.raises(AccessError) as error_raise:
        channel_addowner(server_data, token2, priv_channel_id, u_id3)
예제 #25
0
def test_channel_removeowner(auth_fixture):
    '''
    Test case for a simple channel removeowner
    - owner removing another owner in the same channel
    '''
    (server_data, auth_fixture) = auth_fixture
    # get user details
    token1 = auth_fixture[1]['token']
    token2 = auth_fixture[2]['token']
    uid2 = auth_fixture[2]['u_id']

    # create channels with user1 then add user2 as owner
    pub_channel_id = channels_create(server_data, token1, 'New_Channel', True)['channel_id']
    priv_channel_id = channels_create(server_data, token1, 'Priv_Channel', False)['channel_id']
    channel_addowner(server_data, token1, pub_channel_id, uid2)
    channel_addowner(server_data, token1, priv_channel_id, uid2) 
    
    # user1 removes user2 from owner permissions
    channel_removeowner(server_data, token1, pub_channel_id, uid2)
    channel_removeowner(server_data, token1, priv_channel_id, uid2)

    # check channel details to make sure user 2 is a non owner member
    user2_channel_det1 = channel_details(server_data, token2, pub_channel_id)['owner_members']
    user2_channel_det2 = channel_details(server_data, token2, priv_channel_id)['owner_members']
    
    # owner member list should not have any ids equal to the id of user2 
    assert not any(True for i in user2_channel_det1 if i['u_id'] == uid2)
    assert not any(True for i in user2_channel_det2 if i['u_id'] == uid2)
예제 #26
0
def test_addowner_standard():
    info = starter()
    u0, u1, u3, c1 = info[0], info[1], info[3], info[4]

    # get user information
    u3_info = {
        'u_id': u3['u_id'],
        'name_first': 'Charlie',
        'name_last': 'Barry'
    }
    u0_info = {
        'u_id': u0['u_id'],
        'name_first': 'King',
        'name_last': 'Kingson'
    }
    u1_info = {
        'u_id': u1['u_id'],
        'name_first': 'Elizabeth',
        'name_last': 'Alexander'
    }

    # global owner user 0 joins public channel and is added as owner of channel
    channel.channel_join(u0['token'], c1['channel_id'])
    # user 0 adds user 1 as an owner of the channel
    channel.channel_addowner(u0['token'], c1['channel_id'], u1['u_id'])
    # user 1 should appear in both channel members and owners lists
    details = channel.channel_details(u0['token'], c1['channel_id'])
    assert details['owner_members'] == [u3_info, u0_info, u1_info]
    assert details['all_members'] == [u3_info, u0_info, u1_info]
예제 #27
0
def test_removeowner_standard():
    info = starter()
    u1, u2, u3, c1 = info[1], info[2], info[3], info[4]

    # get user information
    u2_info = {'u_id': u2['u_id'], 'name_first': 'Jane', 'name_last': 'Anton'}
    u3_info = {
        'u_id': u3['u_id'],
        'name_first': 'Charlie',
        'name_last': 'Barry'
    }

    # user 3 adds user 1 as an owner
    channel.channel_addowner(u3['token'], c1['channel_id'], u1['u_id'])
    # user 3 adds user 2 as an owner
    channel.channel_addowner(u3['token'], c1['channel_id'], u2['u_id'])

    # user 2 removes user 1 as owner
    channel.channel_removeowner(u2['token'], c1['channel_id'], u1['u_id'])
    # user 1 should not be in owners list
    details = channel.channel_details(u2['token'], c1['channel_id'])
    assert details['owner_members'] == [u3_info, u2_info]

    # user 2 removes herself as channel owner
    channel.channel_removeowner(u2['token'], c1['channel_id'], u2['u_id'])
    # channel should have one owner now
    details = channel.channel_details(u2['token'], c1['channel_id'])
    assert details['owner_members'] == [u3_info]
예제 #28
0
def test_channel_addowner_already_owner():
    clear()
    user_0, user_1 = create_two_test_users()
    public_channel = channels_create(user_0['token'], "name", True)
    channel_join(user_1['token'], public_channel['channel_id'])
    channel_addowner(user_0['token'], public_channel['channel_id'], user_1['u_id'])
    with pytest.raises(error.InputError):
        channel_addowner(user_0['token'], public_channel['channel_id'], user_1['u_id'])
예제 #29
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)
예제 #30
0
def test_add_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"])
    with pytest.raises(InputError):
        invalid_channel_id = 233
        channel_addowner(user_A["token"], invalid_channel_id, user_B["u_id"])