コード例 #1
0
def test_channel_join_fail(url, user_input, user4_input, channel_input1, channel_input):
    requests.delete(f'{url}clear')
    user = requests.post(f'{url}auth/register', json = user_input).json()
    user1 = requests.post(f'{url}auth/register', json = user4_input).json()

    channel_input1.update({"token": user['token']})
    channel = requests.post(f'{url}channels/create', json = channel_input1).json()
    input_data = {
        "token": user1['token'],
        "channel_id": channel['channel_id'],
    }
    r = requests.post(f'{url}channel/join', json = input_data)
    assert r.status_code == 400
コード例 #2
0
def test_channels_list_fail(url, user_input, invalid_user_input, channel_input,
                            channel_input1, channel_input2, channel_input3):
    requests.delete(f'{url}clear')
    user1 = requests.post(f'{url}auth/register', json=user_input).json()
    user2 = requests.post(f'{url}auth/register',
                          json=invalid_user_input).json()

    channel_input.update({"token": user1['token']})
    channel_input1.update({"token": user1['token']})
    channel_input2.update({"token": user1['token']})
    channel_input3.update({"token": user1['token']})

    r = requests.get(f'{url}channels/list', params=user2)
    assert r.status_code == 400
コード例 #3
0
def test_channel_messages_success(url, user_input, channel_input, channel_input1):
    requests.delete(f'{url}clear')
    user = requests.post(f'{url}auth/register', json = user_input).json()

    channel_input1.update({"token": user['token']})
    channel = requests.post(f'{url}channels/create', json = channel_input1).json()

    input_data = {
        "token": user['token'],
        "channel_id": channel['channel_id'],
        "start": 0
    }

    message = requests.get(f'{url}channel/messages', params = input_data).json()

    assert message == { "messages": [],
                        "start": 0,
                        "end": -1
                      }
コード例 #4
0
def test_channels_listall_fail(url, user_input, user3_input, user4_input,
                               channel_input, channel_input1, channel_input2,
                               channel_input3):
    requests.delete(f'{url}clear')
    user1 = requests.post(f'{url}auth/register', json=user_input).json()
    user2 = requests.post(f'{url}auth/register', json=user3_input).json()
    user3 = requests.post(f'{url}auth/register', json=user4_input).json()

    channel_input.update({"token": user1['token']})
    channel_input1.update({"token": user1['token']})
    channel_input2.update({"token": user2['token']})
    channel_input3.update({"token": user2['token']})

    channel = requests.post(f'{url}channels/create', json=channel_input).json()

    input_data1 = {
        "token": user1['token'],
        "channel_id": channel['channel_id'],
        "user_id": user2['u_id']
    }
    input_data2 = {
        "token": user1['token'],
        "channel_id": channel['channel_id'],
        "user_id": user3['u_id']
    }
    input_data3 = {
        "token": user2['token'],
        "channel_id": channel['channel_id'],
        "user_id": user1['u_id']
    }
    input_data4 = {
        "token": user2['token'],
        "channel_id": channel['channel_id'],
        "user_id": user3['u_id']
    }
    requests.post(f'{url}channel/invite', json=input_data1).json()
    requests.post(f'{url}channel/invite', json=input_data2).json()
    requests.post(f'{url}channel/invite', json=input_data3).json()
    requests.post(f'{url}channel/invite', json=input_data4).json()

    r = requests.get(f'{url}channels/listall', json=user1['token'])
    assert r.status_code == 400
コード例 #5
0
def test_channels_list_success(url, user_input, user3_input, channel_input,
                               channel_input1, channel_input2, channel_input3):
    requests.delete(f'{url}clear')
    user1 = requests.post(f'{url}auth/register', json=user_input).json()
    user2 = requests.post(f'{url}auth/register', json=user3_input).json()

    channel_input.update({"token": user1['token']})
    channel_input1.update({"token": user1['token']})
    channel_input2.update({"token": user1['token']})
    channel_input3.update({"token": user1['token']})

    channel = requests.post(f'{url}channels/create', json=channel_input).json()
    channel1 = requests.post(f'{url}channels/create',
                             json=channel_input1).json()
    channel2 = requests.post(f'{url}channels/create',
                             json=channel_input2).json()
    channel3 = requests.post(f'{url}channels/create',
                             json=channel_input3).json()

    output1 = requests.get(f'{url}channels/list',
                           params={
                               "token": user1['token']
                           }).json()
    output2 = requests.get(f'{url}channels/list',
                           params={
                               "token": user2['token']
                           }).json()

    check_list = [channel['channel_id'] for channel in output1['channels']]
    expected_output = [
        channel['channel_id'], channel1['channel_id'], channel2['channel_id'],
        channel3['channel_id']
    ]
    check_list.sort()
    expected_output.sort()
    assert check_list == expected_output
    assert output2 == {'channels': []}
コード例 #6
0
def test_user_full(url, user_input, user2_input, user3_input, channel_input,
                   channel_input1, channel_input2):
    requests.delete(f'{url}clear')

    user = requests.post(f'{url}auth/register', json=user_input).json()
    user2 = requests.post(f'{url}auth/register', json=user2_input).json()
    user3 = requests.post(f'{url}auth/register', json=user3_input).json()

    # change all the details of both users
    data_name = {
        "token": user['token'],
        "name_first": "bill",
        "name_last": "monkey"
    }
    requests.put(f'{url}user/profile/setname', json=data_name)

    data_name2 = {
        "token": user2['token'],
        "name_first": "hayy",
        "name_last": "mann"
    }
    requests.put(f'{url}user/profile/setname', json=data_name2)

    data_email = {"token": user['token'], "email": "*****@*****.**"}
    requests.put(f'{url}user/profile/setemail', json=data_email)

    data_email2 = {
        "token": user2['token'],
        "email": "*****@*****.**"
    }
    requests.put(f'{url}user/profile/setemail', json=data_email2)

    data_handle = {"token": user['token'], "handle_str": "you_wanna_pizza_me!"}
    requests.put(f'{url}user/profile/sethandle', json=data_handle)

    data_handle2 = {"token": user2['token'], "handle_str": "riddles"}
    requests.put(f'{url}user/profile/sethandle', json=data_handle2)

    channel_input.update({"token": user3['token']})
    channel_input1.update({"token": user['token']})
    channel_input2.update({"token": user2['token']})

    requests.post(f'{url}channels/create', json=channel_input).json()
    channel1 = requests.post(f'{url}channels/create',
                             json=channel_input1).json()
    channel2 = requests.post(f'{url}channels/create',
                             json=channel_input2).json()

    input_data1 = {
        "token": user['token'],
        "channel_id": channel1['channel_id'],
        "u_id": user3['u_id']
    }
    input_data2 = {
        "token": user2['token'],
        "channel_id": channel2['channel_id'],
        "u_id": user['u_id']
    }

    requests.post(f'{url}channel/invite', json=input_data1).json()
    requests.post(f'{url}channel/invite', json=input_data2).json()

    input_data = {
        "token": user3["token"],
        "img_url":
        "https://s3.amazonaws.com/spectrumnews-web-assets/wp-content/uploads/2018/11/13154625/20181112-SHANK3monkey-844.jpg",
        "x_start": 0,
        "y_start": 0,
        "x_end": 800,
        "y_end": 500
    }
    requests.post(f'{url}user/profile/uploadphoto', json=input_data)

    # user check
    resp = requests.get(f'{url}user/profile', params=user).json()
    assert resp['user'] == {
        "u_id": user['u_id'],
        "email": "*****@*****.**",
        "name_first": "bill",
        "name_last": "monkey",
        "handle_str": "you_wanna_pizza_me!",
        "profile_img_url": ""
    }

    # user2 check
    resp1 = requests.get(f'{url}user/profile', params=user2).json()
    assert resp1['user'] == {
        "u_id": user2['u_id'],
        "email": "*****@*****.**",
        "name_first": "hayy",
        "name_last": "mann",
        "handle_str": "riddles",
        "profile_img_url": ""
    }

    resp3 = requests.get(f'{url}user/profile', params=user3).json()
    assert resp3['user']["profile_img_url"] != ""
コード例 #7
0
def test_channels_all(url, user_input, user3_input, user4_input, channel_input,
                      channel_input1, channel_input2, channel_input3):
    requests.delete(f'{url}clear')
    user1 = requests.post(f'{url}auth/register', json=user_input).json()
    user2 = requests.post(f'{url}auth/register', json=user3_input).json()
    user3 = requests.post(f'{url}auth/register', json=user4_input).json()

    channel_input.update({"token": user1['token']})
    channel_input1.update({"token": user1['token']})
    channel_input2.update({"token": user2['token']})
    channel_input3.update({"token": user2['token']})

    channel = requests.post(f'{url}channels/create', json=channel_input).json()
    channel1 = requests.post(f'{url}channels/create',
                             json=channel_input1).json()
    channel2 = requests.post(f'{url}channels/create',
                             json=channel_input2).json()
    channel3 = requests.post(f'{url}channels/create',
                             json=channel_input3).json()

    assert channel is not None
    assert channel['channel_id'] is not None
    assert isinstance(channel['channel_id'], int)

    # test channels/list

    output1 = requests.get(f'{url}channels/list',
                           params={
                               "token": user1['token']
                           }).json()
    output2 = requests.get(f'{url}channels/list',
                           params={
                               "token": user2['token']
                           }).json()
    expected_output1 = [channel['channel_id'], channel1['channel_id']]
    expected_output2 = [channel2['channel_id'], channel3['channel_id']]

    check_list1 = [channel['channel_id'] for channel in output1['channels']]
    check_list2 = [channel['channel_id'] for channel in output2['channels']]

    check_list1.sort()
    expected_output1.sort()
    check_list2.sort()
    expected_output2.sort()

    assert check_list1 == expected_output1
    assert check_list2 == expected_output2

    # check listall
    input_data1 = {
        "token": user1['token'],
        "channel_id": channel['channel_id'],
        "user_id": user2['u_id']
    }
    input_data2 = {
        "token": user1['token'],
        "channel_id": channel['channel_id'],
        "user_id": user3['u_id']
    }
    input_data3 = {
        "token": user2['token'],
        "channel_id": channel['channel_id'],
        "user_id": user1['u_id']
    }
    input_data4 = {
        "token": user2['token'],
        "channel_id": channel['channel_id'],
        "user_id": user3['u_id']
    }
    requests.post(f'{url}channel/invite', json=input_data1).json()
    requests.post(f'{url}channel/invite', json=input_data2).json()
    requests.post(f'{url}channel/invite', json=input_data3).json()
    requests.post(f'{url}channel/invite', json=input_data4).json()

    output1 = requests.get(f'{url}channels/listall',
                           params={
                               "token": user1['token']
                           }).json()
    output2 = requests.get(f'{url}channels/listall',
                           params={
                               "token": user2['token']
                           }).json()

    check_list = [channel['channel_id'] for channel in output1['channels']]
    expected_output = [
        channel['channel_id'], channel1['channel_id'], channel2['channel_id'],
        channel3['channel_id']
    ]
    check_list.sort()
    expected_output.sort()
    assert check_list == expected_output

    check_list = [channel['channel_id'] for channel in output2['channels']]
    expected_output = [
        channel['channel_id'], channel1['channel_id'], channel2['channel_id'],
        channel3['channel_id']
    ]
    check_list.sort()
    expected_output.sort()
    assert check_list == expected_output