示例#1
0
def test_message_edit():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "321654", "Frank", "Li")
    user_info3 = register("*****@*****.**", "456789", "Frank", "Li")
    create(user_info1['token'], 'lol', True)
    invite(user_info1['token'], 0, user_info2['u_id'])
    send(user_info2['token'], 0, "first message")

    edit(user_info1['token'], 0, "new first message")
    data = getData()
    assert (data['messages'][0]['message'] == "new first message")

    edit(user_info2['token'], 0, "second new first message")
    data = getData()
    assert (data['messages'][0]['message'] == "second new first message")

    # a normal member who doesn't send message wants to edit it
    with pytest.raises(AccessError):
        edit(user_info3['token'], 0, "not possible")

    # a member in channel but not the owner who doesn't send message wants to edit it
    invite(user_info1['token'], 0, user_info3['u_id'])
    with pytest.raises(AccessError):
        edit(user_info3['token'], 0, "not possible")

    # now member 3 is a admin
    data = getData()
    data['users'][2]['permission'] = 2
    edit(user_info1['token'], 0, "final message")
    data = getData()
    assert (data['messages'][0]['message'] == "final message")
    save(clear_data())
示例#2
0
def test_message_react():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    react(user_info1['token'], 0, 1)

    data = getData()
    assert len(data['messages'][0]['reacts'][0]['u_ids']) == 1

    # sencond user create a channel and send a msg
    create(user_info2['token'], 'lol', True)
    send(user_info2['token'], 1, "second message")

    data = getData()
    assert len(data['messages']) == 2

    # Not a valid message within a channel that the authorised user has joined
    with pytest.raises(Value_Error):
        react(user_info1['token'], 1, 1)

    # Not a valid react_id
    with pytest.raises(Value_Error):
        react(user_info2['token'], 1, 0)

    # Message already contains active react with same react_id
    react(user_info2['token'], 1, 1)
    data = getData()
    assert len(data['messages'][1]['reacts'][0]['u_ids']) == 1

    with pytest.raises(Value_Error):
        react(user_info2['token'], 1, 1)

    save(clear_data())
示例#3
0
def test_search():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    send(user_info1['token'], 0, "second message")

    messages = search(user_info1['token'], 'mess')
    assert len(messages['messages']) == 2

    messages = search(user_info1['token'], 'p')
    assert len(messages['messages']) == 0

    messages = search(user_info1['token'], '')
    assert len(messages['messages']) == 0

    messages = search(user_info1['token'], 'second')
    assert len(messages['messages']) == 1

    save(clear_data())
示例#4
0
def test_channel_messages():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    send(user_info1['token'], 0, "second message")

    channel_message = messages(user_info1['token'], 0, 0)
    assert (len(channel_message['messages'])
            == 2) and (channel_message['start'] == 0
                       and channel_message['end'] == -1)

    channel_message = messages(user_info1['token'], 0, 1)
    assert (len(channel_message['messages'])
            == 1) and (channel_message['start'] == 1
                       and channel_message['end'] == -1)

    edit(user_info1['token'], 0, '')
    channel_message = messages(user_info1['token'], 0, 0)
    assert (len(channel_message['messages'])
            == 1) and (channel_message['start'] == 0
                       and channel_message['end'] == -1)

    # start is greater than or equal to the total number of messages in the channel
    with pytest.raises(Value_Error):
        channel_message = messages(user_info1['token'], 0, 2)

    # Channel ID: is not a valid channel
    with pytest.raises(Value_Error):
        channel_message = messages(user_info1['token'], 1, 0)

    # Authorised user is not a member of channel with channel_id
    with pytest.raises(AccessError):
        channel_message = messages(user_info2['token'], 0, 0)

    save(clear_data())
示例#5
0
def test_message_unpin():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    pin(user_info1['token'], 0)
    unpin(user_info1['token'], 0)
    data = getData()
    assert data['messages'][0]['is_pinned'] == False

    # Message_Id is not a valid message
    with pytest.raises(Value_Error):
        unpin(user_info1['token'], 1)

    # Message with ID message_id already pinned
    with pytest.raises(Value_Error):
        unpin(user_info1['token'], 0)

# The user is not an admin
    with pytest.raises(Value_Error):
        unpin(user_info2['token'], 0)

    save(clear_data())

    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info2['token'], 'lol', True)
    send(user_info2['token'], 0, "first message")

    # The authorised user is not a member of the channel that the message is within
    with pytest.raises(AccessError):
        unpin(user_info1['token'], 0)

    save(clear_data())
示例#6
0
def test_message_send():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")

    data = getData()
    assert data['messages'][0]['message'] == "first message"

    send(user_info1['token'], 0, "second message")
    data = getData()
    assert len(data['messages']) == 2

    # Message is more than 1000 characters
    with pytest.raises(Value_Error):
        send(user_info1['token'], 0, "second message" * 500)

    # the authorised user has not joined the channel they are trying to post to
    with pytest.raises(AccessError):
        send(user_info2['token'], 0, "second message")

    save(clear_data())
示例#7
0
def test_message_unreact():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message in first channel")
    react(user_info1['token'], 0, 1)

    data = getData()
    assert len(data['messages'][0]['reacts'][0]['u_ids']) == 1

    # sencond user create a channel and send a msg and react by itself
    create(user_info2['token'], 'lol', True)
    send(user_info2['token'], 1, "first message in second channel")
    react(user_info2['token'], 1, 1)

    data = getData()
    assert len(data['messages']) == 2

    # Not a valid message within a channel that the authorised user has joined
    with pytest.raises(Value_Error):
        unreact(user_info1['token'], 1, 1)

    # Not a valid react_id
    with pytest.raises(Value_Error):
        unreact(user_info2['token'], 1, 0)

    # Message with ID message_id does not contain an active React with ID react_id
    send(user_info2['token'], 1, "third message")
    data = getData()
    assert len(data['messages'][2]['reacts'][0]['u_ids']) == 0

    with pytest.raises(Value_Error):
        unreact(user_info2['token'], 2, 1)

    # pass test
    unreact(user_info2['token'], 1, 1)
    data = getData()
    assert len(data['messages'][1]['reacts'][0]['u_ids']) == 0

    save(clear_data())
示例#8
0
def test_message_remove():
    user_info1 = register("*****@*****.**", "12345678", "minglang", "xie")
    user_info2 = register("*****@*****.**", "12345678", "minglang",
                          "xie")
    create(user_info1['token'], 'lol', True)
    send(user_info1['token'], 0, "first message")
    remove(user_info1['token'], 0)

    data = getData()
    assert len(data['messages']) == 0

    # Message (based on ID) no longer exists
    send(user_info1['token'], 0, "first message")
    remove(user_info1['token'], 0)
    with pytest.raises(Value_Error):
        remove(user_info1['token'], 0)

    # Message with message_id was not sent by the authorised user making this request and The authorised user is not an admin or owner of this channel or the slackr
    send(user_info1['token'], 0, "first message")
    with pytest.raises(Value_Error):
        remove(user_info2['token'], 0)

    save(clear_data())
示例#9
0
def message_send():
    """ return messag _id """
    result = send(request.form.get('token'),
                  int(request.form.get('channel_id')),
                  request.form.get('message'))
    return dumps(result)