def test_addOwner_succ(): token = A['token'] u_id = B['u_id'] Pub_channel = CF.channels_create(A['token'], 'Test1', 'True') channelID = Pub_channel['channel_id'] CF.channel_addowner(token, channelID, u_id)
def test_user_NOTLOGIN(): token = A['token'] auth_logout(token) channelID = Pub_channel['channel_id'] u_id = B['u_id'] with pytest.raises(CF.AccessError): CF.channel_addowner(token, channelID, u_id)
def test_invlaid_UID_ADOWNER(): token = A['token'] channelID = Pub_channel['channel_id'] u_id = None with pytest.raises(TypeError): CF.channel_addowner(token, channelID, u_id)
def test_addOwner_invalid_token(): token = A['token'] + '100010' channelID = Pub_channel['channel_id'] u_id = B['u_id'] with pytest.raises(TF.AccessError): CF.channel_addowner(token, channelID, u_id)
def test_channel_addowner(): ''' Function tests for channel_addowner ''' #Initialisation global_var.initialise_all() owner = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token_owner = owner["token"] user1 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name",\ "valid_correct_last_name") token1 = user1["token"] userid1 = user1["u_id"] user2 = auth_register("*****@*****.**",\ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") userid2 = user2["u_id"] token2 = user2["token"] #owner creates a channel and is automatically the owner channel = func.channels_create(token_owner, "TestChannel", True) channel_id = channel["channel_id"] # Initialisation finished #if given an invalid channel_id with pytest.raises(ValueError, match="Channel does not exist"): func.channel_addowner(token_owner, 100, userid1) #token 1&2 joins channel that owner created func.channel_join(token1, channel_id) func.channel_join(token2, channel_id) #token1 is not an owner of the channel with pytest.raises(AccessError, match="User is not an owner of the channel"): func.channel_addowner(token1, channel_id, userid2) # owner successfully promotes user to owner assert func.channel_addowner(token_owner, channel_id, userid1) == {} # user 1 can now promote other to owner assert func.channel_addowner(token1, channel_id, userid2) == {} #token1/userid1 is already an owner of the channel with pytest.raises(ValueError, match="User is already an owner of the channel"): func.channel_addowner(token_owner, channel_id, userid1) # The function is called using a invalid token with pytest.raises(AccessError, match="Invalid token"): func.channel_addowner("12345", channel_id, userid1)
def test_cant_promote(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") Pub_channel = CF.channels_create(A['token'], 'Test1', 'True') token = A['token'] u_id = 1234567 channelID = Pub_channel['channel_id'] CF.channel_addowner(token, channelID, u_id)
def test_canNot_addOwner(): auth_login("*****@*****.**", 'HoyaLee2019') token = A['token'] u_id = A['u_id'] Pub_channel = CF.channels_create(A['token'], 'Test1', 'True') channelID = Pub_channel['channel_id'] with pytest.raises(CHF.ValueError): CF.channel_addowner(token, channelID, u_id)
def test_invlaid_channelID_ADOWNER(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") token = A['token'] channelID = None u_id = B['u_id'] with pytest.raises(TypeError): CF.channel_addowner(token, channelID, u_id)
def test_memeber_addOwner(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") Pub_channel = CF.channels_create(A['token'], 'Test1', 'True') CF.channel_join(B['token'], Pub_channel['channel_id']) token = A['token'] u_id = B['u_id'] channelID = Pub_channel['channel_id'] CF.channel_addowner(token, channelID, u_id)
def test_user_REMOVE_SUCC(): reset_data() B = auth_register("*****@*****.**", "wsad1990", "Tony", "Hex") A = auth_register("*****@*****.**", 'HoyaLee2019', 'Hoya', 'Lee') Pub_channel = CF.channels_create(A['token'], 'channelFirst', 'True') CF.channel_addowner(A['token'], Pub_channel['channel_id'], B['u_id']) token = A['token'] u_id = B['u_id'] channelID = Pub_channel['channel_id'] CF.channel_addowner(token, channelID, u_id) CF.channel_removeowner(token, channelID, u_id)
def test_channel_removeowner(): ''' Function tests for channel_removeowner ''' #Initialisation global_var.initialise_all() user1 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token1 = user1["token"] userid1 = user1["u_id"] user2 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token2 = user2["token"] userid2 = user2["u_id"] #token1 create a channel channel = func.channels_create(token1, "TestChannel", True) channel_id = channel["channel_id"] #token2 joins the channel token1 made func.channel_join(token2, channel_id) # Initialisation finished #user2 is not the owner, thus trying to removeowner raises an error with pytest.raises(ValueError, match=\ "User id is not an owner of the channel"): func.channel_removeowner(token1, channel_id, userid2) # user2 is not the owner and tries to remove owner of channel with pytest.raises(AccessError, match=\ "User is not an owner of the channel or slackrowner"): func.channel_removeowner(token2, channel_id, userid1) #token1 makes token2 a owner func.channel_addowner(token1, channel_id, userid2) assert func.channel_removeowner(token1, channel_id, userid2) == {} #if given an invalid channel_id with pytest.raises(ValueError, match="Channel does not exist"): func.channel_removeowner(token1, 100, userid2) # The function is called using a invalid token with pytest.raises(AccessError, match="Invalid token"): func.channel_removeowner("12345", channel_id, userid2)
def channel_addowner(): """ Make a user an owner of the channel """ token = request.form.get("token") channel_id = to_int(request.form.get("channel_id")) u_id = to_int(request.form.get("u_id")) return dumps(channel.channel_addowner(token, channel_id, u_id))