コード例 #1
0
def test_channel_invite_private_channel(channels_fixture):
    """
    pytest: testing channel_invite with private channel
    """

    (server_data, channels_fixture) = channels_fixture

    # Get user4 and user2's details
    user4 = channels_fixture[3]
    user2 = channels_fixture[1]

    # Get user 2's token and private channel ID
    user2_token = channels_fixture[1]["token"]
    user2_channel_info = channels_fixture[1]["channels"][0]

    #invite user4 into user2's channel using user2's token
    channel_invite(server_data, user2_token, user2_channel_info["channel_id"], user4["u_id"])

    # After invitation, user4 should become a member of the channel 2
    rt_info = channel_details(server_data, user2_token, user2_channel_info["channel_id"])
    channel_member_list = rt_info["all_members"]

    assert does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])

    # And user2 should still remain a member
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
コード例 #2
0
def test_channel_invite_public_channel(channels_fixture):
    """
    pytest: testing channel_invite with public channel
    """

    (server_data, channels_fixture) = channels_fixture

    # Getting user 1 and user 2's info
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]

    # Getting user 1's channel info
    user1_channel_info = channels_fixture[0]["channels"][0]

    #invite user 2 into user 1's channel, as user 1
    channel_invite(server_data, user1["token"], user1_channel_info["channel_id"], user2["u_id"])

    # After nvitation, user 2 should become a member of the channel
    rt_info = channel_details(server_data, user1["token"], user1_channel_info["channel_id"])
    channel_member_list = rt_info["all_members"]

    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])

    # User 1 should also still be in the list
    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
コード例 #3
0
def test_channel_with_extra_members(channels_fixture):
    """
    Function to test channel_details with extra members
    """

    (server_data, channels_fixture) = channels_fixture

    #unpack all 5 users
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # Select channel from user3 as the test channel
    channel = user3["channels"][0]

    # Invite all users into the channel
    channel_invite(server_data, user3["token"], channel["channel_id"], user1["u_id"])
    channel_invite(server_data, user3["token"], channel["channel_id"], user2["u_id"])
    channel_invite(server_data, user3["token"], channel["channel_id"], user4["u_id"])
    channel_invite(server_data, user3["token"], channel["channel_id"], user5["u_id"])

    # Now user1-5 should show up in all members, and user 1 as the owner of slackr, is now the owner of the channel

    rt_info = channel_details(server_data, user3["token"], channel["channel_id"])
    channel_name = rt_info["name"]
    channel_member_list = rt_info["all_members"]
    channel_owner_list = rt_info["owner_members"]

    # Check channel name
    assert channel_name == channel["name"]

    # Check member list
    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # Check owner list
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])

    # Other members should not show up in the owner's list
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"], user5["name_first"], user5["name_last"])
コード例 #4
0
def test_channel_invite_public_channel(channels_http_fixture):
    """
    pytest: testing channel_invite with public channel
    """

    channels_fixture = channels_http_fixture

    # Getting user 1 and user 2's info
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]

    # Getting user 1's channel info
    user1_channel_info = channels_fixture[0]["channels"][0]

    #invite user 2 into user 1's channel, as user 1
    data = {
        "token": user1["token"],
        "channel_id": user1_channel_info["channel_id"],
        "u_id": user2["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # After nvitation, user 2 should become a member of the channel
    token = user1["token"]
    channel_id = user1_channel_info["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={token}&channel_id={channel_id}")
    payload = json.load(response)

    channel_member_list = payload["all_members"]

    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])

    # User 1 should also still be in the list
    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
コード例 #5
0
def test_channel_invite_private_channel(channels_http_fixture):
    """
    pytest: testing channel_invite with private channels
    """

    channels_fixture = channels_http_fixture

    # Get user4 and user2's details
    user4 = channels_fixture[3]
    user2 = channels_fixture[1]

    # Get user 2's token and private channel ID
    user2_token = channels_fixture[1]["token"]
    user2_channel_info = channels_fixture[1]["channels"][0]

    data = {
        "token": user2_token,
        "channel_id": user2_channel_info["channel_id"],
        "u_id": user4["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # After invitation, user4 should become a member of the channel 2
    channel_id = user2_channel_info["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={user2_token}&channel_id={channel_id}"
    )
    payload = json.load(response)

    channel_member_list = payload["all_members"]

    assert does_member_exist_in_list(channel_member_list, user4["u_id"],
                                     user4["name_first"], user4["name_last"])

    # And user2 should still remain a member
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
コード例 #6
0
def test_channel_with_only_owners(channels_fixture):
    """
    Function to test channel_details with only owners
    """

    (server_data, channels_fixture) = channels_fixture

    #unpack all 5 users
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # Select channel from user2 as the test channel
    channel = user2["channels"][0]

    # Add all users to the ownership of the channel
    channel_addowner(server_data, user2["token"], channel["channel_id"], user1["u_id"])
    channel_addowner(server_data, user2["token"], channel["channel_id"], user3["u_id"])
    channel_addowner(server_data, user2["token"], channel["channel_id"], user4["u_id"])
    channel_addowner(server_data, user2["token"], channel["channel_id"], user5["u_id"])

    # Now all members should exist in both owner and member
    rt_info = channel_details(server_data, user2["token"], channel["channel_id"])
    channel_member_list = rt_info["all_members"]
    channel_owner_list = rt_info["owner_members"]

    # Checking the member list, all users should be in members
    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # Checking the owner list, all users should be in owners
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user5["u_id"], user5["name_first"], user5["name_last"])
コード例 #7
0
def test_channel_with_only_owner(channels_fixture):
    """
    Function to test channel_details with only owners
    """

    (server_data, channels_fixture) = channels_fixture

    # unpack the fixtures into 5 separate users
    user = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # using user1 for channel details
    token = user["token"]
    channel_info = channels_fixture[0]["channels"][0]
    channel_id = channel_info["channel_id"]

    # obtain the channel detail from the functions
    rt_value = channel_details(server_data, token, channel_id)
    channel_name = rt_value["name"]
    channel_owner_list = rt_value["owner_members"]
    channel_member_list = rt_value["all_members"]

    # user1 should be both in owner's list and the member's list
    assert channel_name == channel_info["name"]
    assert does_member_exist_in_list(channel_owner_list, user["u_id"], user["name_first"], user["name_last"])
    assert does_member_exist_in_list(channel_member_list, user["u_id"], user["name_first"], user["name_last"])

    # No other users should show up
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"], user5["name_first"], user5["name_last"])

    assert not does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])
コード例 #8
0
def test_channel_invite_multi_users(channels_fixture):
    """
    pytest: testing channel_invite with multi users
    """

    (server_data, channels_fixture) = channels_fixture

    # Getting all 5 user's info
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # Retrieve the target channel: user3's channel
    user3_channel_info = user3["channels"][0]

    # Invite all users into the channel
    channel_invite(server_data, user3["token"], user3_channel_info["channel_id"], user1["u_id"])
    channel_invite(server_data, user3["token"], user3_channel_info["channel_id"], user2["u_id"])
    channel_invite(server_data, user3["token"], user3_channel_info["channel_id"], user4["u_id"])
    channel_invite(server_data, user3["token"], user3_channel_info["channel_id"], user5["u_id"])

    # After invitation, all 5 members should be a member of the channel
    # User1 should be the owner of the channel, as he is the super user
    rt_info = channel_details(server_data, user3["token"], user3_channel_info["channel_id"])
    channel_member_list = rt_info["all_members"]
    channel_owner_list = rt_info["owner_members"]

    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])

    assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])
コード例 #9
0
def test_channel_with_only_owner(channels_http_fixture):
    """
    Pytest: testing the function with only owner
    """

    channels_fixture = channels_http_fixture

    # unpack the fixtures into 5 separate users
    user = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # using user1 for channel details
    token = user["token"]
    channel_info = channels_fixture[0]["channels"][0]
    channel_id = channel_info["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={token}&channel_id={channel_id}")

    # obtain the channel detail from the functions
    payload = json.load(response)

    channel_name = payload["name"]
    channel_owner_list = payload["owner_members"]
    channel_member_list = payload["all_members"]

    # user1 should be both in owner's list and the member's list
    assert channel_name == channel_info["name"]
    assert does_member_exist_in_list(channel_owner_list, user["u_id"],
                                     user["name_first"], user["name_last"])
    assert does_member_exist_in_list(channel_member_list, user["u_id"],
                                     user["name_first"], user["name_last"])

    # No other users should show up
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"],
                                         user2["name_first"],
                                         user2["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                         user3["name_first"],
                                         user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])

    assert not does_member_exist_in_list(channel_member_list, user2["u_id"],
                                         user2["name_first"],
                                         user2["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user3["u_id"],
                                         user3["name_first"],
                                         user3["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])
コード例 #10
0
def test_channel_details_nested_call(channels_http_fixture):
    """
    Pytest: testing the function with nested call
    The intention of this function is to test if a member can call details after it was invited/joined/added owner to the channel
    """

    channels_fixture = channels_http_fixture

    # unpack all 5 users
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # select channel from user1 as the test channel
    channel = user1["channels"][0]

    # user2 will join the channel as member:
    data = {
        "token": user2["token"],
        "channel_id": channel["channel_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/join",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # Now all members should exist in both owner and member
    user2_token = user2["token"]
    channel_id = channel["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={user2_token}&channel_id={channel_id}"
    )

    # obtain the channel detail from the functions
    payload = json.load(response)

    # check that user 2 is now a member, not an owner and user 3-5 is not a member with user2's token
    channel_member_list = payload["all_members"]
    channel_owner_list = payload["owner_members"]

    # Checking Owner's list, only 1 owner - user1
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"],
                                         user2["name_first"],
                                         user2["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                         user3["name_first"],
                                         user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])

    # Checking Member List , 2 members - user1 and user2
    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user3["u_id"],
                                         user3["name_first"],
                                         user3["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])

    # Now user3 will join as an owner
    data = {
        "token": user1["token"],
        "channel_id": channel["channel_id"],
        "u_id": user3["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/addowner",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # Check that user 3 is now a owner, 4-5 is not a member with user3's token
    token = user3["token"]
    channel_id = channel["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={token}&channel_id={channel_id}")

    # obtain the channel detail from the functions
    payload = json.load(response)

    channel_member_list = payload["all_members"]
    channel_owner_list = payload["owner_members"]

    # Checking Owner list, should contain user1 and user3
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"],
                                         user2["name_first"],
                                         user2["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])

    # checking Member List, should contain user 1-3
    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])

    # Now user3 will invite user4 in
    data = {
        "token": user3["token"],
        "channel_id": channel["channel_id"],
        "u_id": user4["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # Check that user 4 is now a member, 5 is not a member with user3's token
    token = user4["token"]
    channel_id = channel["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={token}&channel_id={channel_id}")

    # obtain the channel detail from the functions
    payload = json.load(response)

    channel_member_list = payload["all_members"]
    channel_owner_list = payload["owner_members"]

    # checking Owner list, should still have only user 1 and 3
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"],
                                         user2["name_first"],
                                         user2["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])

    # checking Member List, should have user1-4
    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"],
                                     user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])
コード例 #11
0
def test_channel_with_only_owners(channels_http_fixture):
    """
    Pytest: testing the function with only owners
    """

    channels_fixture = channels_http_fixture

    #unpack all 5 users
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # Select channel from user2 as the test channel
    channel = user2["channels"][0]

    # Add all users to the ownership of the channel
    data = {
        "token": user2["token"],
        "channel_id": channel["channel_id"],
        "u_id": user1["u_id"]
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/addowner",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user2["token"],
        "channel_id": channel["channel_id"],
        "u_id": user3["u_id"]
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/addowner",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user2["token"],
        "channel_id": channel["channel_id"],
        "u_id": user4["u_id"]
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/addowner",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user2["token"],
        "channel_id": channel["channel_id"],
        "u_id": user5["u_id"]
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/addowner",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # Now all members should exist in both owner and member
    user3_token = user3["token"]
    channel_id = channel["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={user3_token}&channel_id={channel_id}"
    )

    # obtain the channel detail from the functions
    payload = json.load(response)
    channel_member_list = payload["all_members"]
    channel_owner_list = payload["owner_members"]

    # Checking the member list, all users should be in members
    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"],
                                     user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_member_list, user5["u_id"],
                                     user5["name_first"], user5["name_last"])

    # Checking the owner list, all users should be in owners
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user4["u_id"],
                                     user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user5["u_id"],
                                     user5["name_first"], user5["name_last"])
コード例 #12
0
def test_channel_with_extra_members(channels_http_fixture):
    """
    Pytest: testing the function with extra members
    """

    channels_fixture = channels_http_fixture

    #unpack all 5 users
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # Select channel from user3 as the test channel
    channel = user3["channels"][0]

    # Invite all users into the channel
    data = {
        "token": user3["token"],
        "channel_id": channel["channel_id"],
        "u_id": user1["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user3["token"],
        "channel_id": channel["channel_id"],
        "u_id": user2["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user3["token"],
        "channel_id": channel["channel_id"],
        "u_id": user4["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user3["token"],
        "channel_id": channel["channel_id"],
        "u_id": user5["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # Now user1-5 should show up in all members, and user 1 as the owner of slackr, is now the owner of the channel
    user3_token = user3["token"]
    channel_id = channel["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={user3_token}&channel_id={channel_id}"
    )

    # obtain the channel detail from the functions
    payload = json.load(response)

    channel_name = payload["name"]
    channel_member_list = payload["all_members"]
    channel_owner_list = payload["owner_members"]

    # Check channel name
    assert channel_name == channel["name"]

    # Check member list
    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"],
                                     user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_member_list, user5["u_id"],
                                     user5["name_first"], user5["name_last"])

    # Check owner list
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])

    # Other members should not show up in the owner's list
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"],
                                         user2["name_first"],
                                         user2["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"],
                                         user4["name_first"],
                                         user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"],
                                         user5["name_first"],
                                         user5["name_last"])
コード例 #13
0
def test_channel_invite_multi_users(channels_http_fixture):
    """
    pytest: testing channel_invite with multi users
    """

    channels_fixture = channels_http_fixture

    # Getting all 5 user's info
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # Retrieve the target channel: user3's channel
    user3_channel_info = user3["channels"][0]

    # Invite all users into the channel
    data = {
        "token": user3["token"],
        "channel_id": user3_channel_info["channel_id"],
        "u_id": user1["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user3["token"],
        "channel_id": user3_channel_info["channel_id"],
        "u_id": user2["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user3["token"],
        "channel_id": user3_channel_info["channel_id"],
        "u_id": user4["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    data = {
        "token": user3["token"],
        "channel_id": user3_channel_info["channel_id"],
        "u_id": user5["u_id"],
    }
    json_data = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(f"{BASE_URL}/channel/invite",
                                 method="POST",
                                 data=json_data,
                                 headers={"Content-Type": "application/json"})
    response = urllib.request.urlopen(req)

    # After invitation, all 5 members should be a member of the channel
    # User1 should be the owner of the channel, as he is the super user
    token = user3["token"]
    channel_id = user3_channel_info["channel_id"]
    response = urllib.request.urlopen(
        f"{BASE_URL}/channel/details?token={token}&channel_id={channel_id}")
    payload = json.load(response)

    channel_member_list = payload["all_members"]
    channel_owner_list = payload["owner_members"]

    assert does_member_exist_in_list(channel_member_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"],
                                     user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"],
                                     user4["name_first"], user4["name_last"])
    assert does_member_exist_in_list(channel_member_list, user5["u_id"],
                                     user5["name_first"], user5["name_last"])

    assert does_member_exist_in_list(channel_owner_list, user1["u_id"],
                                     user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"],
                                     user3["name_first"], user3["name_last"])
コード例 #14
0
def test_channel_details_nested_call(channels_fixture):
    """
    Function to test channel_details with nested call
    """

    (server_data, channels_fixture) = channels_fixture

    # unpack all 5 users
    user1 = channels_fixture[0]
    user2 = channels_fixture[1]
    user3 = channels_fixture[2]
    user4 = channels_fixture[3]
    user5 = channels_fixture[4]

    # select channel from user1 as the test channel
    channel = user1["channels"][0]

    # user2 will join the channel as member:
    channel_join(server_data, user2["token"], channel["channel_id"])

    # check that user 2 is now a member, not an owner and user 3-5 is not a member with user2's token
    rt_info = channel_details(server_data, user2["token"], channel["channel_id"])
    channel_member_list = rt_info["all_members"]
    channel_owner_list = rt_info["owner_members"]

    # Checking Owner's list, only 1 owner - user1
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # Checking Member List , 2 members - user1 and user2
    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # Now user3 will join as an owner
    channel_addowner(server_data, user1["token"], channel["channel_id"], user3["u_id"])

    # Check that user 3 is now a owner, 4-5 is not a member with user3's token
    rt_info = channel_details(server_data, user3["token"], channel["channel_id"])
    channel_member_list = rt_info["all_members"]
    channel_owner_list = rt_info["owner_members"]

    # Checking Owner list, should contain user1 and user3
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # checking Member List, should contain user 1-3
    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # Now user3 will invite user4 in
    channel_invite(server_data, user3["token"], channel["channel_id"], user4["u_id"])

    # Check that user 4 is now a member, 5 is not a member with user3's token
    rt_info = channel_details(server_data, user4["token"], channel["channel_id"])
    channel_member_list = rt_info["all_members"]
    channel_owner_list = rt_info["owner_members"]

    # checking Owner list, should still have only user 1 and 3
    assert does_member_exist_in_list(channel_owner_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_owner_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_owner_list, user5["u_id"], user5["name_first"], user5["name_last"])

    # checking Member List, should have user1-4
    assert does_member_exist_in_list(channel_member_list, user1["u_id"], user1["name_first"], user1["name_last"])
    assert does_member_exist_in_list(channel_member_list, user2["u_id"], user2["name_first"], user2["name_last"])
    assert does_member_exist_in_list(channel_member_list, user3["u_id"], user3["name_first"], user3["name_last"])
    assert does_member_exist_in_list(channel_member_list, user4["u_id"], user4["name_first"], user4["name_last"])
    assert not does_member_exist_in_list(channel_member_list, user5["u_id"], user5["name_first"], user5["name_last"])
コード例 #15
0
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"])
コード例 #16
0
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"])