def test_channel_join_successful(): 'Successful case' workspace_reset() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] u_id1 = user1['u_id'] channel_info = ret['channel'] channel_id = channel_info['channel_id'] channel.leave(token1, channel_id) channel.join(token1, channel_id) assert channel.details(token1, channel_id)['name'] == 'firstChannel' assert channel.details(token1, channel_id)['owner_members'] == [{ 'u_id': u_id1, 'name_first': 'Kennan', 'name_last': 'Wong' }] assert channel.details(token1, channel_id)['all_members'] == [{ 'u_id': u_id1, 'name_first': 'Kennan', 'name_last': 'Wong' }]
def test_admin_user_remove_successful3(): 'Successful case with messages' workspace_reset() channel_store = get_channel_data_store() messages_store = get_messages_store() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] u_id1 = user1['u_id'] user2 = reg_user2() token2 = user2['token'] u_id2 = user2['u_id'] channel_info = ret['channel'] channel_id = channel_info['channel_id'] channel.join(token2, channel_id) payload = {'token': token1, 'u_id': u_id2} msg1 = send_msg1(user2, channel_info) # Remove user1 from slackr user_remove(payload) user2_dets = user_details(u_id2) channel_info = ret['channel'] channel_id = channel_info['channel_id'] for curr_channel in channel_store: channel_id = curr_channel['channel_id'] if user2_dets in curr_channel['members']: assert channel.details(token1, channel_id)['all_members'] == [{ "u_id": u_id1, "name_first": 'Kennan', "name_last": 'Wong' }] if user2_dets in curr_channel['owners']: assert channel.details(token1, channel_id)['owner_members'] == [{ "u_id": u_id1, "name_first": 'Kennan', "name_last": 'Wong' }] assert msg1 not in messages_store assert msg1 not in channel_info['messages']
def test_channel_details_invalid_channel(): 'Invalid channel case' workspace_reset() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] channel_info = ret['channel'] # InputError when we try to get details of an invalid channel # Invalid channel_id = 100 with pytest.raises(InputError) as e: channel.details(token1, 100)
def test_channel_details_unauthorised(): 'User is not a member case' workspace_reset() ret = register_and_create() user2 = reg_user2() token2 = user2['token'] channel_info = ret['channel'] channel_id = channel_info['channel_id'] # AccessError when we try to get details of channel where the user isn't a member # user2 isn't a member with pytest.raises(AccessError) as e: channel.details(token2, channel_id)
def test_channel_remove_owner(): 'Normal case' workspace_reset() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] u_id1 = user1['u_id'] channel_info = ret['channel'] user2 = reg_user2() token2 = user2['token'] u_id2 = user2['u_id'] channel_id = channel_info['channel_id'] channel.join(token2, channel_id) channel.addowner(token1, channel_id, u_id2) # User2 removes user1 as owner channel.removeowner(token2, channel_id, u_id1) assert channel.details(token1, channel_id)['owner_members'] == [{ "u_id": u_id2, "name_first": 'Cindy', "name_last": 'Tran' }]