Esempio n. 1
0
def test_invalid_react_id():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    react_id = 0

    with pytest.raises(ValueError, match=r'Invalid react_id') as excinfo:
        message_react(setupDict['token'], message_id['message_id'], react_id)
    assert excinfo.type == ValueError
Esempio n. 2
0
def test_message_unreact():
    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']

    # SETUP END

    # The right example

    # Assume reactid 1 is valid
    message_react(token1, message_id1, 1)
    assert message_unreact(token1, message_id1, 1) == {}


    message_react(token1, message_id1, 1)
    with pytest.raises(ValueError):
        # assume message_id 2 is not a valid message
        message_unreact(token1, 10, 1)

    with pytest.raises(ValueError):
        # assume react_id 3 is not a valid React ID
        message_unreact(token1, message_id1, 3)

    with pytest.raises(ValueError):
        # message_id1 does not contain an active React with react_id 4
        message_unreact(token1, message_id1, 4)


    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
    reset_data()
Esempio n. 3
0
def test_invalid_token_unreact():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    react_id = 1
    message_react(setupDict['token'], message_id['message_id'], 1)
    auth_logout(setupDict['token'])
    with pytest.raises(AccessError,
                       match=r'User is not a valid user') as excinfo:
        message_unreact(setupDict['token'], message_id['message_id'], react_id)
    assert excinfo.type == AccessError
Esempio n. 4
0
def test_already_reacted():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    react_id = 1
    message_react(setupDict['token'], message_id['message_id'], react_id)
    message = get_message_from_m_id(message_id['message_id'])
    reacts = message.get_reacts()
    assert setupDict['u_id'] in reacts[0].get_uids()

    with pytest.raises(ValueError,
                       match=r'Already contains an active react') as excinfo:
        message_react(setupDict['token'], message_id['message_id'], react_id)
    assert excinfo.type == ValueError
Esempio n. 5
0
def test_standard_unreact():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    react_id = 1
    message_react(setupDict['token'], message_id['message_id'], react_id)
    message = get_message_from_m_id(message_id['message_id'])
    reacts = message.get_reacts()

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

    message_unreact(userDict['token'], message_id['message_id'], react_id)
    assert userDict['u_id'] not in reacts[0].get_uids()
Esempio n. 6
0
def test_react_not_in_channel():
    global my_users
    setupDict = setup()
    userDict = auth_register("*****@*****.**", "password", "Student", "Citizen")
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    react_id = 1
    message_react(setupDict['token'], message_id['message_id'], react_id)
    message = get_message_from_m_id(message_id['message_id'])
    reacts = message.get_reacts()
    assert setupDict['u_id'] in reacts[0].get_uids()

    with pytest.raises(
            ValueError,
            match=r'Invalid message_id with in the user joined channel'
    ) as excinfo:
        message_react(userDict['token'], message_id['message_id'], react_id)
    assert excinfo.type == ValueError
def run_message_react():
    """
    Run the message_react function to react a message and
    add it to the server database
    """
    request_data = request.form
    return_value = message.message_react(request_data["token"],
                                         int(request_data["message_id"]),
                                         int(request_data["react_id"]))

    return dumps(return_value)
Esempio n. 8
0
def react_message():
    token = request.form.get('token')
    message_id = request.form.get('message_id')
    react_id = request.form.get('react_id')

    try:
        react = message_react(token, int(message_id), int(react_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. 9
0
def react():
    token = get_args('token')
    message_id = int(get_args('message_id'))
    react_id = int(get_args('react_id'))
    return dumps(message_react(token, message_id, react_id))