def test_channels_list_under_channel_join(): '''User 1 make 2 channels, User 2 joins them and channel list updates''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] #Creates Channel One under User One's token which adds user to channel channel_id = channels_create(token, "Channel One", True) user_one_channel_list = channels_list(token) assert len(user_one_channel_list['channels']) == 1 #Creates Channel Two under User One's token which adds user to channel channel_two_id = channels_create(token, "Channel Two", True) user_one_channel_list = channels_list(token) assert len(user_one_channel_list['channels']) == 2 #Register User Two data_two = auth_register('*****@*****.**', 'cs1531', 'Yuri', 'Jo') token_two = data_two['token'] #Assert that User Two's channel_list is empty user_two_channel_list = channels_list(token_two) assert bool(user_two_channel_list['channels']) is False #User Two joins Channel One and channel list is updated channel_join(token_two, channel_id['channel_id']) user_two_channel_list = channels_list(token_two) assert len(user_two_channel_list['channels']) == 1 #User Two joins Channel Two and channel list is updated channel_join(token_two, channel_two_id['channel_id']) user_two_channel_list = channels_list(token_two) assert len(user_two_channel_list['channels']) == 2
def test_channel_leave(): '''Authorised user is given permission to leave channel''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] channel_id = channels_create(token, 'Channel One', True) data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi') token_two = data_two['token'] channel_join(token_two, channel_id['channel_id']) assert channel_leave(token_two, channel_id['channel_id']) == {}
def test_channel_join_private_channel(): '''Authorised user can't join private channel''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] channel_id = channels_create(token, 'Channel One', False) data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi') token_two = data_two['token'] with pytest.raises(AccessError): channel_join(token_two, channel_id['channel_id'])
def test_channel_join_invalid_channel_id(): '''Authorised user can't join channel with invalid channel id''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] channel_id = channels_create(token, 'Channel One', True) data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi') token_two = data_two['token'] assert channel_id['channel_id'] == 1 with pytest.raises(InputError): channel_join(token_two, 2)
def test_edit_other(): '''Cannot edit another user's message when not admin/owner''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] channel_id = channels_create(token, 'Channel One', True) message_id = message_send(token, channel_id['channel_id'], 'Hello World') data_two = auth_register('*****@*****.**', 'IZ*ONE', 'Yena', 'Choi') token_two = data_two['token'] channel_join(token_two, channel_id['channel_id']) with pytest.raises(AccessError): message_edit(token_two, message_id['message_id'], 'Promote IZ*ONE')
def test_channel_details(): '''Function should return some details of specified channel''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] user_id = data['u_id'] channel_id = channels_create(token, 'Channel One', True) data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi') token_two = data_two['token'] user_two_id = data_two['u_id'] channel_join(token_two, channel_id['channel_id']) channel_dict = channel_details(token, channel_id['channel_id']) assert channel_dict['name'] == 'Channel One' assert channel_dict['owner_members'] == [user_id] assert channel_dict['all_members'] == [user_id, user_two_id]
def test_channel_join(): '''Function should allow authorised user to join channel''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] channel_id = channels_create(token, 'Channel One', True) data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi') token_two = data_two['token'] assert channel_join(token_two, channel_id['channel_id']) == {}
def join(): '''Authorised user adds a new user to the channel''' details = request.get_json() return dumps(channel_join(details['token'], details['channel_id']))
def join_channel(): response = request.get_json() token = response['token'] channel_id = response['channel_id'] channel_join(token, channel_id, da.USERS, da.CHANNEL) return dumps({})