def test_details_highPermission_succ():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    Pub_channel = CF.channels_create(A['token'], 'NextChannel', 'True')
    token = A['token']
    channelID = Pub_channel['channel_id']

    CF.channel_details(token, channelID)
def test_invalid_channelID():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    Pub_channel = CF.channels_create(A['token'], 'NextChannel', 'True')
    token = A['token']
    channelID = Pub_channel['channel_id'] + 45645

    with pytest.raises(CHF.ValueError):
        CF.channel_details(token, channelID)
def test_validationOFtoken():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    Pub_channel = CF.channels_create(A['token'], 'NextChannel', 'True')
    token = A['token'] + '45645'
    channelID = Pub_channel['channel_id']

    with pytest.raises(TF.AccessError):
        CF.channel_details(token, channelID)
def test_not_loggedIn():
    reset_data()
    A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee")
    Pub_channel = CF.channels_create(A['token'], 'NextChannel', 'True')
    token = A['token']
    auth_logout(token)
    channelID = Pub_channel['channel_id']

    with pytest.raises(CF.AccessError):
        CF.channel_details(token, channelID)
Beispiel #5
0
def channel_details():
    """ Provides basic details about a channel """

    token = request.args.get("token")
    channel_id = to_int(request.args.get("channel_id"))

    return dumps(channel.channel_details(token, channel_id))
Beispiel #6
0
def test_channel_details():
    '''
    Function tests for channel_details
    '''
    #Initialisation
    global_var.initialise_all()

    user1 = auth_register("*****@*****.**", \
    "valid_correct_password", "valid_correct_first_name", \
    "valid_correct_last_name")
    token1 = user1["token"]
    userdict1 = {
        "u_id":
        0,
        "name_first":
        "valid_correct_first_name",
        "name_last":
        "valid_correct_last_name",
        "profile_img_url":
        'http://*****:*****@test.com", \
    "valid_correct_password", "valid_correct_first_name", \
    "valid_correct_last_name")
    token2 = user2["token"]
    userdict2 = {
        "u_id":
        1,
        "name_first":
        "valid_correct_first_name",
        "name_last":
        "valid_correct_last_name",
        "profile_img_url":
        'http://localhost:5001/imgurl/server/assets/images/default.jpg'
    }

    #token1 creates a channel and is automatically part of it as the owner
    channel = func.channels_create(token1, "TestChannel", True)
    channel_id = channel["channel_id"]
    # Initialisation finished

    #if user is not a member of the channel, has not joined yet
    with pytest.raises(AccessError, match=\
    "Authorised user is not a member of the channel"):
        func.channel_details(token2, channel_id)

    assert func.channel_details(token1, channel_id) == {
        "name": "TestChannel",
        "owner_members": [userdict1],
        "all_members": [userdict1]
    }

    # If a user changes names, this is reflected in channel_details
    user_profile_setname(token1, "another", "name")
    userdict1["name_first"] = "another"
    userdict1["name_last"] = "name"

    assert func.channel_details(token1, channel_id) == {
        "name": "TestChannel",
        "owner_members": [userdict1],
        "all_members": [userdict1]
    }

    #if given an invalid channel_id
    with pytest.raises(ValueError, match="Channel does not exist"):
        func.channel_details(token1, 100)

    # The function is called using a invalid token
    with pytest.raises(AccessError, match="Invalid token"):
        func.channel_details("12345", channel_id)

    # A second user joins the channel
    func.channel_join(token2, channel_id)

    assert func.channel_details(token1, channel_id) == {
        "name": "TestChannel",
        "owner_members": [userdict1],
        "all_members": [userdict1, userdict2]
    }