Exemplo n.º 1
0
def test_search():
    '''
    assumption:
        [email protected] is the only registered email for now.
        2.all the value errors have been modified into specfic words.
        3.the channel called "channelname" hasn't been created
    '''

    #successful test:
    #login
    reset_data()
    auth_register('*****@*****.**', 'q1w2e3r4', 'BEAR', 'XI')
    login1_dic = auth_login('*****@*****.**', 'q1w2e3r4')
    token = login1_dic['token']
    #create a channel
    channelValue = channels_create(token, "channelname", True)
    channel_id = channelValue['channel_id']
    #sending a message
    message_send(token, channel_id, "1q2w3e4r")
    #search
    messages_dic = search(token, "1q")
    assert messages_dic['messages'][0]['message'] == "1q2w3e4r"
    #logout
    auth_logout(token)
    reset_data()
Exemplo n.º 2
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()
Exemplo n.º 3
0
def test_long_message():
    global my_users
    setupDict = setup()
    message = "A" * 1001

    with pytest.raises(ValueError) as excinfo:
        message_send(setupDict['token'], setupDict['channel_id'], message)
    assert excinfo.type == ValueError
Exemplo n.º 4
0
def test_user_not_in_channel():
    global send_later
    setupDict = setup()
    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')
    message = "Hello world"

    with pytest.raises(AccessError) as excinfo:
        message_send(userDict['token'], setupDict['channel_id'], message)

    assert excinfo.type == AccessError
Exemplo n.º 5
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']
Exemplo n.º 6
0
def test_channel_messages():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    # SETUP END

    # successful test
    # assume the total number of messages in the channel is 0
    # which means there is no message in the channel
    # assume the start number is 0

    # send a message to channel1
    message_send(token1, channel_id1, "hello")
    channel_messages(token1, channel_id1, 0)

    # error test
    with pytest.raises(ValueError):
        # Channel (based on ID) does not exist
        # assume the channel ID 2 does not exist
        channel_messages(token1, 10, 0)

    with pytest.raises(ValueError):
        # start is greater than the total number of messages in the channel
        # the total number of messages is 1, start is 2
        channel_messages(token1, channel_id1, 2)

    with pytest.raises(AccessError):
        # Authorised user is not a member of channel with channel_id
        channel_messages(token2, channel_id1, 0)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    reset_data()
Exemplo n.º 7
0
def test_message_edit():
    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 the message id 1 is a valid id for user1
    assert message_edit(token1, message_id1, 'hello') == {}

    with pytest.raises(ValueError):
        # Assume Message id 2 does not exist
        message_edit(token1, 10, 'hello')

    with pytest.raises(ValueError):
        # Message is more than 1000 characters
        message_edit(token1, message_id1, 'a' * 1001)

    with pytest.raises(AccessError):
        # message_id1 was not sent by the authorised user token2 making this request
        message_edit(token2, message_id1, 'hello')

    with pytest.raises(AccessError):
        # token3 is not an owner of this channel
        message_edit(token3, message_id1, 'hello')

    with pytest.raises(AccessError):
        # token4 is not an admin or owner of the slack
        message_edit(token4, message_id1, 'hello')

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
    reset_data()
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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']
Exemplo n.º 11
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
Exemplo n.º 12
0
def test_invalid_token():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              'A new message')
    auth_logout(setupDict['token'])
    with pytest.raises(AccessError,
                       match=r'User is not a valid user') as excinfo:
        message_edit(setupDict['token'], message_id['message_id'], "Hello")
    assert excinfo.type == AccessError
Exemplo n.º 13
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
Exemplo n.º 14
0
def run_message_send():
    """
    Run the message_send function to send a message and
    add it to the  server database
    """
    request_data = request.form
    return_value = message.message_send(request_data["token"],
                                        int(request_data["channel_id"]),
                                        request_data["message"])

    return dumps(return_value)
Exemplo n.º 15
0
def test_message_react():
    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
    # message_id1 is a valid message for user1
    # assume the react id 1 is a valid id
    assert message_react(token1, message_id1, 1) == {}

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

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

    with pytest.raises(ValueError):
        # message_id 1 already contains an active React with react_id 1
        message_react(token1, message_id1, 1)

    with pytest.raises(ValueError):
        # user3 is not a member of channel which contain messageid1
        message_react(token3, message_id1, 1)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
0
def test_normal():
    global my_users
    setupDict = setup()
    message = 'A new message'
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              message)

    reply = channel_messages(setupDict['token'], setupDict['channel_id'],
                             0)  # dictionary
    reply_messages = reply['messages']  #list
    first_message = reply_messages[0]  #dictionary
    assert first_message['message'] == message
Exemplo n.º 19
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
Exemplo n.º 20
0
def test_message_send():
    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']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']
    channelidDict2 = channels_create(token2, 'channel_8', True)
    channel_id2 = channelidDict2['channel_id']
    # SETUP END

    # The right example
    message_send(token1, channel_id1, 'hello')

    # error test
    with pytest.raises(ValueError):
        # Message is more than 1000 characters
        message_send(token1, channel_id1, 'a' * 1001)

    with pytest.raises(AccessError):
        # token1 has not joined Channel channel_id2
        message_send(token1, channel_id2, 'hello')

    # logout
    auth_logout(token1)
    auth_logout(token2)
    reset_data()
Exemplo n.º 21
0
def test_standard_edit():
    global my_users
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              'A new message')

    message_edit(setupDict['token'], message_id['message_id'], "Hello")
    start = 0
    reply = channel_messages(setupDict['token'], setupDict['channel_id'],
                             start)  # dictionary
    reply_messages = reply['messages']  #list
    first_message = reply_messages[0]  #dictionary
    assert first_message['message'] == "Hello"
Exemplo n.º 22
0
def test_not_owner_or_poster():
    global my_users
    setupDict = setup()
    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')
    channel_invite(setupDict['token'], setupDict['channel_id'],
                   userDict['u_id'])
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              'A new message')

    with pytest.raises(AccessError,
                       match=r'Not authorized user of message') as excinfo:
        message_edit(userDict['token'], message_id['message_id'], "Hello")
    assert excinfo.type == AccessError
Exemplo n.º 23
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
Exemplo n.º 24
0
def send_message():

    token = request.form.get('token')
    channel_id = request.form.get('channel_id')
    message = request.form.get('message')

    try:
        sending = message_send(token, channel_id, message)
        return sendSuccess({
            'message_id' : sending['message_id']
        })
    except ValueError as e:
        return sendError(400, "ValueError", e.args)
    except AccessError as e:
        return sendError(401, "AccessError", a.args)
Exemplo n.º 25
0
def test_invalid_token_unpin():
    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'])
    auth_logout(setupDict['token'])
    with pytest.raises(AccessError,
                       match=r'User is not a valid user') as excinfo:
        message_unpin(setupDict['token'], message_id['message_id'])
    assert excinfo.type == AccessError

    assert message.is_pinned == True
Exemplo n.º 26
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
Exemplo n.º 27
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()
Exemplo n.º 28
0
def test_message_creator():
    global my_users
    setupDict = setup()
    auth_register("*****@*****.**", "password", "Student", "Citizen")
    userDict = auth_login("*****@*****.**", 'password')
    channel_invite(setupDict['token'], setupDict['channel_id'],
                   userDict['u_id'])
    message_id = message_send(userDict['token'], setupDict['channel_id'],
                              'A new message')

    message_edit(userDict['token'], message_id['message_id'], "Hello")
    start = 0
    reply = channel_messages(setupDict['token'], setupDict['channel_id'],
                             start)  # dictionary
    reply_messages = reply['messages']  #list
    first_message = reply_messages[0]  #dictionary

    assert first_message['message'] == "Hello"
Exemplo n.º 29
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
Exemplo n.º 30
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