def test_dm_details_v1_token(reg_user):
    clear_v2()
    token_sender = reg_user(0)['token']
    auth_user_id_receiver = reg_user(1)['auth_user_id']
    dm_id = dm_create_v1(token_sender, [auth_user_id_receiver])['dm_id']
    fake_token = 'garbage values'

    with pytest.raises(AccessError):
        dm_details_v1(fake_token, dm_id)
def test_dm_details_v1_dm_id_is_non_valid_dm(reg_user):
    clear_v2()
    token_sender = reg_user(0)['token']
    auth_user_id_receiver = reg_user(1)['auth_user_id']
    dm_create_v1(token_sender, [auth_user_id_receiver])
    fake_dm_id = 'garbage values'

    with pytest.raises(InputError):
        dm_details_v1(token_sender, fake_dm_id)
def test_invalid_dm_id():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]

    with pytest.raises(InputError):
        dm_details_v1(auth_user_1_token, 99999)
def test_dm_details_v1_auth_user_not_a_member_of_dm(reg_user):
    clear_v2()
    token_sender = reg_user(0)['token']
    auth_user_id_receiver = reg_user(1)['auth_user_id']
    token_non_auth_user = reg_user(2)['token']
    dm_id = dm_create_v1(token_sender, [auth_user_id_receiver])['dm_id']
    with pytest.raises(AccessError):
        dm_details_v1(
            token_non_auth_user, dm_id
        )  #since this user was never appart of the dm he cant access info to it
Esempio n. 5
0
def test_dm_details_v1_multiple(user_setup, dm_setup):

    # Test 2:
    # Lists the details of dm no.1 with multiple users in the dm
    assert dm_details_v1(make_token(1), 0) == {
        "name":
        "christopherluong, gungeetsingh, petertran",
        "members": [{
            'u_id': 1,
            'email': "*****@*****.**",
            'name_first': 'Peter',
            'name_last': 'Tran',
            'handle': 'petertran'
        }, {
            'u_id': 0,
            'email': "*****@*****.**",
            'name_first': 'Gungeet',
            'name_last': 'Singh',
            'handle': 'gungeetsingh'
        }, {
            'u_id': 2,
            'email': "*****@*****.**",
            'name_first': 'Christopher',
            'name_last': 'Luong',
            'handle': 'christopherluong'
        }],
    }
Esempio n. 6
0
def test_commom_one(reg_user):
    clear_v2()
    user = reg_user(0)
    token = user['token']
    u_id = user['auth_user_id']

    # one dm id
    dm = dm_create_v1(token, [u_id])
    dm_id = dm['dm_id']

    dm_remove_v1(token, dm_id)

    dm_list = dm_list_v1(token)['dms']
    assert not len(dm_list)

    with pytest.raises(InputError):
        dm_details_v1(token, dm_id)
Esempio n. 7
0
def test_commom_more(reg_user):
    clear_v2()
    user = reg_user(0)
    token = user['token']

    user_2 = reg_user(1)
    user_2_id = user_2['auth_user_id']

    # more dm id
    dm1 = dm_create_v1(token, [user_2_id])
    dm_id1 = dm1['dm_id']
    dm2 = dm_create_v1(token, [user_2_id])
    dm_id2 = dm2['dm_id']
    dm3 = dm_create_v1(token, [user_2_id])
    dm_id3 = dm3['dm_id']
    dm_remove_v1(token, dm_id1)
    dm_remove_v1(token, dm_id2)
    dm_remove_v1(token, dm_id3)

    dm_list = dm_list_v1(token)['dms']
    assert not len(dm_list)

    # dm become invaild
    with pytest.raises(InputError):
        dm_details_v1(token, dm_id1)
    with pytest.raises(InputError):
        dm_details_v1(token, dm_id2)
    with pytest.raises(InputError):
        dm_details_v1(token, dm_id3)
Esempio n. 8
0
def test_invite_single_user(reg_user):
    clear_v2()
    sender = reg_user(0)
    receiver_id = reg_user(1)['auth_user_id']

    dm = dm_create_v1(sender['token'], [receiver_id])

    invitee_id = reg_user(2)['auth_user_id']
    dm_invite_v1(sender['token'], dm['dm_id'], invitee_id)

    dm_members = [sender['auth_user_id'], receiver_id, invitee_id]
    dm_details = dm_details_v1(sender['token'], dm['dm_id'])
    for user in dm_details['members']:
        assert user['u_id'] in dm_members
Esempio n. 9
0
def test_invite_multi_user(reg_user):
    clear_v2()
    sender = reg_user(0)
    receiver_id = reg_user(1)['auth_user_id']
    dm = dm_create_v1(sender['token'], [receiver_id])
    dm_members = [sender['auth_user_id'], receiver_id]

    for i in range(2, 5):
        invitee_id = reg_user(i)['auth_user_id']
        dm_invite_v1(sender['token'], dm['dm_id'], invitee_id)
        dm_members.append(invitee_id)

    dm_details = dm_details_v1(sender['token'], dm['dm_id'])
    for user in dm_details['members']:
        assert user['u_id'] in dm_members
def test_non_member():
    clear_v1()
    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]

    auth_user_2_data = auth_register_v2("*****@*****.**", "123456", "Bob",
                                        "Hobs")
    auth_user_2_id = auth_user_2_data["auth_user_id"]

    auth_user_3_data = auth_register_v2("*****@*****.**", "123456", "Chris",
                                        "Wiz")
    auth_user_3_id = auth_user_3_data["auth_user_id"]

    dm_data_1 = dm_create_v1(auth_user_1_token,
                             [auth_user_2_id, auth_user_3_id])
    dm_id_1 = dm_data_1["dm_id"]

    auth_user_4_data = auth_register_v2("*****@*****.**", "123456", "Joshua",
                                        "King")
    auth_user_4_token = auth_user_4_data["token"]

    with pytest.raises(AccessError):
        dm_details_v1(auth_user_4_token, dm_id_1)
Esempio n. 11
0
def test_dm_leave_v1_owner(user_setup, dm_setup):

    # dm_create_v1(make_token(1), [0, 2]) # dm_id 0
    dm_leave_v1(make_token(0), 0)
    dm_leave_v1(make_token(1), 0)
    assert dm_details_v1(make_token(2), 0) == {
        "name":
        "christopherluong",
        "members": [
            {
                'u_id': 2,
                'email': "*****@*****.**",
                'name_first': 'Christopher',
                'name_last': 'Luong',
                'handle': 'christopherluong'
            },
        ],
    }
def test_dm_details_v1_basic(reg_user):
    clear_v2()
    user_register_sender = reg_user(0)  #sender
    user_register_receiver = reg_user(1)  #receiver
    dm = dm_create_v1(user_register_sender['token'],
                      [user_register_receiver['auth_user_id']])
    dm_members = [
        user_register_sender['auth_user_id'],
        user_register_receiver['auth_user_id']
    ]  # create a list with the ids of the users
    dm_details = dm_details_v1(user_register_sender['token'], dm['dm_id'])
    for user in dm_details['members']:
        assert user['u_id'] in dm_members
    assert dm_details['members'][0]['email'] == '*****@*****.**'
    assert dm_details['members'][0]['name_first'] == 'firstname0'
    assert dm_details['members'][0]['name_last'] == 'lastname0'
    assert dm_details['members'][1]['email'] == '*****@*****.**'
    assert dm_details['members'][1]['name_first'] == 'firstname1'
    assert dm_details['members'][1]['name_last'] == 'lastname1'
    assert dm_details['name'] == dm['dm_name']
Esempio n. 13
0
def test_dm_details_v1(user_setup, dm_setup):

    # Test 1:
    # Lists the details of dm no.2
    assert dm_details_v1(make_token(1), 1) == {
        "name":
        "gungeetsingh, petertran",
        "members": [{
            'u_id': 0,
            'email': "*****@*****.**",
            'name_first': 'Gungeet',
            'name_last': 'Singh',
            'handle': 'gungeetsingh'
        }, {
            'u_id': 1,
            'email': "*****@*****.**",
            'name_first': 'Peter',
            'name_last': 'Tran',
            'handle': 'petertran'
        }],
    }
Esempio n. 14
0
def test_dm_invite_v1_success(user_setup, dm_setup):
    # dm_create_v1(make_token(0), [1]) # dm_id 1
    dm_invite_v1(make_token(0), 1, 2)
    dm_invite_v1(make_token(0), 1, 3)
    dm_invite_v1(make_token(0), 1, 4)
    assert dm_details_v1(make_token(0), 1) == {
        "name":
        "christopherluong, eyaldorfan, gungeetsingh, petertran, talavrahami",
        "members": [{
            'u_id': 0,
            'email': "*****@*****.**",
            'name_first': 'Gungeet',
            'name_last': 'Singh',
            'handle': 'gungeetsingh'
        }, {
            'u_id': 1,
            'email': "*****@*****.**",
            'name_first': 'Peter',
            'name_last': 'Tran',
            'handle': 'petertran'
        }, {
            'u_id': 2,
            'email': "*****@*****.**",
            'name_first': 'Christopher',
            'name_last': 'Luong',
            'handle': 'christopherluong'
        }, {
            'u_id': 3,
            'email': "*****@*****.**",
            'name_first': 'Tal',
            'name_last': 'Avrahami',
            'handle': 'talavrahami'
        }, {
            'u_id': 4,
            'email': "*****@*****.**",
            'name_first': 'Eyal',
            'name_last': 'Dorfan',
            'handle': 'eyaldorfan'
        }],
    }
Esempio n. 15
0
def test_dm_details_v1_errors(user_setup, dm_setup):
    # Test the errors for channel_details_v1
    # Test 1:
    # invalid token
    with pytest.raises(AccessError):
        dm_details_v1(123456, 2)  # "Invalid token"

    # Test 2:
    # invalid dm
    with pytest.raises(InputError):
        dm_details_v1(make_token(1), 10)  # "Invalid dm"

    # Test 3:
    # Authorised user is not a member of dm with dm_id
    with pytest.raises(AccessError):
        dm_details_v1(make_token(0), 2)
Esempio n. 16
0
def test_dm_leave_v1_success(user_setup, dm_setup):

    # Test 1:
    # Remove user no.3 from dm no.1
    # dm_create_v1(make_token(1), [0, 2]) # dm_id 0
    dm_leave_v1(make_token(2), 0)
    assert dm_details_v1(make_token(1), 0) == {
        "name":
        "gungeetsingh, petertran",
        "members": [{
            'u_id': 1,
            'email': "*****@*****.**",
            'name_first': 'Peter',
            'name_last': 'Tran',
            'handle': 'petertran'
        }, {
            'u_id': 0,
            'email': "*****@*****.**",
            'name_first': 'Gungeet',
            'name_last': 'Singh',
            'handle': 'gungeetsingh'
        }],
    }
Esempio n. 17
0
def dm_details():
    token = request.args.get('token')
    dm_id = request.args.get('dm_id')

    dm_details = dm_details_v1(token, dm_id)
    return dumps(dm_details)
Esempio n. 18
0
def dm_details():
    parameters = request.args
    token = parameters['token']
    dm_id = int(parameters['dm_id'])
    output = dm_details_v1(token, dm_id)
    return dumps(output)
def test_dm_details_v1():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]
    auth_user_1_id = auth_user_1_data["auth_user_id"]

    auth_user_2_data = auth_register_v2("*****@*****.**", "123456", "Bob",
                                        "Hobs")
    auth_user_2_token = auth_user_2_data["token"]
    auth_user_2_id = auth_user_2_data["auth_user_id"]

    auth_user_3_data = auth_register_v2("*****@*****.**", "123456", "Chris",
                                        "Wiz")
    auth_user_3_id = auth_user_3_data["auth_user_id"]

    dm_data_1 = dm_create_v1(auth_user_1_token,
                             [auth_user_2_id, auth_user_3_id])
    dm_id_1 = dm_data_1["dm_id"]
    dm_name_1 = dm_data_1["dm_name"]

    members_1 = []
    user_1_profile = user_profile_v2(auth_user_1_token, auth_user_1_id)["user"]
    members_1.append(user_1_profile)
    user_2_profile = user_profile_v2(auth_user_1_token, auth_user_2_id)["user"]
    members_1.append(user_2_profile)
    user_3_profile = user_profile_v2(auth_user_1_token, auth_user_3_id)["user"]
    members_1.append(user_3_profile)

    assert dm_details_v1(auth_user_1_token, dm_id_1) == {
        "name": dm_name_1,
        "members": members_1
    }

    auth_user_4_data = auth_register_v2("*****@*****.**", "123456", "Joshua",
                                        "King")
    auth_user_4_id = auth_user_4_data["auth_user_id"]

    dm_invite_v1(auth_user_1_token, dm_id_1, auth_user_4_id)
    user_4_profile = user_profile_v2(auth_user_1_token, auth_user_4_id)["user"]
    members_1.append(user_4_profile)

    assert dm_details_v1(auth_user_1_token, dm_id_1) == {
        "name": dm_name_1,
        "members": members_1
    }

    dm_data_2 = dm_create_v1(auth_user_2_token,
                             [auth_user_1_id, auth_user_3_id, auth_user_4_id])
    dm_id_2 = dm_data_2["dm_id"]
    dm_name_2 = dm_data_2["dm_name"]

    members_2 = []
    members_2.append(user_2_profile)
    members_2.append(user_1_profile)
    members_2.append(user_3_profile)
    members_2.append(user_4_profile)

    assert dm_details_v1(auth_user_1_token, dm_id_2) == {
        "name": dm_name_2,
        "members": members_2
    }