def test_flockr_owner(): clear() # Register and login the global owner auth_register("*****@*****.**", "password", "First", "Last") flockr_owner = auth_login("*****@*****.**", "password") # Register and login 2 other users auth_register("*****@*****.**", "password", "First", "Last") owner_1 = auth_login("*****@*****.**", "password") auth_register("*****@*****.**", "password", "First", "Last") owner_2 = auth_login("*****@*****.**", "password") # Create a channel for owner_1 public = True owner_1_c_id = channels_create(owner_1['token'], "Channel", public)['channel_id'] channel_join(owner_2['token'], owner_1_c_id) # Make owner_2 actually an owner channel_addowner(owner_1['token'], owner_1_c_id, owner_2['u_id']) # The flockr_owner removes owner_2 as an owner channel_removeowner(flockr_owner['token'], owner_1_c_id, owner_2['u_id']) details = channel_details(owner_1['token'], owner_1_c_id) assert len(details['owner_members']) == 1 assert details['owner_members'][0]['u_id'] == 1
def test_invalid_owner_remove_2(channel_with_2_owners): owner = channel_with_2_owners auth_register("*****@*****.**", "password", "First", "Last") not_owner = auth_login("*****@*****.**", "password") channel_join(not_owner['token'], owner['c_id']['channel_id']) with pytest.raises(AccessError): channel_removeowner(not_owner['token'], owner['c_id']['channel_id'], owner['token_2']['u_id'])
def test_remove_owner_success(channel_with_2_owners): owner = channel_with_2_owners original_channel = channel_details(owner['token_1']['token'], owner['c_id']['channel_id']) assert len(original_channel['owner_members']) == 2 assert original_channel['owner_members'][0]['u_id'] == 0 assert original_channel['owner_members'][1]['u_id'] == 2 channel_removeowner(owner['token_1']['token'], owner['c_id']['channel_id'], owner['token_2']['u_id']) updated_channel = channel_details(owner['token_1']['token'], owner['c_id']['channel_id']) assert len(updated_channel['owner_members']) == 1 assert updated_channel['owner_members'][0]['u_id'] == 0
def channel_removeowner_flask(): payload = request.get_json() token = payload['token'] channel_id = payload['channel_id'] u_id = payload['u_id'] return dumps(c.channel_removeowner(token, channel_id, u_id))
def test_ivalid_u_id(channel_with_2_owners): owner = channel_with_2_owners invalid_u_id = -1 with pytest.raises(InputError): channel_removeowner(owner['token_1']['token'], owner['c_id']['channel_id'], invalid_u_id)
def test_invalid_token(channel_with_2_owners): owner = channel_with_2_owners with pytest.raises(AccessError): channel_removeowner(token_hash(1), owner['c_id']['channel_id'], owner['token_2']['u_id'])