def run_channel_addowner(): request_data = request.form return_value = channel.channel_addowner( request_data["token"], int(request_data["channel_id"]), int(request_data["u_id"]) ) return dumps(return_value)
def test_channel_addowner(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] uid2 = auth_dic2['u_id'] auth_dic3 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic3 = auth_login("*****@*****.**", "123456") token3 = auth_dic3['token'] uid3 = auth_dic3['u_id'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] channel_join(token2, channel_id1) channel_join(token3, channel_id1) # create a private channel channelid_dic2 = channels_create(token2, "channel 2", True) channel_id2 = channelid_dic2['channel_id'] channel_join(token3, channel_id2) # SETUP END # successful test assert channel_addowner(token1, channel_id1, uid2) == {} assert channel_addowner(token1, channel_id2, uid3) == {} # token 1 is the owner of the slackr # error test with pytest.raises(ValueError): # Channel (based on ID) does not exist channel_addowner(token1, 10, uid2) with pytest.raises(ValueError): # When user with user id u_id is already an owner of the channel channel_addowner(token1, channel_id1, uid2) with pytest.raises(ValueError): # When the user with u_id is not a member of the channel channel_addowner(token1, channel_id2, uid2) with pytest.raises(AccessError): # when the authorised user is not an owner of the slackr, or an owner of this channel channel_addowner(token3, channel_id1, uid3) # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) reset_data()
def test_message_remove(): reset_data() # SETUP BEGIN authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego') auth_login('*****@*****.**', '123456') token1 = authRegisterDict1['token'] authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan') auth_login('*****@*****.**', '123456') token2 = authRegisterDict2['token'] uid2 = authRegisterDict2['u_id'] authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith') auth_login('*****@*****.**', '123456') token3 = authRegisterDict3['token'] authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis') auth_login('*****@*****.**', '123456') token4 = authRegisterDict4['token'] channelidDict1 = channels_create(token1, 'channel_1', True) channel_id1 = channelidDict1['channel_id'] channel_join(token2, channel_id1) channel_addowner(token1, channel_id1, uid2) channel_join(token3, channel_id1) messages_dic1 = message_send(token1, channel_id1, "hello") message_id = messages_dic1['message_id'] # SETUP END # The right example # the message_id is a valid message for user1 assert message_remove(token1, message_id) == {} # send again messages_dic1 = message_send(token1, channel_id1, "hello") message_id = messages_dic1['message_id'] # the right example # Message_id was not sent by the authorised user token2, # but the token2 is a owner of this channel assert message_remove(token2, message_id) == {} # send again messages_dic1 = message_send(token1, channel_id1, "hello") message_id = messages_dic1['message_id'] with pytest.raises(ValueError): # assume Message id 2 no longer exists message_remove(token1, 10) with pytest.raises(AccessError): # assume token3 is not an owner of this channel that contain message_id message_remove(token3, message_id) with pytest.raises(AccessError): # assume token4 is not an admin or owner of the slack message_remove(token4, message_id) # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) auth_logout(token4)
def channels_addowner(): token = request.form.get('token') channel_id = request.form.get('channel_id') u_id = request.form.get('u_id') return dumps(channel_addowner(token, channel_id, u_id))
def app_channel_addowner(): token = get_args('token') channel_id = int(get_args('channel_id')) u_id = int(get_args('u_id')) return dumps(channel_addowner(token, channel_id, u_id))