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

    with pytest.raises(ValueError,
                       match=r'Does not contain an active react') as excinfo:
        message_unreact(setupDict['token'], message_id['message_id'], react_id)
    assert excinfo.type == ValueError
Ejemplo n.º 2
0
def test_invalid_unreact_id():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              "Hello")
    react_id = 0
    message_react(setupDict['token'], message_id['message_id'], 1)

    with pytest.raises(ValueError, match=r'Invalid react_id') as excinfo:
        message_unreact(setupDict['token'], message_id['message_id'], react_id)
    assert excinfo.type == ValueError
Ejemplo 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
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
def run_message_unreact():
    """
    Run the message_react function to react a message and
    add it to the server database
    """
    request_data = request.form
    return_value = message.message_unreact(request_data["token"],
                                           int(request_data["message_id"]),
                                           int(request_data["react_id"]))

    return dumps(return_value)
Ejemplo n.º 6
0
def unreact_message():
    token = request.form.get('token')
    message_id = request.form.get('message_id')
    react_id = request.form.get('react_id')

    try:
        unreact = message_unreact(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)
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
def unreact():
    token = get_args('token')
    message_id = int(get_args('message_id'))
    react_id = int(get_args('react_id'))
    return dumps(message_unreact(token, message_id, react_id))