Example #1
0
def test_editing_with_invalid_token(new_channel_and_user):
    """ Tests that an access error is thrown when an an invalid token is used """
    message = message_send(new_channel_and_user['token'],
                           new_channel_and_user['channel_id'], 'a')
    with pytest.raises(AccessError):
        message_edit('invalid token', message['message_id'],
                     'new message to replace existing message')
Example #2
0
def test_editing_authored_message(new_channel_and_user):
    """ Tests the successful edit of a message from a user that sent it"""
    author = auth_register("*****@*****.**", "password", "first_name1",
                           "last_name1")
    channel_invite(new_channel_and_user['token'],
                   new_channel_and_user['channel_id'], author['u_id'])
    message = message_send(author['token'], new_channel_and_user['channel_id'],
                           'a')
    message_edit(author['token'], message['message_id'],
                 'new message to replace existing message')
Example #3
0
def test_editing_authored_message_with_empty_message(new_channel_and_user):
    """ Tests replacing a message with an empty message removes the messages"""
    author = auth_register("*****@*****.**", "password", "first_name1",
                           "last_name1")
    channel_invite(new_channel_and_user['token'],
                   new_channel_and_user['channel_id'], author['u_id'])
    message = message_send(author['token'], new_channel_and_user['channel_id'],
                           'a')
    message_edit(author['token'], message['message_id'], '')
    with pytest.raises(InputError):
        message_edit(author['token'], message['message_id'], '')
Example #4
0
def test_editing_invalid_messages(new_channel_and_user):
    """ Tests that editing a message with an invalid message id throws an input error"""
    with pytest.raises(InputError):
        assert message_edit(new_channel_and_user['token'], 0,
                            'new message to replace existing message')
    with pytest.raises(InputError):
        assert message_edit(new_channel_and_user['token'], -1,
                            'new message to replace existing message')
    with pytest.raises(InputError):
        assert message_edit(new_channel_and_user['token'], 50,
                            'new message to replace existing message')
Example #5
0
def test_editing_a_message_unauthorized_user(new_channel_and_user):
    """Tests that an error is thrown when the user is not authorised to edit the message
        A user is not authorised if they are not authorised to see the channel
    """
    message = message_send(new_channel_and_user['token'],
                           new_channel_and_user['channel_id'], 'a')
    unauthorized_user = auth_register("*****@*****.**", "password",
                                      "first_name1", "last_name1")

    with pytest.raises(AccessError):
        assert message_edit(unauthorized_user['token'], message['message_id'],
                            'new message to replace existing message')
Example #6
0
def test_editing_a_message_neither_author_nor_owner(new_channel_and_user):
    """Tests that an error is thrown when the user is not authorised to edit the message
        A user is not authorised if they are
             i not the author of the message and
            ii: not an admin/owner of the chat
    """
    not_author = auth_register("*****@*****.**", "password",
                               "first_name1", "last_name1")
    message = message_send(new_channel_and_user['token'],
                           new_channel_and_user['channel_id'], 'a')
    channel_invite(new_channel_and_user['token'],
                   new_channel_and_user['channel_id'], not_author['u_id'])

    with pytest.raises(AccessError):
        assert message_edit(not_author['token'], message['message_id'],
                            'new message to replace existing message')
Example #7
0
def message_edit_wsgi():
    json = request.get_json()
    return jsonify(
        message_edit(json['token'], int(json['message_id']), json['message']))