Beispiel #1
0
def test_invalid_message():
    global send_later
    setupDict = setup()
    message = message_send(setupDict['token'], setupDict['channel_id'],
                           'A new message')
    message_remove(setupDict['token'], message['message_id'])
    with pytest.raises(ValueError) as excinfo:
        message_remove(setupDict['token'], message['message_id'])
    assert excinfo.type == ValueError
Beispiel #2
0
def test_unauthorized_user():
    global send_later
    setupDict = setup()
    message = message_send(setupDict['token'], setupDict['channel_id'],
                           'A new message')
    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')

    with pytest.raises(AccessError,
                       match=r'Not authorized user of message') as excinfo:
        message_remove(userDict['token'], message['message_id'])
    assert excinfo.type == AccessError
Beispiel #3
0
def test_standard_remove():
    global send_later
    setupDict = setup()
    message_send(setupDict['token'], setupDict['channel_id'], 'hello')
    message = message_send(setupDict['token'], setupDict['channel_id'],
                           'A new message')
    message_remove(setupDict['token'], message['message_id'])
    start = 0
    reply = channel_messages(setupDict['token'], setupDict['channel_id'],
                             start)  # dictionary
    reply_messages = reply['messages']  #list
    for messageDict in reply_messages:
        assert message['message_id'] != messageDict['message_id']
Beispiel #4
0
def test_message_creator_remove():
    global send_later
    setupDict = setup()
    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')
    channel_invite(setupDict['token'], setupDict['channel_id'],
                   userDict['u_id'])
    message_send(setupDict['token'], setupDict['channel_id'], 'hello')
    message = message_send(userDict['token'], setupDict['channel_id'],
                           'A new message')
    message_remove(userDict['token'], message['message_id'])

    start = 0
    reply = channel_messages(setupDict['token'], setupDict['channel_id'],
                             start)  # dictionary
    reply_messages = reply['messages']  #list
    for messageDict in reply_messages:
        assert message['message_id'] != messageDict['message_id']
def run_message_remove():
    """
    Run the message_remove function to remove a message and
    update the server database
    """
    request_data = request.form
    return_value = message.message_remove(request_data["token"],
                                          int(request_data["message_id"]))

    return dumps(return_value)
Beispiel #6
0
def remove_message():

    token = request.form.get('token')
    message_id = request.form.get('message_id')

    try:
        remove = message_remove(token, int(message_id))
        return sendSuccess({})

    except ValueError as e:
        return sendError(400, "ValueError", e.args)
    except AccessError as a:
        return sendError(401, "AccessError", a.args)
Beispiel #7
0
def test_message_remove():
    reset_data()

    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']
    uid2 = authRegisterDict2['u_id']
    authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith')
    auth_login('*****@*****.**', '123456')
    token3 = authRegisterDict3['token']
    authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis')
    auth_login('*****@*****.**', '123456')
    token4 = authRegisterDict4['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']

    channel_join(token2, channel_id1)
    channel_addowner(token1, channel_id1, uid2)

    channel_join(token3, channel_id1)

    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id = messages_dic1['message_id']

    # SETUP END

    # The right example
    # the message_id is a valid message for user1
    assert message_remove(token1, message_id) == {}

    # send again
    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id = messages_dic1['message_id']
    # the right example
    # Message_id was not sent by the authorised user token2,
    # but the token2 is a owner of this channel
    assert message_remove(token2, message_id) == {}

    # send again
    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id = messages_dic1['message_id']
    with pytest.raises(ValueError):
        # assume Message id 2 no longer exists
        message_remove(token1, 10)

    with pytest.raises(AccessError):
        # assume token3 is not an owner of this channel that contain message_id
        message_remove(token3, message_id)

    with pytest.raises(AccessError):
        # assume token4 is not an admin or owner of the slack
        message_remove(token4, message_id)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
Beispiel #8
0
def remove():
    token = get_args('token')
    message_id = int(get_args('message_id'))
    return dumps(message_remove(token, message_id))