Пример #1
0
def dm_details_v1_http():
    data = request.args
    token = str(data['token'])  #the pass in value
    dm_id = int(data['dm_id'])  #the pass in value

    return_val = dm_details_v1(
        token, dm_id)  # get the return value, which is not dumped

    return dumps(return_val)
Пример #2
0
def test_removed_from_dm():
    """Tests that a user is removed from a dm"""
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng")
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton")

    dm_1 = dm_create_v1(user_1["token"], [])
    dm_invite_v1(user_1["token"], dm_1["dm_id"], user_2["auth_user_id"])

    admin_user_remove_v1(user_1["token"], user_2["auth_user_id"])

    members = dm_details_v1(user_1["token"], dm_1["dm_id"])["members"]

    assert user_2["auth_user_id"] not in [m["u_id"] for m in members]
def test_dm_leave(create_dms):
    users = create_dms['users']
    dm_1 = create_dms['dms'][0]
    dm_2 = create_dms['dms'][1]
    dm_3 = create_dms['dms'][2]

    dm_details_v1(users[0]['token'], dm_1['dm_id'])
    dm_leave_v1(users[2]['token'], dm_1['dm_id'])
    dm_leave_v1(users[0]['token'], dm_1['dm_id'])
    dm_leave_v1(users[1]['token'], dm_1['dm_id'])
    

    dm_details_v1(users[1]['token'], dm_2['dm_id'])
    dm_leave_v1(users[1]['token'], dm_2['dm_id'])




    dm_details_v1(users[3]['token'], dm_3['dm_id'])
    dm_leave_v1(users[3]['token'], dm_3['dm_id'])
    dm_leave_v1(users[0]['token'], dm_3['dm_id'])
    dm_leave_v1(users[2]['token'], dm_3['dm_id'])
    dm_leave_v1(users[1]['token'], dm_3['dm_id'])

    with pytest.raises(InputError):
        dm_details_v1(users[0]['token'], dm_1['dm_id'])
    
    with pytest.raises(InputError):
        dm_details_v1(users[3]['token'], dm_3['dm_id'])

    with pytest.raises(InputError):
        dm_details_v1(users[1]['token'], dm_2['dm_id'])
    
    clear_v1()
def test_dm_create(register_users):
    users = register_users
    user_list = []
    user_list.append(users[1]['auth_user_id'])
    user_list.append(users[2]['auth_user_id'])
    user_1 = users[0]
    dm_1 = dm_create_v1(user_1['token'], user_list)  #create dm 1

    profile_0 = user_profile_v2(user_1['token'],
                                user_1['auth_user_id'])['user']
    profile_1 = user_profile_v2(user_1['token'],
                                users[1]['auth_user_id'])['user']
    profile_2 = user_profile_v2(user_1['token'],
                                users[2]['auth_user_id'])['user']
    profile_3 = user_profile_v2(user_1['token'],
                                users[3]['auth_user_id'])['user']

    rt_val = dm_details_v1(user_1['token'], dm_1['dm_id'])
    assert rt_val['name'] == "ab, cd, ef"
    assert sorted(rt_val['members'],
                  key=lambda x: x['u_id']) == sorted([
                      {
                          'u_id': users[1]['auth_user_id'],
                          'name_first': 'c',
                          'name_last': 'd',
                          'email': '*****@*****.**',
                          'handle_str': 'cd',
                          'profile_img_url': profile_1['profile_img_url'],
                      },
                      {
                          'u_id': users[2]['auth_user_id'],
                          'name_first': 'e',
                          'name_last': 'f',
                          'email': '*****@*****.**',
                          'handle_str': 'ef',
                          'profile_img_url': profile_2['profile_img_url'],
                      },
                      {
                          'u_id': users[0]['auth_user_id'],
                          'name_first': 'a',
                          'name_last': 'b',
                          'email': '*****@*****.**',
                          'handle_str': 'ab',
                          'profile_img_url': profile_0['profile_img_url'],
                      },
                  ],
                                                     key=lambda x: x['u_id'])

    user_2 = users[1]
    user_list = []
    user_list.append(users[0]['auth_user_id'])
    dm_2 = dm_create_v1(user_2['token'], user_list)  #create dm 2

    rt_val = dm_details_v1(user_2['token'], dm_2['dm_id'])
    assert rt_val['name'] == "ab, cd"
    assert sorted(rt_val['members'],
                  key=lambda x: x['u_id']) == sorted([
                      {
                          'u_id': users[1]['auth_user_id'],
                          'name_first': 'c',
                          'name_last': 'd',
                          'email': '*****@*****.**',
                          'handle_str': 'cd',
                          'profile_img_url': profile_1['profile_img_url'],
                      },
                      {
                          'u_id': users[0]['auth_user_id'],
                          'name_first': 'a',
                          'name_last': 'b',
                          'email': '*****@*****.**',
                          'handle_str': 'ab',
                          'profile_img_url': profile_0['profile_img_url'],
                      },
                  ],
                                                     key=lambda x: x['u_id'])

    user_4 = users[3]
    user_list = []
    user_list.append(users[0]['auth_user_id'])
    user_list.append(users[1]['auth_user_id'])
    user_list.append(users[2]['auth_user_id'])
    dm_3 = dm_create_v1(user_4['token'], user_list)  #create dm 3

    rt_val = dm_details_v1(user_4['token'], dm_3['dm_id'])
    assert rt_val['name'] == "ab, cd, ef, gh"
    assert sorted(rt_val['members'],
                  key=lambda x: x['u_id']) == sorted([
                      {
                          'u_id': users[0]['auth_user_id'],
                          'name_first': 'a',
                          'name_last': 'b',
                          'email': '*****@*****.**',
                          'handle_str': 'ab',
                          'profile_img_url': profile_0['profile_img_url'],
                      },
                      {
                          'u_id': users[1]['auth_user_id'],
                          'name_first': 'c',
                          'name_last': 'd',
                          'email': '*****@*****.**',
                          'handle_str': 'cd',
                          'profile_img_url': profile_1['profile_img_url'],
                      },
                      {
                          'u_id': users[2]['auth_user_id'],
                          'name_first': 'e',
                          'name_last': 'f',
                          'email': '*****@*****.**',
                          'handle_str': 'ef',
                          'profile_img_url': profile_2['profile_img_url'],
                      },
                      {
                          'u_id': users[3]['auth_user_id'],
                          'name_first': 'g',
                          'name_last': 'h',
                          'email': '*****@*****.**',
                          'handle_str': 'gh',
                          'profile_img_url': profile_3['profile_img_url'],
                      },
                  ],
                                                     key=lambda x: x['u_id'])

    clear_v1()
Пример #5
0
def test_dm_invite(create_dms):
    users = create_dms['users']
    dm_1 = create_dms['dms'][0]
    dm_2 = create_dms['dms'][1]
    #dm_3 = create_dms['dms'][2]

    dm_invite_v1(users[0]['token'], dm_1['dm_id'], users[3]['auth_user_id'])

    profile_0 = user_profile_v2(users[0]['token'],
                                users[0]['auth_user_id'])['user']
    profile_1 = user_profile_v2(users[0]['token'],
                                users[1]['auth_user_id'])['user']
    profile_2 = user_profile_v2(users[0]['token'],
                                users[2]['auth_user_id'])['user']
    profile_3 = user_profile_v2(users[0]['token'],
                                users[3]['auth_user_id'])['user']

    rt_val_1 = dm_details_v1(users[0]['token'], dm_1['dm_id'])
    assert rt_val_1['name'] == "ab, cd, ef"
    assert sorted(rt_val_1['members'],
                  key=lambda x: x['u_id']) == sorted([
                      {
                          'u_id': users[1]['auth_user_id'],
                          'name_first': 'c',
                          'name_last': 'd',
                          'email': '*****@*****.**',
                          'handle_str': 'cd',
                          'profile_img_url': profile_1['profile_img_url'],
                      },
                      {
                          'u_id': users[2]['auth_user_id'],
                          'name_first': 'e',
                          'name_last': 'f',
                          'email': '*****@*****.**',
                          'handle_str': 'ef',
                          'profile_img_url': profile_2['profile_img_url'],
                      },
                      {
                          'u_id': users[0]['auth_user_id'],
                          'name_first': 'a',
                          'name_last': 'b',
                          'email': '*****@*****.**',
                          'handle_str': 'ab',
                          'profile_img_url': profile_0['profile_img_url'],
                      },
                      {
                          'u_id': users[3]['auth_user_id'],
                          'name_first': 'g',
                          'name_last': 'h',
                          'email': '*****@*****.**',
                          'handle_str': 'gh',
                          'profile_img_url': profile_3['profile_img_url'],
                      },
                  ],
                                                     key=lambda x: x['u_id'])

    dm_invite_v1(users[1]['token'], dm_2['dm_id'], users[2]['auth_user_id'])
    dm_invite_v1(users[1]['token'], dm_2['dm_id'], users[3]['auth_user_id'])

    rt_val_2 = dm_details_v1(users[1]['token'], dm_2['dm_id'])
    assert rt_val_2['name'] == "ab, cd"
    assert sorted(rt_val_2['members'],
                  key=lambda x: x['u_id']) == sorted([
                      {
                          'u_id': users[0]['auth_user_id'],
                          'name_first': 'a',
                          'name_last': 'b',
                          'email': '*****@*****.**',
                          'handle_str': 'ab',
                          'profile_img_url': profile_0['profile_img_url'],
                      },
                      {
                          'u_id': users[1]['auth_user_id'],
                          'name_first': 'c',
                          'name_last': 'd',
                          'email': '*****@*****.**',
                          'handle_str': 'cd',
                          'profile_img_url': profile_1['profile_img_url'],
                      },
                      {
                          'u_id': users[2]['auth_user_id'],
                          'name_first': 'e',
                          'name_last': 'f',
                          'email': '*****@*****.**',
                          'handle_str': 'ef',
                          'profile_img_url': profile_2['profile_img_url'],
                      },
                      {
                          'u_id': users[3]['auth_user_id'],
                          'name_first': 'g',
                          'name_last': 'h',
                          'email': '*****@*****.**',
                          'handle_str': 'gh',
                          'profile_img_url': profile_3['profile_img_url'],
                      },
                  ],
                                                     key=lambda x: x['u_id'])
    clear_v1()
Пример #6
0
def test_dm_details_errors(create_dms):
    users = create_dms['users']
    dm_1 = create_dms['dms'][0]
    dm_2 = create_dms['dms'][1]
    #dm_3 = create_dms['dms'][2]

    with pytest.raises(InputError):
        dm_details_v1(users[0]['token'], 100)

    with pytest.raises(InputError):
        dm_details_v1(users[0]['token'], 500)

    with pytest.raises(AccessError):
        dm_details_v1(users[3]['token'], dm_1['dm_id'])

    with pytest.raises(AccessError):
        dm_details_v1(users[3]['token'], dm_2['dm_id'])
    
    with pytest.raises(AccessError):
        dm_details_v1(users[2]['token'], dm_2['dm_id'])
    
    with pytest.raises(AccessError):
        dm_details_v1("fewfwfe", dm_1['dm_id'])
    
    clear_v1()