def test_details_invalid_channel_id(): '''Function won't work if channel id is invalid''' reset_data() data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang') token = data['token'] channels_create(token, 'Channel One', True) with pytest.raises(InputError): channel_details(token, 2)
def test_details_invalid_channel_member(): '''Function won't work if authorised user is not member of 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'] with pytest.raises(AccessError): channel_details(token_two, channel_id['channel_id'])
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 details(): '''Provides the details of a channel''' return dumps( channel_details(request.args.get('token'), request.args.get('channel_id')))
def details_channel(): token = request.args.get('token') #assert token is not None channel_idp = request.args.get('channel_id') channel_id = int(channel_idp) return channel_details(token, channel_id, da.CHANNEL, da.USERS)