示例#1
0
def test_message_unreact():
    helper.reset_data()

    # Set up valid parameters
    token = helper.token_account_1()["token"]
    react_id = 1  # We do not have any way of obtaining a valid react_id atm
    channel_id = helper.get_valid_channel(token)
    message_id = helper.get_valid_message(token, channel_id)
    stub.message_react(token, message_id, react_id)

    # Set up invalid parameters
    invalid_react_id = -1
    invalid_message_id = -1

    # message_id is invalid
    with pytest.raises(validation_helper.ValueError):
        stub.message_unreact(token, invalid_message_id, react_id)

    # react_id is not a valid React ID
    with pytest.raises(validation_helper.ValueError):
        stub.message_unreact(token, invalid_message_id, invalid_react_id)

    # successfully unreact a message
    assert stub.message_unreact(token, message_id, react_id) == {}

    # unreact something you already unreacted
    with pytest.raises(validation_helper.ValueError):
        stub.message_unreact(token, message_id, react_id)
示例#2
0
def test_message_unpin():
    helper.reset_data()

    # Set up valid parameters
    token = helper.token_admin()["token"]
    not_admin = helper.token_account_1()["token"]
    channel_id = helper.get_valid_channel(not_admin)
    message_id = helper.get_valid_message(not_admin, channel_id)
    stub.channel_join(token, channel_id)
    stub.message_pin(token, message_id)

    # Set up invalid parameters
    invalid_message_id = -1

    # message_id is not a valid message
    with pytest.raises(validation_helper.ValueError):
        stub.message_unpin(token, invalid_message_id)

    # Error when the authorised user is not an admin
    with pytest.raises(validation_helper.ValueError):
        stub.message_unpin(not_admin, message_id)

    # Error when the admin is not a member of the channel that the message is within
    with pytest.raises(validation_helper.AccessError):
        stub.channel_leave(token, channel_id)
        stub.message_unpin(channel_id, message_id)
    stub.channel_join(token, channel_id)

    # successfully unpin a message
    assert stub.message_unpin(token, message_id) == {}

    # try and unpin a message again
    with pytest.raises(validation_helper.ValueError):
        stub.message_unpin(token, message_id)
示例#3
0
def test_message_react():
    helper.reset_data()

    # Valid parameters
    token = helper.token_account_1()["token"]
    react_id = 1  # We do not have any way of obtaining a valid react_id atm
    channel_id = helper.get_valid_channel(token)
    message_id = helper.get_valid_message(token, channel_id)

    # Invalid parameters
    invalid_react_id = -1
    invalid_message_id = -1

    # message_id is not a valid message within a channel that the authorised user has joined
    with pytest.raises(validation_helper.ValueError):
        stub.message_react(token, invalid_message_id, react_id)

    # react_id is not a valid React ID
    with pytest.raises(validation_helper.ValueError):
        stub.message_react(token, message_id, invalid_react_id)

    # Successfully react a message
    assert stub.message_react(token, message_id, react_id) == {}

    # Message with ID message_id already contains an active React with ID react_id
    with pytest.raises(validation_helper.ValueError):
        stub.message_react(token, message_id, react_id)
示例#4
0
def test_message_remove():
    helper.reset_data()

    # Valid parameters
    token = helper.token_account_1()["token"]
    channel_id = helper.get_valid_channel(token)
    message_id = helper.get_valid_message(token, channel_id)
    message = "This message was produced by the get_valid_message function."

    # Invalid parameters
    unauthorised_token = helper.token_account_2()["token"]
    stub.channel_leave(unauthorised_token, channel_id)

    # Test that it raises an access erorr if the user is not in the channel
    # to remove a message
    with pytest.raises(validation_helper.AccessError):
        stub.message_remove(unauthorised_token, message_id)

    # Test that it raises an access erorr if the user does not have the proper
    # authority to remove a message
    with pytest.raises(validation_helper.AccessError):
        stub.channel_join(unauthorised_token, channel_id)
        stub.message_remove(unauthorised_token, message_id)

    # Attempt to successfully remove a message
    assert stub.message_remove(token, message_id) == {}

    # Test that it raises an error if trying to remove a already removed message
    with pytest.raises(validation_helper.ValueError):
        stub.message_remove(token, message_id)

    # Test that the message disappears from search
    assert message_id not in stub.search(token, message)
示例#5
0
def test_message_send():
    helper.reset_data()

    # Valid parameters
    token = helper.token_account_1()["token"]
    channel_id = helper.get_valid_channel(token)
    message = "Testing the function message_send."

    # Invalid parameters
    invalid_channel_id = -00000
    invalid_message = message*3000
    unauthorised_token = helper.token_account_2()["token"]

    # Test that it raises an erorr if the channel does not exist
    with pytest.raises(validation_helper.ValueError):
        stub.message_send(token, invalid_channel_id, message)

    # Test that it raises an erorr if the message is >1000 characters
    with pytest.raises(validation_helper.ValueError):
        stub.message_send(token, channel_id, invalid_message)

    # Test that it raises an access erorr if the token is not an authorised user.
    # Note: we assume the second account is not part of the channel. This will fail if the second
    # account is in the channel
    with pytest.raises(validation_helper.AccessError):
        stub.channel_leave(unauthorised_token, channel_id)
        stub.message_send(unauthorised_token, channel_id, message)

    # Test that the function successfully completes with valid parameters
    # (this may require manual verification)
    assert stub.message_send(token, channel_id, message)["message_id"] > -1
示例#6
0
def test_message_edit():
    helper.reset_data()

    # Valid parameters
    token = helper.token_account_1()["token"]
    channel_id = helper.get_valid_channel(token)
    message_id = helper.get_valid_message(token, channel_id)
    message = "This message was edited by the message_edit function."

    # Invalid parameters
    invalid_message = message*3000
    invalid_message_id = -1
    unauthorised_token = helper.token_account_2()["token"]

    # Test that it raises an error if a user edits a message that is not theirs.
    with pytest.raises(validation_helper.AccessError):
        stub.channel_join(unauthorised_token, channel_id)
        stub.message_edit(unauthorised_token, message_id, message)
    stub.channel_leave(unauthorised_token, channel_id)

    # Test that it raises an error if invalid message_id
    with pytest.raises(validation_helper.ValueError):
        stub.message_edit(token, invalid_message_id, message)

    # Test that it raises an error if it is a invalid message being edited
    with pytest.raises(validation_helper.ValueError):
        stub.message_edit(token, message_id, invalid_message)

    # Attempt to successfully edit a message
    assert stub.message_edit(token, message_id, message) == {}

    # Test that the message is edited in search
    assert stub.search(token, message)["messages"] != []

    # Test that message is deleted if edited with an empty string
    stub.message_edit(token, message_id, "")
    assert stub.channel_messages(token, channel_id, 0)["messages"] == []
示例#7
0
def test_message_sendlater():
    helper.reset_data()

    # Valid parameters
    token = helper.token_account_1()["token"]
    channel_id = helper.get_valid_channel(token)
    message = "Testing the function message_sendlater."
    time_sent = helper.in_one_second()

    # Invalid parameters
    unauthorised_token = helper.token_account_2()["token"]
    invalid_channel_id = -00000
    invalid_message = message*3000
    invalid_time_sent = datetime(2018, 12, 12)
    stub.channel_leave(unauthorised_token, channel_id)

    # Test that it raises a error if the channel does not exist
    with pytest.raises(validation_helper.ValueError):
        stub.message_sendlater(token, invalid_channel_id, message, time_sent)

    # Test that it raises an error if the message is >1000 characters
    with pytest.raises(validation_helper.ValueError):
        stub.message_sendlater(token, channel_id, invalid_message, time_sent)

    # Test that it raises an error if the time sent is a time in the past
    with pytest.raises(validation_helper.ValueError):
        stub.message_sendlater(token, channel_id, message, invalid_time_sent)

    # Test that it raises an access error if the token is not an authorised user
    with pytest.raises(validation_helper.AccessError):
        stub.message_sendlater(unauthorised_token, channel_id, message, time_sent)

    # Test that the function successfully completes with valid parameters
    # (this may require manual verification)
    message_id = stub.message_sendlater(token, channel_id, message, time_sent)["message_id"]
    assert message_id > -1