def test_invite_global_owner(create_input):
    """ Tests that when a global owner is invited to a channel, they will have
        owner permissions in that channel.
    """

    channel_1 = create_input[1][1]

    assert channel_invite_v2(create_input[0][1]['token'],
                             channel_1['channel_id'],
                             create_input[0][0]['auth_user_id']) == {}
    assert channel_invite_v2(create_input[0][1]['token'],
                             channel_1['channel_id'],
                             create_input[0][2]['auth_user_id']) == {}

    # create_input[0][0] is a global owner, so when invited, they should join
    # as a member but have owner permissions
    # create_input[0][2] is a member
    assert len(
        channel_details_v2(create_input[0][1]['token'],
                           channel_1['channel_id'])['owner_members']) == 1
    assert len(
        channel_details_v2(create_input[0][1]['token'],
                           channel_1['channel_id'])['all_members']) == 3

    # create_input[0][0] should be able to promote create_input[0][2] to a
    # channel owner
    assert channel_addowner_v1(create_input[0][0]['token'],
                               channel_1['channel_id'],
                               create_input[0][2]['auth_user_id']) == {}
Exemplo n.º 2
0
def test_non_existent_channel_id(reg_user,
                                 crt_channel):  # Give invalid channel id
    clear_v2()
    user_token = reg_user(0)['token']
    channel_id = crt_channel(user_token, True)['channel_id']
    with pytest.raises(InputError):
        channel_details_v2(user_token, channel_id + 1)
def test_success_owner_leave(create_input):
    # Add another owner to First Channel
    assert channel_addowner_v1(create_input[0][0]["token"], create_input[1][0]["channel_id"], create_input[0][4]["auth_user_id"]) == {}

    # length of *_members for First Channel before leave
    assert len(channel_details_v2(create_input[0][0]["token"], create_input[1][0]["channel_id"])["owner_members"]) == 2
    assert len(channel_details_v2(create_input[0][0]["token"], create_input[1][0]["channel_id"])["all_members"]) == 4

    # One owner leaves
    assert channel_leave_v1(create_input[0][0]["token"], create_input[1][0]["channel_id"]) == {}

    # length of *_members for First Channel after leave; testing for all involved users
    assert len(channel_details_v2(create_input[0][1]["token"], create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(channel_details_v2(create_input[0][1]["token"], create_input[1][0]["channel_id"])["all_members"]) == 3
    assert len(channel_details_v2(create_input[0][2]["token"], create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(channel_details_v2(create_input[0][2]["token"], create_input[1][0]["channel_id"])["all_members"]) == 3
    assert len(channel_details_v2(create_input[0][4]["token"], create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(channel_details_v2(create_input[0][4]["token"], create_input[1][0]["channel_id"])["all_members"]) == 3
    with pytest.raises(AccessError):
        channel_details_v2(create_input[0][0]["token"], create_input[1][0]["channel_id"])

    # number of channels each user is a part of
    assert len(channels_list_v2(create_input[0][0]["token"])["channels"]) == 0
    assert len(channels_list_v2(create_input[0][1]["token"])["channels"]) == 2
    assert len(channels_list_v2(create_input[0][2]["token"])["channels"]) == 2
    assert len(channels_list_v2(create_input[0][4]["token"])["channels"]) == 1
def test_fail_not_member(create_input):
    # length of *_members for First Channel before leave
    assert len(channel_details_v2(create_input[0][0]["token"], create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(channel_details_v2(create_input[0][0]["token"], create_input[1][0]["channel_id"])["all_members"]) == 3

    with pytest.raises(AccessError):
        channel_leave_v1(create_input[0][4]["token"], create_input[1][0]["channel_id"])
Exemplo n.º 5
0
def test_non_member_user(
        reg_user, crt_channel
):  # Give user id that is not in the channel's list of members
    clear_v2()
    user_token = reg_user(0)['token']
    channel_id = crt_channel(user_token, True)['channel_id']
    non_member_token = reg_user(1)['token']
    with pytest.raises(AccessError):  # Test non-member user
        channel_details_v2(non_member_token, channel_id)
Exemplo n.º 6
0
def test_success_remove_multiple(create_input):
    # Add extra owner to First Channel
    assert channel_addowner_v1(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               create_input[0][2]["auth_user_id"]) == {}

    # length of *_members for First Channel before remove
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 3
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 4

    assert channel_removeowner_v1(create_input[0][0]["token"],
                                  create_input[1][0]["channel_id"],
                                  create_input[0][1]["auth_user_id"]) == {}
    assert channel_removeowner_v1(create_input[0][0]["token"],
                                  create_input[1][0]["channel_id"],
                                  create_input[0][2]["auth_user_id"]) == {}

    # length of *_members for First Channel after remove; testing for all users
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 4
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 4
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 4
    assert len(
        channel_details_v2(
            create_input[0][4]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][4]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 4
def test_successful_invites(create_input):
    """ Tests for multiple successful invites to a channel
    """

    # Create a set of users not in the channel yet
    user_1, user_2, user_3, user_4, user_5 = create_input[0]

    channel_1, channel_2, channel_3 = create_input[1]

    # Test for successful calls and that users have been immediately added into
    # their channels

    # Invite user2, user3, user4, user5 to channel 1
    assert channel_invite_v2(user_1['token'], channel_1['channel_id'],
                             user_2['auth_user_id']) == {}
    assert channel_invite_v2(user_1['token'], channel_1['channel_id'],
                             user_3['auth_user_id']) == {}
    assert channel_invite_v2(user_1['token'], channel_1['channel_id'],
                             user_4['auth_user_id']) == {}
    assert channel_invite_v2(user_1['token'], channel_1['channel_id'],
                             user_5['auth_user_id']) == {}

    # Invite user4, user5 to channel 2
    assert channel_invite_v2(user_2['token'], channel_2['channel_id'],
                             user_4['auth_user_id']) == {}
    assert channel_invite_v2(user_2['token'], channel_2['channel_id'],
                             user_5['auth_user_id']) == {}

    # Invite user1 to channel 3
    assert channel_invite_v2(user_3['token'], channel_3['channel_id'],
                             user_1['auth_user_id']) == {}

    # Check that users have been added to channels
    channel_detail_1 = channel_details_v2(user_1['token'],
                                          channel_1['channel_id'])
    channel_detail_2 = channel_details_v2(user_2['token'],
                                          channel_2['channel_id'])
    channel_detail_3 = channel_details_v2(user_3['token'],
                                          channel_3['channel_id'])

    # Check channel 1
    assert channel_detail_1['all_members'][0]['u_id'] == user_1['auth_user_id']
    assert channel_detail_1['all_members'][1]['u_id'] == user_2['auth_user_id']
    assert channel_detail_1['all_members'][2]['u_id'] == user_3['auth_user_id']
    assert channel_detail_1['all_members'][3]['u_id'] == user_4['auth_user_id']
    assert channel_detail_1['all_members'][4]['u_id'] == user_5['auth_user_id']

    # Check channel 2
    assert channel_detail_2['all_members'][0]['u_id'] == user_2['auth_user_id']
    assert channel_detail_2['all_members'][1]['u_id'] == user_4['auth_user_id']
    assert channel_detail_2['all_members'][2]['u_id'] == user_5['auth_user_id']

    # Check channel 3
    assert channel_detail_3['all_members'][0]['u_id'] == user_3['auth_user_id']
    assert channel_detail_3['all_members'][1]['u_id'] == user_1['auth_user_id']
Exemplo n.º 8
0
def us_setup(scrambler, channel_id):
    """
    Makes sure that the scrambler is a member of channel with channel_id
    """

    # if channel details doesnt raise an error, scrambler is in that channel
    # if it does, it will join the channel
    try:
        channel_details_v2(scrambler["token"], channel_id)
    except:
        channel_join_v2(scrambler["token"], channel_id)

    # if the scrambler already has a game in this channel, remove it
    us_remove_instance(scrambler, channel_id)
Exemplo n.º 9
0
def test_fail_user_not_owner(create_input):
    # length of *_members for First Channel
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 3

    with pytest.raises(InputError):
        channel_removeowner_v1(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               create_input[0][4]["auth_user_id"])
def test_fail_token_not_owner(create_input):
    # length of *_members for Second Channel before add
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][1]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][1]["channel_id"])["all_members"]) == 1

    with pytest.raises(AccessError):
        channel_addowner_v1(create_input[0][2]["token"],
                            create_input[1][1]["channel_id"],
                            create_input[0][3]["auth_user_id"])
Exemplo n.º 11
0
def test_channel_invite_v2_multiple_private(user_setup, channel_setup):
    assert channel_invite_v2(make_token(1), 3, 2) == {}
    assert channel_details_v2(make_token(1), 3) == {
        'name': 'PrivateChannel1',
        'is_public': False,
        'owner_members': [
            {
                'u_id': 1,
                'email': "*****@*****.**",
                'name_first': "Peter",
                'name_last': "Tran",
                'handle': "petertran"
            },
        ],
        'all_members': [
            {
                'u_id': 1,
                'email': "*****@*****.**",
                'name_first': "Peter",
                'name_last': "Tran",
                'handle': "petertran"
            },
            {
                'u_id': 2,
                'email': "*****@*****.**",
                'name_first': "Christopher",
                'name_last': "Luong",
                'handle': "christopherluong"
            }
        ]
    }
Exemplo n.º 12
0
def test_channel_join_v2(user_setup, channel_setup):

    channel_join_v2(make_token(2), 0)
    assert channel_details_v2(make_token(2), 0) == {
        'name': 'PublicChannel1',
        'is_public': True,
        'owner_members': [
            {
                'u_id': 1,
                'email': "*****@*****.**",
                'name_first': "Peter",
                'name_last': "Tran",
                'handle': "petertran"
            },
        ],
        'all_members': [
            {
                'u_id': 1,
                'email': "*****@*****.**",
                'name_first': "Peter",
                'name_last': "Tran",
                'handle': "petertran"
            },
            {
                'u_id': 2,
                'email': "*****@*****.**",
                'name_first': "Christopher",
                'name_last': "Luong",
                'handle': "christopherluong"
            }
        ]
    }
def test_success_private_channel(create_input):
    """ Tests that users can be invited into private channels too.
    """

    channel_private = create_input[1][2]

    assert channel_invite_v2(create_input[0][2]['token'],
                             channel_private['channel_id'],
                             create_input[0][0]['auth_user_id']) == {}

    assert len(
        channel_details_v2(
            create_input[0][2]['token'],
            channel_private['channel_id'])['owner_members']) == 1
    assert len(
        channel_details_v2(create_input[0][2]['token'],
                           channel_private['channel_id'])['all_members']) == 2
Exemplo n.º 14
0
def test_invalid_auth_id_exception():
    """ Tests when the authorised user is an invalid id
    """
    clear_v1()

    user = auth_register_v2("*****@*****.**", "mangofruit1", 
                            "Adam", "Apple")
    channel = channels_create_v2(user['token'], "Valid channel", True)

    with pytest.raises(AccessError):
        channel_details_v2(user['token'] + 'bug', channel['channel_id'])
        channel_details_v2(user['token'] + 'ttopk', channel['channel_id'])
        channel_details_v2(user['token'] + '12312', channel['channel_id'])
        channel_details_v2(user['token'] + '1', channel['channel_id'])
        channel_details_v2(user['token'] + 't324', channel['channel_id'])

    clear_v1()
def test_self_invite(create_input):
    """ Test for user trying to invite themselves. The function should call
        successfully and not add the user again to the channel.
    """

    user_1, user_2, user_3, user_4, user_5 = create_input[0]

    channel_1, channel_2, channel_3 = create_input[1]

    # Owner inviting themselves
    assert channel_invite_v2(user_1['token'], channel_1['channel_id'],
                             user_1['auth_user_id']) == {}
    channel_1_details = channel_details_v2(user_1['token'],
                                           channel_1['channel_id'])
    assert len(channel_1_details['all_members']) == 1

    assert channel_invite_v2(user_2['token'], channel_2['channel_id'],
                             user_2['auth_user_id']) == {}
    channel_2_details = channel_details_v2(user_2['token'],
                                           channel_2['channel_id'])
    assert len(channel_2_details['all_members']) == 1

    assert channel_invite_v2(user_3['token'], channel_3['channel_id'],
                             user_3['auth_user_id']) == {}
    channel_3_details = channel_details_v2(user_3['token'],
                                           channel_3['channel_id'])
    assert len(channel_3_details['all_members']) == 1

    # User 4 inviting themselves after being invited by user 1
    assert channel_invite_v2(user_1['token'], channel_1['channel_id'],
                             user_4['auth_user_id']) == {}
    assert channel_invite_v2(user_4['token'], channel_1['channel_id'],
                             user_4['auth_user_id']) == {}
    channel_1_details = channel_details_v2(user_1['token'],
                                           channel_1['channel_id'])
    assert len(channel_1_details['all_members']) == 2

    # User 5 inviting themselves after being invited by user 4
    assert channel_invite_v2(user_4['token'], channel_1['channel_id'],
                             user_5['auth_user_id']) == {}
    assert channel_invite_v2(user_5['token'], channel_1['channel_id'],
                             user_5['auth_user_id']) == {}
    channel_1_details = channel_details_v2(user_1['token'],
                                           channel_1['channel_id'])
    assert len(channel_1_details['all_members']) == 3
Exemplo n.º 16
0
def test_fail_no_permission(create_input):
    # length of *_members for Third Channel before remove
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["owner_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["all_members"]) == 2

    assert channel_join_v2(create_input[0][4]["token"],
                           create_input[1][2]["channel_id"]) == {}

    with pytest.raises(AccessError):
        channel_removeowner_v1(create_input[0][4]["token"],
                               create_input[1][2]["channel_id"],
                               create_input[0][2]["auth_user_id"])
def test_leaved_user_is_not_a_member(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token'] #use v2 because we want tokens as well 
    user_register2 = reg_user(1)
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']

    channel_join_v2(user_register2['token'], channel_id)
    channel_details = channel_details_v2(token_1, channel_id)
    check_joined = False
    for members in channel_details['all_members']:
        if user_register2['auth_user_id'] == members['u_id']: # Verify that joined user is apart of the channel
            check_joined = True
    assert check_joined == True
    channel_leave_v1(user_register2['token'], channel_id)
    channel_details = channel_details_v2(token_1, channel_id) #this was the issue its in the wrong order
    for members in channel_details['all_members']:
        assert user_register2['auth_user_id'] != members['u_id']
def test_invite(test_data):
    a_data, b_data, c_data, a_ch_id, b_ch_id = test_data

    # public channel
    assert channel_invite_v2(a_data["token"], a_ch_id,
                             c_data["auth_user_id"]) == {}

    # a member of a channel should be able to get its details
    # they should also be within all_members of channel_details return
    details = channel_details_v2(c_data["token"], a_ch_id)

    is_member_exist = False
    for member in details["all_members"]:
        if member["u_id"] == c_data["auth_user_id"]:
            is_member_exist = True

    assert is_member_exist == True

    # private channel
    assert channel_invite_v2(b_data["token"], b_ch_id,
                             c_data["auth_user_id"]) == {}

    details = channel_details_v2(c_data["token"], b_ch_id)

    is_member_exist = False
    for member in details["all_members"]:
        if member["u_id"] == c_data["auth_user_id"]:
            is_member_exist = True

    assert is_member_exist == True

    # inviting an existing user (no change)
    assert channel_invite_v2(b_data["token"], b_ch_id,
                             c_data["auth_user_id"]) == {}

    details = channel_details_v2(c_data["token"], b_ch_id)

    is_member_exist = False
    for member in details["all_members"]:
        if member["u_id"] == c_data["auth_user_id"]:
            is_member_exist = True

    assert is_member_exist == True
def test_fail_private_channel(create_input):
    # length of *_members for Third Channel before join
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["all_members"]) == 1

    # AccessError becuase these users are not global owners
    with pytest.raises(AccessError):
        channel_join_v2(create_input[0][1]["token"],
                        create_input[1][2]["channel_id"])
        channel_join_v2(create_input[0][3]["token"],
                        create_input[1][2]["channel_id"])
        channel_join_v2(create_input[0][4]["token"],
                        create_input[1][2]["channel_id"])
def test_success_user_is_member(create_input):
    # Add member to First Channel before making them owner
    assert channel_join_v2(create_input[0][1]["token"],
                           create_input[1][0]["channel_id"]) == {}
    assert channel_join_v2(create_input[0][2]["token"],
                           create_input[1][0]["channel_id"]) == {}

    # length of *_members for First Channel before add
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 3

    assert channel_addowner_v1(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               create_input[0][1]["auth_user_id"]) == {}

    # length of *_members for First Channel after add; testing for all users
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 3
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 3
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 3

    # number of channels each user is a part of
    assert len(channels_list_v2(create_input[0][0]["token"])["channels"]) == 1
    assert len(channels_list_v2(create_input[0][1]["token"])["channels"]) == 2
    assert len(channels_list_v2(create_input[0][2]["token"])["channels"]) == 2
    assert len(channels_list_v2(create_input[0][3]["token"])["channels"]) == 1
    assert len(channels_list_v2(create_input[0][4]["token"])["channels"]) == 0
Exemplo n.º 21
0
def test_unauthorised_user_exception():
    """ Tests for AccessError when Authorised user is not a member of channel
        with channel_id.
    """
    clear_v1()

    user_1, user_2, user_3, user_4, user_5 = create_valid_user_data()
    channel_1 = channels_create_v2(user_1['token'], "Gang gang", True)
    channel_2 = channels_create_v2(user_2['token'], "Beep boop", True)

    channel_join_v2(user_3['token'], channel_1['channel_id'])

    with pytest.raises(AccessError):
        channel_details_v2(user_3['token'], channel_2['channel_id'])
        channel_details_v2(user_1['token'], channel_2['channel_id'])
        channel_details_v2(user_4['token'], channel_1['channel_id'])
        channel_details_v2(user_5['token'], channel_2['channel_id'])
        channel_details_v2(user_2['token'], channel_1['channel_id'])

    clear_v1()
Exemplo n.º 22
0
def test_invalid_channel_id_exception():
    """ Tests for InputError when Channel ID is passed in as an invalid channel.
    """
    clear_v1()

    user_1, user_2, user_3, user_4, user_5 = create_valid_user_data()
    
    channel = channels_create_v2(user_1['token'], "Silent Fox", True)
    channel_join_v2(user_2['token'], channel['channel_id'])
    channel_join_v2(user_3['token'], channel['channel_id'])
    channel_join_v2(user_4['token'], channel['channel_id'])
    channel_join_v2(user_5['token'], channel['channel_id'])

    with pytest.raises(InputError):
        channel_details_v2(user_1['token'], channel['channel_id'] + 1)
        channel_details_v2(user_2['token'], channel['channel_id'] + 5)
        channel_details_v2(user_3['token'], channel['channel_id'] + 5000)
        channel_details_v2(user_4['token'], channel['channel_id'] - 500)
        channel_details_v2(user_5['token'], channel['channel_id'] + 2)

    clear_v1()
def test_success_one_join(create_input):
    # length of *_members for First Channel before join
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 1

    assert channel_join_v2(create_input[0][1]["token"],
                           create_input[1][0]["channel_id"]) == {}

    # length of *_members for First Channel after join; testing for both users
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][0]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][1]["token"],
            create_input[1][0]["channel_id"])["all_members"]) == 2

    # number of channels each user is a part of
    assert len(channels_list_v2(create_input[0][0]["token"])["channels"]) == 1
    assert len(channels_list_v2(create_input[0][1]["token"])["channels"]) == 2
def test_success_private_channel(create_input):
    # length of *_members for Third Channel before join
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["all_members"]) == 1

    assert channel_join_v2(create_input[0][0]["token"],
                           create_input[1][2]["channel_id"]) == {}

    # create_input[0][0] is a global owner so will pass test
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][2]["token"],
            create_input[1][2]["channel_id"])["all_members"]) == 2
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][2]["channel_id"])["owner_members"]) == 1
    assert len(
        channel_details_v2(
            create_input[0][0]["token"],
            create_input[1][2]["channel_id"])["all_members"]) == 2
def test_non_members(test_data):
    a_data, b_data, c_data, ab_ch_id, c_ch_id = test_data

    with pytest.raises(AccessError):
        channel_details_v2(a_data["token"], c_ch_id)
        channel_details_v2(b_data["token"], c_ch_id)
        channel_details_v2(c_data["token"], ab_ch_id)
Exemplo n.º 26
0
def test_order_of_exceptions():
    """ Tests that the function raises exceptions in the order as assumed. The order
        should be:
        1. AccessError from invalid token
        2. InputError from invalid channel id
        3. AccessError when any of the authorised user is not already part of
           the channel with channel_id
    """
    clear_v1()

    user_1 = auth_register_v2("*****@*****.**", "dfgsdgsdfgdf", "Dum",
                              "Doggo")
    user_2 = auth_register_v2("*****@*****.**", "password09123", "Dummy",
                            "Dog")
    channel = channels_create_v2(user_1['token'], "General", True)

    # Pass in invalid channel id, invalid auth id, auth_user who is not part 
    # of the channel. This should raise an access error.
    with pytest.raises(AccessError):
        channel_details_v2(user_2['token'] + 'bug', channel['channel_id'] + 5)

    # Pass in invalid channel id, valid auth id, auth_user who is not part 
    # of the channel. This should raise an input error.
    with pytest.raises(InputError):
        channel_details_v2(user_2['token'], channel['channel_id'] + 5)

    # Pass in valid channel id, valid auth id, auth_user who is not part 
    # of the channel. This should raise an access error.
    with pytest.raises(AccessError):
        channel_details_v2(user_2['token'], channel['channel_id'])

    clear_v1()
Exemplo n.º 27
0
def test_joined_user_is_member(
        reg_user, crt_channel):  # Give valid user_id and channel_id
    clear_v2()
    auth_user_token = reg_user(0)['token']
    channel_id = crt_channel(auth_user_token, True)['channel_id']
    joined_user = reg_user(1)
    channel_join_v2(joined_user['token'], channel_id)
    channel_details = channel_details_v2(auth_user_token, channel_id)
    joined_user_found = False
    for user in channel_details['all_members']:
        if joined_user['auth_user_id'] == user['u_id']:
            joined_user_found = True
    assert joined_user_found  # Verify that joined user is in channel's all_members list
Exemplo n.º 28
0
def test_valid_input_private_channel(
        reg_user, crt_channel, ch_name,
        user_details):  # Test obtaining details from private channel
    clear_v2()
    user_token = reg_user(0)['token']
    channel_id = crt_channel(user_token, False)['channel_id']
    ch_details = channel_details_v2(user_token, channel_id)
    assert ch_details['name'] == ch_name
    assert ch_details['is_public'] == False
    assert len(ch_details['owner_members']) == 1
    assert len(ch_details['all_members']) == 1
    assert ch_details['owner_members'][0] == user_details(0)
    assert ch_details['all_members'][0] == user_details(0)
Exemplo n.º 29
0
def test_valid_input_public(
    reg_user, crt_channel, ch_name, user_details
):  # Test basic functionality with channel creator as only member of public channel
    clear_v2()
    user_token = reg_user(0)['token']
    channel_id = crt_channel(user_token, True)['channel_id']
    ch_details = channel_details_v2(user_token, channel_id)
    assert ch_details['name'] == ch_name
    assert ch_details['is_public'] == True
    assert len(ch_details['owner_members']) == 1
    assert len(ch_details['all_members']) == 1
    assert ch_details['owner_members'][0] == user_details(0)
    assert ch_details['all_members'][0] == user_details(0)
Exemplo n.º 30
0
def test_global_owner_join_private_channel(
        reg_user,
        crt_channel):  # Global owner should be able to join private channel
    clear_v2()
    global_owner = reg_user(0)
    auth_user_token = reg_user(1)['token']
    channel_id = crt_channel(auth_user_token, False)['channel_id']
    channel_join_v2(global_owner['token'], channel_id)
    channel_details = channel_details_v2(auth_user_token, channel_id)
    global_owner_found = False
    for user in channel_details['all_members']:
        if global_owner['auth_user_id'] == user['u_id']:
            global_owner_found = True
    assert global_owner_found  # Verify that global owner user is in channel's all_members list