Exemple #1
0
def test_basic():
    '''
    Test correct input -> output
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # invite users to channel
    invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"],
                        URL_INVITE)
    invite_user_channel(users_data[0]["token"], ch_id, users_data[2]["u_id"],
                        URL_INVITE)

    token = users_data[0]["token"]

    # send a details request
    payload = requests.get(URL_DETAILS +
                           f'?token={token}&channel_id={ch_id}').json()

    # confirm output
    assert payload["name"] == "FOX_NEWS"
    assert payload["owner_members"] and payload["all_members"]
Exemple #2
0
def test_route_name():
    '''
    This tests for inclusivity of '/' in the route url.
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # invite users to channel
    invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"],
                        URL_INVITE)
    invite_user_channel(users_data[0]["token"], ch_id, users_data[2]["u_id"],
                        URL_INVITE)

    token = users_data[0]["token"]

    response = requests.get(URL_DETAILS + '/' +
                            f'?token={token}&channel_id={ch_id}')

    assert response.status_code == 404
def test_user_not_owner_of_slackr_or_channel():
        # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    token_0 = users_data[0]["token"]
    token_1 = users_data[1]["token"]
    token_2 = users_data[2]["token"]

    # ch_id: owner = token_0; member = token_0, token_2
    # ch_id2: owner = token1; member = token_1
    ch_id = common_set.create_channel_99(users_data[0]["token"])
    data_in = {"token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True}
    ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id']
    invite_user_channel(token_0, ch_id, users_data[2]['u_id'], URL_INVITE)


    # send 3 messages to each channel + 1 extra into channel2
    msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "a"}).json()['message_id']
    msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "b"}).json()['message_id']
    msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "c"}).json()['message_id']
    msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "d"}).json()['message_id']
    msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "e"}).json()['message_id']
    msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "f"}).json()['message_id']
    
    requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg1_1})
    requests.post(URL_MSG_PIN, json={"token": token_2, "message_id": msg1_2})
    requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg3_2})

    # unpin some messages where you arent owner of channel or slackr
    response = requests.post(URL_MSG_UNPIN, json={"token": token_2, "message_id": msg1_1})
    assert response.status_code == 400
def test_route_name():
    '''
    This tests for inclusivity of '/' in the route url.
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # send a invite request
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # add a user[2] as an owner
    common_set.add_user_owner(
        users_data[0]["token"], ch_id, users_data[2]["u_id"])

    # confirm http error, code = 404
    response = requests.post(URL_REMOWNER + '/', json={
        "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]})

    assert response.status_code == 404
def test_basic():
    '''
    This is a sanity test for correct output based on all-correct input.
    '''
    # debug mode
    # pdb.set_trace()

    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    token_0 = users_data[0]["token"]
    token_1 = users_data[1]["token"]
    token_2 = users_data[2]["token"]

    # owner of slackr = token_0
    # ch_id: owner = token_0; member = token_0, token_2
    # ch_id2: owner = token1; member = token_1
    ch_id = common_set.create_channel_99(users_data[0]["token"])
    data_in = {"token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True}
    ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id']
    invite_user_channel(token_0, ch_id, users_data[2]['u_id'], URL_INVITE)


    # send 3 messages to each channel + 1 extra into channel2
    msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "a"}).json()['message_id']
    msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "b"}).json()['message_id']
    msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "c"}).json()['message_id']
    msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "d"}).json()['message_id']
    msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "e"}).json()['message_id']
    msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "f"}).json()['message_id']
    
    # pin some messages - first is owner of channel and slackr, second is owner of channel, third is owner of slackr
    requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg1_1})
    requests.post(URL_MSG_PIN, json={"token": token_1, "message_id": msg1_2})
    requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg3_2})

    # unpin the messages - first is owner of channel and slackr, second is owner of channel, third is owner of slackr
    requests.post(URL_MSG_UNPIN, json={"token": token_0, "message_id": msg1_1})
    requests.post(URL_MSG_UNPIN, json={"token": token_1, "message_id": msg1_2})
    requests.post(URL_MSG_UNPIN, json={"token": token_0, "message_id": msg3_2})
    
    # retrieve messages
    payload = requests.get(
        URL_MESSAGES + f"?token={token_0}&channel_id={ch_id}&start=0").json()
    payload2 = requests.get(
        URL_MESSAGES + f"?token={token_1}&channel_id={ch_id2}&start=0").json()
    
    
    # confirm output.
    assert payload["messages"][0]["is_pinned"] == False
    assert payload["messages"][1]["is_pinned"] == False
    assert payload2["messages"][0]["is_pinned"] == False
    assert payload2["messages"][2]["is_pinned"] == False
def test_bad_data_invite():
    '''
    1. Sends a token of a non owner.
    2. Sends an invalid channel id.
    3. Sends an invalid u_id.
    '''

    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # send an invite request to user[1]
    invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"],
                        URL_INVITE)

    # non-owner user[1] trying to invite user[2]
    response = requests.post(URL_INVITE,
                             json={
                                 "token": users_data[1]["token"],
                                 "channel_id": 124124,
                                 "u_id": users_data[2]["u_id"]
                             })

    assert response.status_code == 400

    # send invalid ch_id, which will result in an internal error
    response = requests.post(URL_INVITE,
                             json={
                                 "token": users_data[1]["token"],
                                 "channel_id": 124124,
                                 "u_id": users_data[2]["u_id"]
                             })

    assert response.status_code == 400

    # send invalid u_id
    response = requests.post(URL_INVITE,
                             json={
                                 "token": users_data[1]["token"],
                                 "channel_id": ch_id,
                                 "u_id": 12551
                             })

    assert response.status_code == 400
Exemple #7
0
def test_user_not_in_channel():
    '''Test error occurs where user is not in the channel'''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # ch_id: owner = token_0; member = token_0, token_2
    # ch_id2: owner = token1; member = token_1
    ch_id = common_set.create_channel_99(users_data[0]["token"])
    data_in = {
        "token": users_data[1]["token"],
        "name": "FOX_NEWS",
        "is_public": True
    }
    ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id']

    token_0 = users_data[0]["token"]
    token_1 = users_data[1]["token"]
    token_2 = users_data[2]["token"]
    invite_user_channel(token_0, ch_id, users_data[2]['u_id'], URL_INVITE)

    # send 3 messages to each channel + 1 extra into channel2
    msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \
        "a"}).json()['message_id']
    msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \
        "b"}).json()['message_id']
    msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \
        "c"}).json()['message_id']
    msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \
        "d"}).json()['message_id']
    msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \
        "e"}).json()['message_id']
    msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \
        "f"}).json()['message_id']

    # react to some messages where you arent in the channel
    response = requests.post(URL_MSG_REACT, json={"token": token_1, "message_id": msg1_1, \
        "react_id": 1})
    response2 = requests.post(URL_MSG_REACT, json={"token": token_0, "message_id": msg1_2, \
        "react_id": 1})
    response3 = requests.post(URL_MSG_REACT, json={"token": token_2, "message_id": msg1_2, \
        "react_id": 1})

    assert response.status_code == 400
    assert response2.status_code == 400
    assert response3.status_code == 400
Exemple #8
0
def test_errors():
    '''
    Testing for correct http error returns.
    Input = invalid route from admin
    Expected Ouput = corresponding http error codes
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    invite_user_channel(users_data[0]["token"], ch_id, users_data[2]["u_id"],
                        URL_INVITE)

    token = users_data[0]["token"]

    # confirm http error, code = 404
    # send base url
    response = requests.get(BASE_CHANNEL +
                            f'?token={token}&channel_id={ch_id}')

    assert response.status_code == 404

    # confirm http error, code = 404
    # send base url with 'detail'
    response = requests.get(BASE_CHANNEL + '/detail' +
                            f'?token={token}&channel_id={ch_id}')

    assert response.status_code == 404

    # confirm http error, code = 405
    # send with post method, i.e. not get.
    response = requests.post(URL_DETAILS,
                             json={
                                 "token": token,
                                 "channel_id": ch_id,
                                 "u_id": users_data[2]["u_id"]
                             })

    assert response.status_code == 405
def test_errors():
    '''
    Testing for correct http error returns.
    Input = invalid route
    Expected Ouput = corresponding http error codes
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # send a invite request
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # add a user[2] as an owner
    common_set.add_user_owner(
        users_data[0]["token"], ch_id, users_data[2]["u_id"])

    # confirm http error, code = 404
    # send base url
    response = requests.post(BASE_CHANNEL, json={
        "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]})

    assert response.status_code == 404

    # confirm http error, code = 404
    # send base url appended with '/removal', i.e. a possible user mistake.
    response = requests.post(BASE_CHANNEL + '/removal', json={
        "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]})

    assert response.status_code == 404

    # confirm http error, code = 405
    # send base url
    response = requests.get(URL_REMOWNER, json={
        "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]})

    assert response.status_code == 405
def test_errors():
    '''
    Testing for correct http error returns.
    Input = invalid route from admin
    Expected Ouput = corresponding http error codes
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # invite user to channel
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # send a leave request
    response = requests.post(
        BASE_CHANNEL, json={"token": users_data[2]["token"], "channel_id": ch_id})

    assert response.status_code == 404

    # send a join request to base channel. if this doesnt raise an error,
    # there are serious problems with the implementation
    response = requests.post(
        BASE_CHANNEL+'/', json={"token": users_data[2]["token"], "channel_id": ch_id})

    assert response.status_code == 404

    response = requests.post(
        BASE_CHANNEL+'/leaving', json={"token": users_data[2]["token"], "channel_id": ch_id})

    assert response.status_code == 404

    # send with wrong method
    response = requests.get(
        URL_LEAVE, json={"token": users_data[2]["token"], "channel_id": ch_id})

    assert response.status_code == 405
def test_basic_reset():
    '''
    Send a variety of data to the server, then reset and confirm that all the data has been cleared.
    - Register users -> user_data
    - Create channel with owner -> all_channels
    - Send a message -> message_data
    - Start a standup -> standup_list
    Confirm that all these datasets are free
    '''
    # reset workspace
    response = requests.post(URL_RESET)

    assert response.json() == {}

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel with user[0] as the owner
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # send a invite request to user[2]
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # send a message as the owner
    send_3_messages(users_data[0]["token"], ch_id)

    token_ = users_data[0]["token"]

    # start a standup, lasting for 30 seconds maximum
    requests.post(URL_STNDUP_START, json={"token": users_data[0]["token"],
                  "channel_id": ch_id, "length": 30})

    # send a standup message
    requests.post(URL_STNDUP_START, json={"token": token_,
                  "channel_id": ch_id, "length": 5})
    
    # reset the workspace
    requests.post(URL_RESET)

    assert response.json() == {}
def test_route_name():
    '''
    This tests for inclusivity of '/' in the route url.
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # invite user to channel
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # send a leave request
    response = requests.post(
        URL_LEAVE+'/', json={"token": users_data[2]["token"], "channel_id": ch_id})

    assert response.status_code == 404
def test_basic():
    '''
    This is a sanity test for correct output based on all-correct input.
    Input = Correct token of owner, u_id of invitee and channel_id of owner.
    Expected Output = {} with no errors.
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # send a invite request
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # add a user[2] as an owner
    ok_ = common_set.add_user_owner(
        users_data[0]["token"], ch_id, users_data[2]["u_id"])

    assert ok_ == {}

    # send requeust to remove owner
    payload = requests.post(URL_REMOWNER, json={
        "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]}).json()

    # confirm output
    assert payload == {}

    token_ = users_data[0]["token"]

    # confirm that user[2] is no longer in owner_members
    payload = requests.get(
        URL_DETAILS + f'?token={token_}&channel_id={ch_id}').json()

    assert users_data[2]["u_id"] not in payload["owner_members"]
def test_basic():
    '''
    Test correct input -> output
    '''
    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # invite user to channel
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # send a leave request
    payload = requests.post(
        URL_LEAVE, json={"token": users_data[2]["token"], "channel_id": ch_id})

    # confirm output
    assert payload.json() == {}
def test_bad_data_leave():
    '''
    1. Sends token of a non-member.
    2. Sends an invalid channel id.
    '''

    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # create a channel
    ch_id = common_set.create_channel_99(users_data[0]["token"])

    # invite 2 people
    invite_user_channel(
        users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE)

    # send invalid token
    response = requests.post(
        URL_LEAVE, json={"token": users_data[1]["token"], "channel_id": ch_id})

    assert response.status_code == 400

    # send invalid ch_id with ownr, which should result in bad request
    response = requests.post(URL_LEAVE, json={"token": users_data[0]["token"],
                                              "channel_id": 124124})

    assert response.status_code == 400

    # send invalid ch_id with user[1], which should result in bad request
    response = requests.post(URL_LEAVE, json={"token": users_data[1]["token"],
                                              "channel_id": 124124})

    assert response.status_code == 400
Exemple #16
0
def test_basic():
    '''
    This is a sanity test for correct output based on all-correct input.
    Input = Correct token, u_id and permission_id
    Expected Output = {} with no errors.
    '''
    # debug mode
    # pdb.set_trace()

    # reset workspace
    requests.post(URL_RESET)

    # register 3 people, fetch tokens and u_id of the users.
    users_data = common_set.register_3_users()

    # ch_id: owner = token_0; member = token_0, token_2
    # ch_id2: owner = token1; member = token_1
    ch_id = common_set.create_channel_99(users_data[0]["token"])
    data_in = {"token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True}
    ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id']

    token_0 = users_data[0]["token"]
    token_1 = users_data[1]["token"]
    token_2 = users_data[2]["token"]
    invite_user_channel(token_0, ch_id, users_data[2]['u_id'], URL_INVITE)

    # send 3 messages to each channel + 1 extra into channel2
    msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \
        "a"}).json()['message_id']
    msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \
        "b"}).json()['message_id']
    msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \
        "c"}).json()['message_id']
    msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \
        "d"}).json()['message_id']
    msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \
        "e"}).json()['message_id']
    msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \
        "f"}).json()['message_id']

    # react to some messages
    requests.post(URL_MSG_REACT, json={"token": token_0, "message_id": msg1_1, "react_id": 1})
    requests.post(URL_MSG_REACT, json={"token": token_2, "message_id": msg2_1, "react_id": 1})
    requests.post(URL_MSG_REACT, json={"token": token_1, "message_id": msg1_2, "react_id": 1})
    requests.post(URL_MSG_REACT, json={"token": token_2, "message_id": msg1_1, "react_id": 1})

    # unreact to some messages
    requests.post(URL_MSG_UNREACT, json={"token": token_0, "message_id": msg1_1, "react_id": 1})
    requests.post(URL_MSG_UNREACT, json={"token": token_1, "message_id": msg1_2, "react_id": 1})

    # retrieve messages
    payload = requests.get(
        URL_MESSAGES + f"?token={token_0}&channel_id={ch_id}&start=0").json()
    payload2 = requests.get(
        URL_MESSAGES + f"?token={token_1}&channel_id={ch_id2}&start=0").json()


    # confirm output.
    assert payload["messages"][2]["reacts"][0]['u_ids'] == [users_data[2]['u_id']]
    assert payload["messages"][1]["reacts"][0]['u_ids'] == [users_data[2]['u_id']]
    assert payload2["messages"][2]["reacts"][0]['u_ids'] == []