def test_valid_token_member_channel(channels_fixture): """ Pytest: testing channels_list with member channels """ (server_data, channels_fixture) = channels_fixture #Split up the users: user1 = channels_fixture[0] user2 = channels_fixture[1] #Extract the channel informations from the user channel_list1 = user1["channels"] channel_list2 = user2["channels"] #Now invite user2 into user1's channel channel_invite(server_data, user1["token"], channel_list1[0]["channel_id"], user2["u_id"]) #Now user 2 should contain 2 channels, one owned, one as member rt_info = channels_list(server_data, user2["token"]) channels_user2 = rt_info["channels"] assert does_channel_exist_in_list(channels_user2, channel_list1[0]["channel_id"], channel_list1[0]["name"]) assert does_channel_exist_in_list(channels_user2, channel_list2[0]["channel_id"], channel_list2[0]["name"])
def test_valid_token_owned_channels(channels_http_fixture): """ Pytest: test channels_list with owned channels """ channels_fixture = channels_http_fixture #Split up the users: user1 = channels_fixture[0] user2 = channels_fixture[1] #Extract the channel informations from the user channel_list1 = user1["channels"] channel_list2 = user2["channels"] # List channels for user 1 token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/list?token={token}") payload = json.load(response) channels_user1 = payload["channels"] # Check if it only contains the channels created by user1 # user1 created two channels, COMP1531 and COMP2511, both public assert does_channel_exist_in_list(channels_user1, channel_list1[0]["channel_id"], channel_list1[0]["name"]) assert does_channel_exist_in_list(channels_user1, channel_list1[1]["channel_id"], channel_list1[1]["name"]) # The channel name should match with the channel ID assert not does_channel_exist_in_list(channels_user1, channel_list1[0]["channel_id"], channel_list1[1]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list1[1]["channel_id"], channel_list1[0]["name"]) # List channels for user 2 token = user2["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/list?token={token}") payload = json.load(response) channels_user2 = payload["channels"] # Check if it only contains the channels created by user2 # user2 created one channel, ENG1001 it is private but since user2 is authorized, they should still see it assert does_channel_exist_in_list(channels_user2, channel_list2[0]["channel_id"], channel_list2[0]["name"]) # The channel name should match with the channel ID assert not does_channel_exist_in_list( channels_user2, channel_list2[0]["channel_id"], "something random") assert not does_channel_exist_in_list(channels_user2, 99983, channel_list2[0]["name"])
def test_valid_token_member_channel(channels_http_fixture): """ Pytest: test channels_list with channels that user is a member of """ channels_fixture = channels_http_fixture #Split up the users: user1 = channels_fixture[0] user2 = channels_fixture[1] #Extract the channel informations from the user channel_list1 = user1["channels"] channel_list2 = user2["channels"] #Now invite user2 into user1's channel # List channels for user 1 data = { "token": user1["token"], "channel_id": channel_list1[0]["channel_id"], "u_id": user2["u_id"], } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channel/invite", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) #Now user 2 should contain 2 channels, one owned, one as member token = user2["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/list?token={token}") payload = json.load(response) channels_user2 = payload["channels"] assert does_channel_exist_in_list(channels_user2, channel_list1[0]["channel_id"], channel_list1[0]["name"]) assert does_channel_exist_in_list(channels_user2, channel_list2[0]["channel_id"], channel_list2[0]["name"])
def test_valid_token_not_owned_channels(channels_http_fixture): """ Pytest: test channels_list with not owned channels """ channels_fixture = channels_http_fixture #Split up the users: user1 = channels_fixture[0] user2 = channels_fixture[1] user3 = channels_fixture[2] user4 = channels_fixture[3] user5 = channels_fixture[4] #Extract the channel informations from the user channel_list2 = user2["channels"] channel_list3 = user3["channels"] channel_list4 = user4["channels"] channel_list5 = user5["channels"] # List channels for user 1 token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/list?token={token}") payload = json.load(response) channels_user1 = payload["channels"] # the channels from other users should not exist in this list # Because the user is not authorized assert not does_channel_exist_in_list(channels_user1, channel_list2[0]["channel_id"], channel_list2[0]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list3[0]["channel_id"], channel_list3[0]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list4[0]["channel_id"], channel_list4[0]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list5[0]["channel_id"], channel_list5[0]["name"])
def test_valid_token_not_owned_channels(channels_fixture): """ Pytest: testing channels_list with not owned channels """ (server_data, channels_fixture) = channels_fixture #Split up the users: user1 = channels_fixture[0] user2 = channels_fixture[1] user3 = channels_fixture[2] user4 = channels_fixture[3] user5 = channels_fixture[4] #Extract the channel informations from the user channel_list2 = user2["channels"] channel_list3 = user3["channels"] channel_list4 = user4["channels"] channel_list5 = user5["channels"] # List channels for user 1 rt_info = channels_list(server_data, user1["token"]) channels_user1 = rt_info["channels"] # the channels from other users should not exist in this list # Because the user is not authorized assert not does_channel_exist_in_list(channels_user1, channel_list2[0]["channel_id"], channel_list2[0]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list3[0]["channel_id"], channel_list3[0]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list4[0]["channel_id"], channel_list4[0]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list5[0]["channel_id"], channel_list5[0]["name"])
def test_valid_token_owned_channels(channels_fixture): """ Pytest: testing channels_list wiht owned channels """ (server_data, channels_fixture) = channels_fixture #Split up the users: user1 = channels_fixture[0] user2 = channels_fixture[1] #Extract the channel informations from the user channel_list1 = user1["channels"] channel_list2 = user2["channels"] # List channels for user 1 rt_info = channels_list(server_data, user1["token"]) channels_user1 = rt_info["channels"] # Check if it only contains the channels created by user1 # user1 created two channels, COMP1531 and COMP2511, both public assert does_channel_exist_in_list(channels_user1, channel_list1[0]["channel_id"], channel_list1[0]["name"]) assert does_channel_exist_in_list(channels_user1, channel_list1[1]["channel_id"], channel_list1[1]["name"]) # The channel name should match with the channel ID assert not does_channel_exist_in_list(channels_user1, channel_list1[0]["channel_id"], channel_list1[1]["name"]) assert not does_channel_exist_in_list(channels_user1, channel_list1[1]["channel_id"], channel_list1[0]["name"]) # List channels for user 2 rt_info = channels_list(server_data, user2["token"]) channels_user2 = rt_info["channels"] # Check if it only contains the channels created by user2 # user2 created one channel, ENG1001 it is private but since user2 is authorized, they should still see it assert does_channel_exist_in_list(channels_user2, channel_list2[0]["channel_id"], channel_list2[0]["name"]) # The channel name should match with the channel ID assert not does_channel_exist_in_list( channels_user2, channel_list2[0]["channel_id"], "something random") assert not does_channel_exist_in_list(channels_user2, 99983, channel_list2[0]["name"])
def test_token_with_channels_n_changes(channels_fixture): """ Pytest: testing with channels and after changes """ (server_data, channels_fixture) = channels_fixture # Import the user info user1 = channels_fixture[0] user2 = channels_fixture[1] user3 = channels_fixture[2] user4 = channels_fixture[3] user5 = channels_fixture[4] # Extract the channel info from users channels_list1 = user1["channels"] channels_list2 = user2["channels"] channels_list3 = user3["channels"] channels_list4 = user4["channels"] channels_list5 = user5["channels"] # Making several changes to membership and ownership # Add user5 to COMP1531 # Remove user1 from COMP1531 # add user2 to COMP3221 # remove user4 to COMP3221 channel_addowner(server_data, user1["token"], channels_list1[0]["channel_id"], user5["u_id"]) channel_addowner(server_data, user4["token"], channels_list4[0]["channel_id"], user2["u_id"]) channel_removeowner(server_data, user1["token"], channels_list1[0]["channel_id"], user5["u_id"]) channel_removeowner(server_data, user4["token"], channels_list4[0]["channel_id"], user4["u_id"]) #The list of channels should remain the same rt_val = channels_listall(server_data, user1["token"]) channels_user = rt_val["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"])
def test_token_with_channels(channels_http_fixture): """ Pytest: testing with channels """ # Import the user info user1 = channels_http_fixture[0] user2 = channels_http_fixture[1] user3 = channels_http_fixture[2] user4 = channels_http_fixture[3] user5 = channels_http_fixture[4] # Extract the channel info from users channels_list1 = user1["channels"] channels_list2 = user2["channels"] channels_list3 = user3["channels"] channels_list4 = user4["channels"] channels_list5 = user5["channels"] # Each of the listall should contain the same thing # user1 token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channels_user = payload["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) # user2 token = user2["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channels_user = payload["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) # user3 token = user3["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channels_user = payload["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) #user4 token = user4["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channels_user = payload["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) #user5 token = user4["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channels_user = payload["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"])
def test_token_with_channels_n_changes(channels_http_fixture): """ Pytest: testing with channels and changes """ # Import the user info user1 = channels_http_fixture[0] user2 = channels_http_fixture[1] user3 = channels_http_fixture[2] user4 = channels_http_fixture[3] user5 = channels_http_fixture[4] # Extract the channel info from users channels_list1 = user1["channels"] channels_list2 = user2["channels"] channels_list3 = user3["channels"] channels_list4 = user4["channels"] channels_list5 = user5["channels"] # Making several changes to membership and ownership # Add user5 to COMP1531 # Remove user1 from COMP1531 # add user2 to COMP3221 # remove user4 to COMP3221 data = { "token": user1["token"], "channel_id": channels_list1[0]["channel_id"], "u_id": user5["u_id"], } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channel/addowner", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) data = { "token": user4["token"], "channel_id": channels_list4[0]["channel_id"], "u_id": user2["u_id"], } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channel/addowner", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) data = { "token": user1["token"], "channel_id": channels_list1[0]["channel_id"], "u_id": user1["u_id"], } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channel/removeowner", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) data = { "token": user4["token"], "channel_id": channels_list4[0]["channel_id"], "u_id": user4["u_id"], } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channel/removeowner", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) #The list of channels should remain the same token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channels_user = payload["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"])
def test_token_with_channels(channels_fixture): """ Pytest: testing with valid channels """ (server_data, channels_fixture) = channels_fixture # Import the user info user1 = channels_fixture[0] user2 = channels_fixture[1] user3 = channels_fixture[2] user4 = channels_fixture[3] user5 = channels_fixture[4] # Extract the channel info from users channels_list1 = user1["channels"] channels_list2 = user2["channels"] channels_list3 = user3["channels"] channels_list4 = user4["channels"] channels_list5 = user5["channels"] # Each of the listall should contain the same thing # user1 rt_val = channels_listall(server_data, user1["token"]) channels_user = rt_val["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) # user2 rt_val = channels_listall(server_data, user2["token"]) channels_user = rt_val["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) # user3 rt_val = channels_listall(server_data, user3["token"]) channels_user = rt_val["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) #user4 rt_val = channels_listall(server_data, user4["token"]) channels_user = rt_val["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"]) #user5 rt_val = channels_listall(server_data, user2["token"]) channels_user = rt_val["channels"] assert does_channel_exist_in_list(channels_user, channels_list1[0]["channel_id"], channels_list1[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list1[1]["channel_id"], channels_list1[1]["name"]) assert does_channel_exist_in_list(channels_user, channels_list2[0]["channel_id"], channels_list2[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list3[0]["channel_id"], channels_list3[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list4[0]["channel_id"], channels_list4[0]["name"]) assert does_channel_exist_in_list(channels_user, channels_list5[0]["channel_id"], channels_list5[0]["name"])
def test_valid_channel_creation(auth_fixture): """ Pytest: testing channels_create with valid channel creation """ (server_data, auth_fixture) = auth_fixture # Split up the users user1 = auth_fixture[0] # register the first public channel for user1 # Name: "COMP1000" # Channel ID: unknown, return from function channel_name = "COMP1000" return_val = channels_create(server_data, user1["token"], channel_name, True) channel_id = return_val['channel_id'] # check if the return contains the correct type assert isinstance(channel_id, int) # The channel is successfully created, it should show up in other functions return_val = channels_list(server_data, user1["token"]) # The only channel that should returned is the channel that were created channel_list = return_val["channels"] assert channel_list[0]["channel_id"] == channel_id assert channel_list[0]["name"] == "COMP1000" # Same thing should happen to channels_listall return_val = channels_listall(server_data, user1["token"]) channel_list = return_val["channels"] assert channel_list[0]["channel_id"] == channel_id assert channel_list[0]["name"] == "COMP1000" # register the second channel, first private channel for user1, it should not overwrite the previous channel # Name: "ENG1001" # Channel ID: unknown, return from function channel_name2 = "ENG1001" return_val = channels_create(server_data, user1["token"], channel_name2, False) channel_id2 = return_val['channel_id'] assert isinstance(channel_id2, int) # Now the user should have 2 channels in the list return_val = channels_list(server_data, user1["token"]) channel_list2 = return_val["channels"] # The public channel should still exist assert does_channel_exist_in_list(channel_list2, channel_id, channel_name) assert does_channel_exist_in_list(channel_list2, channel_id2, channel_name2) # The channel ID and channel name should match assert not does_channel_exist_in_list(channel_list2, channel_id2, channel_name) assert not does_channel_exist_in_list(channel_list2, channel_id, channel_name2) # User1 should be the owner of the channel created return_val = channel_details(server_data, user1["token"], channel_id) channel_owner_list = return_val["owner_members"] channel_name3 = return_val["name"] assert channel_name3 == channel_name assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
def test_valid_channel_creation(auth_http_fixture): """ Pytest: testing channels_create with valid channel creation """ auth_fixture = auth_http_fixture # Split up the users user1 = auth_fixture[0] # register the first public channel for user1 # Name: "COMP1000" # Channel ID: unknown, return from function channel_name = "COMP1000" data = { "token": user1["token"], "name": channel_name, "is_public": True, } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channels/create", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) payload = json.load(response) channel_id = payload['channel_id'] # check if the return contains the correct type assert isinstance(channel_id, int) # The channel is successfully created, it should show up in other functions token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/list?token={token}") payload = json.load(response) # The only channel that should returned is the channel that were created channel_list = payload["channels"] assert channel_list[0]["channel_id"] == channel_id assert channel_list[0]["name"] == "COMP1000" # Same thing should happen to channels_listall token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/listall?token={token}") payload = json.load(response) channel_list = payload["channels"] assert channel_list[0]["channel_id"] == channel_id assert channel_list[0]["name"] == "COMP1000" # register the second channel, first private channel for user1, it should not overwrite the previous channel # Name: "ENG1001" # Channel ID: unknown, return from function channel_name2 = "ENG1001" data = { "token": user1["token"], "name": channel_name2, "is_public": False, } json_data = json.dumps(data).encode('utf-8') post_req = urllib.request.Request( f"{BASE_URL}/channels/create", method="POST", data=json_data, headers={"Content-Type": "application/json"}) response = urllib.request.urlopen(post_req) payload = json.load(response) channel_id2 = payload['channel_id'] assert isinstance(channel_id2, int) # Now the user should have 2 channels in the list token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channels/list?token={token}") payload = json.load(response) channel_list2 = payload["channels"] # The public channel should still exist assert does_channel_exist_in_list(channel_list2, channel_id, channel_name) assert does_channel_exist_in_list(channel_list2, channel_id2, channel_name2) # The channel ID and channel name should match assert not does_channel_exist_in_list(channel_list2, channel_id2, channel_name) assert not does_channel_exist_in_list(channel_list2, channel_id, channel_name2) # User1 should be the owner of the channel created token = user1["token"] response = urllib.request.urlopen( f"{BASE_URL}/channel/details?token={token}&channel_id={channel_id}") payload = json.load(response) channel_owner_list = payload["owner_members"] channel_name3 = payload["name"] assert channel_name3 == channel_name assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])