def test_join_channel_successfully(): clear() user_A, user_B = register_n_users(2) public_channel = channels_create(user_A["token"], "Channel_A", True) channel_join(user_B["token"], public_channel["channel_id"]) details = channel_details(user_A["token"], public_channel["channel_id"]) expected_member_ids = [user_A["u_id"], user_B["u_id"]] assert_contains_users_id(details["all_members"], expected_member_ids)
def test_remove_the_only_owner(): clear() user_A, user_B = register_n_users(2) public_channel = channels_create(user_A["token"], "public_channel", True) channel_join(user_B["token"], public_channel["channel_id"]) channel_removeowner(user_A["token"], public_channel["channel_id"], user_A["u_id"]) details = channel_details(user_B["token"], public_channel["channel_id"]) expected_owner_ids = [user_B["u_id"]] assert_contains_users_id(details["owner_members"], expected_owner_ids)
def test_channel_addowner_admin_private_channel(): clear() admin, usera = register_n_users(2, include_admin=True) channel_id = channels_create(usera["token"], "channel", is_public=False)["channel_id"] channel_addowner(admin["token"], channel_id, admin["u_id"]) details = channel_details(usera["token"], channel_id) assert_contains_users_id(details["all_members"], [admin["u_id"], usera["u_id"]]) assert_contains_users_id(details["owner_members"], [admin["u_id"], usera["u_id"]])
def test_add_owner_successfully(): clear() user_A, user_B = register_n_users(2) public_channel = channels_create(user_A["token"], "public_channel", True) channel_join(user_B["token"], public_channel["channel_id"]) # user_A add user_B as onwer, gotta check whether user_B is in owner list channel_addowner(user_A["token"], public_channel["channel_id"], user_B["u_id"]) details = channel_details(user_A["token"], public_channel["channel_id"]) expect_owner_in_channel = [user_A["u_id"], user_B["u_id"]] assert_contains_users_id(details["owner_members"], expect_owner_in_channel)
def test_add_non_members_as_owner(): clear() user_a, user_b = register_n_users(2) public_channel = channels_create(user_a["token"], "public_channel", True) # invite user from outside this channel channel_addowner(user_a["token"], public_channel["channel_id"], user_b["u_id"]) details = channel_details(user_a["token"], public_channel["channel_id"]) expect_owner_in_channel = [user_a["u_id"], user_b["u_id"]] expect_member_in_channel = [user_a["u_id"], user_b["u_id"]] # We assume user who is invited will be the member and owner of this channel assert_contains_users_id(details["owner_members"], expect_owner_in_channel) assert_contains_users_id(details["all_members"], expect_member_in_channel)
def test_channel_removeowner_admin_last_owner_with_members(): clear() admin, usera, userb = register_n_users(3, include_admin=True) # A creates his channel and B joins channel_id = channels_create(usera["token"], "", is_public=True)["channel_id"] channel_join(userb["token"], channel_id) # admin removes A as an owner channel_removeowner(admin["token"], channel_id, usera["u_id"]) # B becomes an owner, and A is just a regular member details = channel_details(usera["token"], channel_id) assert_contains_users_id(details["owner_members"], [userb["u_id"]]) assert_contains_users_id(details["all_members"], [userb["u_id"], usera["u_id"]])
def test_remove_user_successfully(): clear() user_A, user_B = register_n_users(2) public_channel = channels_create(user_A["token"], "public_channel", True) channel_join(user_B["token"], public_channel["channel_id"]) # Add user_B as owner and check whether user_B is in the owner list channel_addowner(user_A["token"], public_channel["channel_id"], user_B["u_id"]) details = channel_details(user_A["token"], public_channel["channel_id"]) expect_owner_in_channel = [user_A["u_id"], user_B["u_id"]] assert_contains_users_id(details["owner_members"], expect_owner_in_channel) # Remove user_B from owner list and check whether user_B has been removed channel_removeowner(user_A["token"], public_channel["channel_id"], user_B["u_id"]) details = channel_details(user_A["token"], public_channel["channel_id"]) expect_owner_in_channel = [user_A["u_id"]] assert_contains_users_id(details["owner_members"], expect_owner_in_channel)
def test_channel_removeowner_admin_remaining_owners(): clear() admin, usera, userb = register_n_users(3, include_admin=True) # A creates channel and adds B as an owner channel_id = channels_create(usera["token"], "", is_public=True)["channel_id"] channel_addowner(usera["token"], channel_id, userb["u_id"]) # admin removes user A channel_removeowner(admin["token"], channel_id, usera["u_id"]) # there should only be user B left details = channel_details(usera["token"], channel_id) assert_contains_users_id(details["owner_members"], [userb["u_id"]]) assert_contains_users_id(details["all_members"], [userb["u_id"], usera["u_id"]])
def test_leave_channel_successfully(): clear() user_A, user_B = register_n_users(2) public_channel = channels_create( user_A["token"], "public_channel", True ) # Create public channel # user_B join the channel, we have two users in the channel now channel_join(user_B["token"], public_channel["channel_id"]) details = channel_details(user_A["token"], public_channel["channel_id"]) expected_members_id = [user_A["u_id"], user_B["u_id"]] assert_contains_users_id(details["all_members"], expected_members_id) # user_B leave the channel, only user_A left in the channel channel_leave(user_B["token"], public_channel["channel_id"]) details = channel_details(user_A["token"], public_channel["channel_id"]) expected_members_id = [user_A["u_id"]] assert_contains_users_id(details["all_members"], expected_members_id)
def test_join_empty_channel(): """ If a user join a channel with no member, he should automatically becomes the owner """ clear() # user_a create a channel and leave from there, user_b join the # channel with no member. user_a, user_b = register_n_users(2) channel = channels_create(user_a["token"], "public_channel", True) # Create a public channel channel_leave(user_a["token"], channel["channel_id"]) channel_join(user_b["token"], channel["channel_id"]) # Verify that user_b automatically be the owner of that channel details = channel_details(user_b["token"], channel["channel_id"]) expect_owner_in_channel = [user_b["u_id"]] assert_contains_users_id(details["owner_members"], expect_owner_in_channel)
def test_channel_invite_multiple_channels(): clear() usera, userb = register_n_users(2) channela = channels_create(usera["token"], "usera_ch", is_public=False) channelb = channels_create(userb["token"], "userb_ch", is_public=False) channel_invite(usera["token"], channela["channel_id"], userb["u_id"]) detailsa = channel_details(usera["token"], channela["channel_id"]) detailsb = channel_details(userb["token"], channelb["channel_id"]) assert_contains_users_id(detailsa["all_members"], [usera["u_id"], userb["u_id"]]) assert_contains_users_id(detailsa["owner_members"], [usera["u_id"]]) assert_contains_users_id(detailsb["all_members"], [userb["u_id"]]) assert_contains_users_id(detailsb["owner_members"], [userb["u_id"]])
def test_channel_join_multiple_channels(): clear() usera, userb, userc = register_n_users(3) channel_id_a = channels_create(usera["token"], "channela", is_public=True)["channel_id"] channel_id_b = channels_create(userb["token"], "channelb", is_public=True)["channel_id"] channel_id_c = channels_create(userc["token"], "channelc", is_public=True)["channel_id"] channel_join(usera["token"], channel_id_b) channel_join(usera["token"], channel_id_c) channel_join(userb["token"], channel_id_c) # usera should be able to get all the details since the channels are public detailsa = channel_details(usera["token"], channel_id_a) detailsb = channel_details(usera["token"], channel_id_b) detailsc = channel_details(usera["token"], channel_id_c) # there should still be only one owner assert_contains_users_id(detailsa["owner_members"], [usera["u_id"]]) assert_contains_users_id(detailsb["owner_members"], [userb["u_id"]]) assert_contains_users_id(detailsc["owner_members"], [userc["u_id"]]) assert_contains_users_id(detailsa["all_members"], [usera["u_id"]]) assert_contains_users_id(detailsb["all_members"], [usera["u_id"], userb["u_id"]]) assert_contains_users_id(detailsc["all_members"], [usera["u_id"], userb["u_id"], userc["u_id"]])