def test_channel_removeowner_unauthorized_user(setup1, setup2, setup3): data = getData() reset_channels() ''' Creates a public channel (Admin: user1) ''' channelsCreate1 = channels_create(setup1['token'], "Public Channel", True) channelId1 = channelsCreate1['channel_id'] ''' Error when not-an-owner tries to remove another user as an owner''' with pytest.raises(AccessError, match=r".*"): channel_removeowner(setup2['token'], channelId1, setup1['u_id'])
def test_channel_removeowner_yourself(setup1, setup2, setup3): data = getData() reset_channels() ''' Creates a public channel (Admin: user1) ''' channelsCreate1 = channels_create(setup1['token'], "Public Channel", True) channelId1 = channelsCreate1['channel_id'] ''' User1 removes attempts to remove themself as an owner ''' ''' (Assumption) It is impossible to remove yourself as an owner (if you are the only owner) ''' with pytest.raises(ValueError_http, match=r".*"): channel_removeowner(setup1['token'], channelId1, setup1['u_id'])
def test_channel_removeowner_no_channel(setup1, setup2, setup3): data = getData() reset_channels() ''' Creates a public channel (Admin: user1) ''' channelsCreate1 = channels_create(setup1['token'], "Public Channel", True) channelId1 = channelsCreate1['channel_id'] ''' User2 joins the channel ''' channel_join(setup2['token'], channelId1) ''' Adds user2 as owner of "Public Channel" ''' channel_addowner(setup1['token'], channelId1, setup2['u_id']) ''' Error when channel does not exist ''' with pytest.raises(ValueError_http, match=r".*"): channel_removeowner(setup1['token'], -1, setup2['u_id'])
def test_channel_removeowner_success(setup1, setup2, setup3): data = getData() reset_channels() ''' Creates a public channel (Admin: user1) ''' channelsCreate1 = channels_create(setup1['token'], "Public Channel", True) channelId1 = channelsCreate1['channel_id'] ''' User 2 joins the channel ''' channel_join(setup2['token'], channelId1) ''' Adds user2 as an owner ''' channel_addowner(setup1['token'], channelId1, setup2['u_id']) ''' User2 removes user1 as owner ''' channel_removeowner(setup2['token'], channelId1, setup1['u_id']) details = channel_details(setup2['token'], channelId1) assert details['owner_members'] == [{ 'u_id': setup2['u_id'], 'name_first': "Fairuz", 'name_last': "Alam", 'profile_img_url': "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg/440px-An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg" }]