Beispiel #1
0
def test_remove_simple():
    '''
    Test remove with multiple messages
    '''
    reset_data()
    # SETUP
    registered_user = auth_register("*****@*****.**", "123456", "John",
                                    "Smith")
    token = registered_user['token']

    c_id = channel_create(token, "Channel1", 'true')

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    msg1_id = get_message_id(message_list, "Hello world!")
    msg2_id = get_message_id(message_list, "another message")
    # SETUP END

    # Delete both messages one by one
    message_remove(token, msg1_id)
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") is None
    message_remove(token, msg2_id)
    message_list = get_messages(c_id)
    assert find_message(message_list, "another message") is None
Beispiel #2
0
def test_remove_owner():
    '''
    Test remove as an owner of the channel
    '''
    reset_data()
    # SETUP
    registered_user = auth_register("*****@*****.**", "123456", "John",
                                    "Smith")
    first_token = registered_user['token']
    c_id = channel_create(first_token, "Channel1", 'true')

    # Add two messages
    message_send(first_token, c_id, "Hello world!")
    message_list = get_messages(c_id)

    # Login as a new user
    registered_user = auth_register("*****@*****.**", "1password", "Bob",
                                    "Smith")
    token = registered_user['token']
    u_id = registered_user['u_id']

    # Set new user as a channel owner
    channel_join(token, c_id)
    channel_addowner(first_token, c_id, u_id)

    # SETUP END
    msg1_id = get_message_id(message_list, "Hello world!")

    message_remove(token, msg1_id)
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") is None
Beispiel #3
0
def test_message_edit():
    '''
    Test edit as the poster of the message on multiple messages
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    msg1_id = get_message_id(message_list, "Hello world!")
    msg2_id = get_message_id(message_list, "another message")
    # SETUP END

    message_edit(token, msg1_id, "Updated message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Updated message") == "Updated message"
    message_edit(token, msg2_id, "Another update")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Another update") == "Another update"
Beispiel #4
0
def test_remove_admin():
    '''
    Test remove as an admin of the slack
    '''
    reset_data()
    # SETUP
    registered_user = auth_register("*****@*****.**", "123456", "John",
                                    "Smith")
    first_token = registered_user['token']

    c_id = channel_create(first_token, "Channel1", 'true')

    # Add two messages
    message_send(first_token, c_id, "Hello world!")
    message_send(first_token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    # Login as a new user
    registered_user = auth_register("*****@*****.**", "1password", "Bob",
                                    "Smith")
    token = registered_user['token']
    u_id = registered_user['u_id']

    # Set new user as an admin of slack
    admin_userpermission_change(first_token, u_id, 2)
    # SETUP END

    message_list = get_messages(c_id)
    msg1_id = get_message_id(message_list, "Hello world!")
    message_remove(token, msg1_id)
    assert find_message(message_list, "Hello world!") is None
Beispiel #5
0
def test_simple():
    '''
    Test sending multiple messages in different channels
    '''
    reset_data()

    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, 'Channel1', 'true')
    # SETUP END

    # Send message
    message_send(token, c_id, 'Hello world!')
    message_list = get_messages(c_id)
    assert find_message(message_list, 'Hello world!') == 'Hello world!'

    # Send message to a channel that already has a message
    message_send(token, c_id, 'another message')
    message_list = get_messages(c_id)
    assert find_message(message_list, 'Hello world!') == 'Hello world!'
    assert find_message(message_list, 'another message') == 'another message'

    # Send message to another channel
    c2_id = channel_create(token, 'Channel2', 'true')

    # Send message
    message_send(token, c2_id, 'Hello world!')
    message_list = get_messages(c2_id)
    assert find_message(message_list, 'Hello world!') == 'Hello world!'
Beispiel #6
0
def test_edit_notoken():
    '''
    Test edit with an invalid or no token
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    msg1_id = get_message_id(message_list, "Hello world!")
    msg2_id = get_message_id(message_list, "another message")
    # SETUP END

    with pytest.raises(AccessError, match=r"*"):
        message_edit("123", msg1_id, "update")
        message_edit('', msg2_id, "there is no message")
Beispiel #7
0
def test_remove_diffuser():
    '''
    Test remove as a different user in the channel
    '''
    reset_data()
    # SETUP
    registered_user = auth_register("*****@*****.**", "123456", "John",
                                    "Smith")
    token = registered_user['token']

    c_id = channel_create(token, "Channel1", 'true')

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    msg1_id = get_message_id(message_list, "Hello world!")

    # Logout
    auth_logout(token)

    # Login as a new user
    registered_user = auth_register("*****@*****.**", "1password", "Bob",
                                    "Smith")
    token = registered_user['token']

    # SETUP END

    with pytest.raises(AccessError, match=r"*"):
        message_remove(token, msg1_id)
Beispiel #8
0
def test_edit_diffuser():
    '''
    Test edit as a different user
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    msg1_id = get_message_id(message_list, "Hello world!")

    # Logout
    auth_logout(token)

    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    # SETUP END

    with pytest.raises(AccessError, match=r"*"):
        message_edit(token, msg1_id, "update")
Beispiel #9
0
def test_message_edit_empty():
    '''
    Test edit with an empty input, should delete the message
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    msg1_id = get_message_id(message_list, "Hello world!")

    message_edit(token, msg1_id, "")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Updated message") is None
Beispiel #10
0
def test_edit_owner():
    '''
    Test edit as the owner of the channel
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    first_token = registered_user['token']
    c_id = channel_create(first_token, "Channel1", 'true')

    # Add two messages
    message_send(first_token, c_id, "Hello world!")
    message_send(first_token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"

    # Login as a new user
    registered_user = auth_register("*****@*****.**", "1password", "Bob",
                                    "Smith")
    token = registered_user['token']
    u_id = registered_user['u_id']

    # Set new user as a channel owner
    channel_join(token, c_id)
    channel_addowner(first_token, c_id, u_id)

    msg1_id = get_message_id(message_list, "Hello world!")
    msg2_id = get_message_id(message_list, "another message")
    # SETUP END

    message_edit(token, msg1_id, "Updated message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Updated message") == "Updated message"
    message_edit(token, msg2_id, "Another update")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Another update") == "Another update"
Beispiel #11
0
def test_edit_cap():
    '''
    Test edit at the maximum character limit
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"

    msg1_id = get_message_id(message_list, "Hello world!")
    # SETUP END

    message_edit(token, msg1_id, "a" * 999)
    message_list = get_messages(c_id)
    assert 'a' in message_list[0]['message']
Beispiel #12
0
def test_maximum():
    '''
    Test sending a message at the maxmium character limit (1000)
    '''
    reset_data()

    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, 'Channel1', 'true')
    # SETUP END

    message_send(token, c_id, 'a' * 1000)
    message_list = get_messages(c_id)
    assert 'a' in message_list[0]['message']
Beispiel #13
0
def test_edit_longmessage():
    '''
    Test edit when the edit is over the character limit
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_list = get_messages(c_id)

    msg1_id = get_message_id(message_list, "Hello world!")
    long_message = "a" * 1001

    with pytest.raises(ValueError):
        message_edit(token, msg1_id, long_message)
Beispiel #14
0
def test_remove_no_id():
    '''
    Test remove when message_id doesn't exist
    '''
    reset_data()
    # SETUP
    registered_user = auth_register("*****@*****.**", "123456", "John",
                                    "Smith")
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"
    # SETUP END

    with pytest.raises(ValueError, match=r"*"):
        message_remove(token, "123asfawf12")
        message_remove(token, "")
Beispiel #15
0
def test_edit_same():
    '''
    Test edit when the editted message is the same as the original
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world") == "Hello world"

    msg1_id = get_message_id(message_list, "Hello world")
    # SETUP END

    with pytest.raises(ValueError, match=r"*"):
        message_edit(token, msg1_id, "Hello world")
Beispiel #16
0
def test_unreact_already():
    '''
    Test message_unreact when the message already has no react
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']

    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"

    msg1_id = get_message_id(message_list, "Hello world!")
    # SETUP END

    with pytest.raises(ValueError):
        message_unreact(token, msg1_id, 1)
Beispiel #17
0
def test_edit_no_id():
    '''
    Test edit when the message ID is invalid or doesn't exist
    '''
    reset_data()
    # SETUP
    registered_user = auth_register('*****@*****.**', '123456', 'John',
                                    'Smith')
    token = registered_user['token']
    c_id = channel_create(token, "Channel1", 'true')
    # SETUP END

    # Add two messages
    message_send(token, c_id, "Hello world!")
    message_send(token, c_id, "another message")
    message_list = get_messages(c_id)
    assert find_message(message_list, "Hello world!") == "Hello world!"
    assert find_message(message_list, "another message") == "another message"
    # SETUP END

    with pytest.raises(ValueError, match=r"*"):
        message_edit(token, "123asfawf12", "update")
        message_edit(token, "", "there is no message")