Esempio n. 1
0
def test_message_unpin():
    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']
    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)

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

    messagedic2 = message_send(token1, channel_id1, "helloooo")
    message_id2 = messagedic2['message_id']

    message_pin(token1, message_id1)
    message_pin(token1, message_id2)
    # SETUP END

    # The right example
    assert message_unpin(token1, message_id1) == {}

    with pytest.raises(ValueError):
        # message_id 8 is not a valid message
        message_unpin(token1, 8)

    with pytest.raises(ValueError):
        # The authorised user token2 is not an admin
        message_unpin(token2, message_id2)

    with pytest.raises(ValueError):
        # Message message_1 is already unpinned
        message_unpin(token1, message_id1)

    with pytest.raises(AccessError):
        # The authorised user is not a member of the channel that the message is within
        message_unpin(token3, message_id2)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
    reset_data()
Esempio n. 2
0
def test_standard_pin():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    message_pin(setupDict['token'], message_id['message_id'])
    message = get_message_from_m_id(message_id['message_id'])

    assert message.is_pinned == True
Esempio n. 3
0
def test_invalid_token_pin():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    message_pin(setupDict['token'], message_id['message_id'])
    auth_logout(setupDict['token'])
    with pytest.raises(AccessError,
                       match=r'User is not a valid user') as excinfo:
        message_pin(setupDict['token'], message_id['message_id'])
    assert excinfo.type == AccessError
Esempio n. 4
0
def test_already_pinned():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    message_pin(setupDict['token'], message_id['message_id'])

    with pytest.raises(ValueError,
                       match=r'Message is already pinned') as excinfo:
        message_pin(setupDict['token'], message_id['message_id'])
    assert excinfo.type == ValueError
Esempio n. 5
0
def test_invalid_message_id_pin():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")

    with pytest.raises(ValueError, match=r'Message no long exist') as excinfo:
        message_pin(setupDict['token'], "123")
    assert excinfo.type == ValueError

    message = get_message_from_m_id(message_id['message_id'])
    assert message.is_pinned == False
Esempio n. 6
0
def test_unauthorized():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")

    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')

    with pytest.raises(
            AccessError,
            match=r'User is not a member of the channel') as excinfo:
        message_pin(userDict['token'], message_id['message_id'])
    assert excinfo.type == AccessError

    message = get_message_from_m_id(message_id['message_id'])
    assert message.is_pinned == False
Esempio n. 7
0
def test_not_admin_pin():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")

    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')
    channel_invite(setupDict['token'], setupDict['channel_id'],
                   userDict['u_id'])

    with pytest.raises(ValueError,
                       match=r'The user is not an admin') as excinfo:
        message_pin(userDict['token'], message_id['message_id'])
    assert excinfo.type == ValueError

    message = get_message_from_m_id(message_id['message_id'])
    assert message.is_pinned == False
def run_message_pin():
    """
    Run the message_react function to react a message and
    add it to the server database
    """
    request_data = request.form
    return_value = message.message_pin(request_data["token"],
                                       int(request_data["message_id"]))

    return dumps(return_value)
Esempio n. 9
0
def pin_message():
    token = request.form.get('token')
    message_id = request.form.get('message_id')

    try:
        pin = message_pin(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)
Esempio n. 10
0
def pin():
    token = get_args('token')
    message_id = int(get_args('message_id'))
    return dumps(message_pin(token, message_id))