예제 #1
0
def test_removing_invalid_messages(new_channel_and_user):
    """ Tests that removing a message with an invalid message id throws an input error"""
    with pytest.raises(InputError):
        assert message_remove(new_channel_and_user['token'], 0)
    with pytest.raises(InputError):
        assert message_remove(new_channel_and_user['token'], -1)
    with pytest.raises(InputError):
        assert message_remove(new_channel_and_user['token'], 50)
예제 #2
0
def test_removing_message_as_owner(new_channel_and_user):
    ''' tests the sucessful removal of a message by the channel owner'''
    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_remove(new_channel_and_user['token'], message['message_id'])
예제 #3
0
def test_removing_authored_message(new_channel_and_user):
    """ Tests the successful removal 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_remove(author['token'], message['message_id'])
예제 #4
0
def test_removing_a_message_unauthorized_user(new_channel_and_user):
    """Tests that an error is thrown when the user is not authorised to remove 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_remove(unauthorized_user['token'],
                              message['message_id'])
예제 #5
0
def test_removing_a_message_neither_author_nor_owner(new_channel_and_user):
    """Tests that an error is thrown when the user is not authorised to remove 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_remove(not_author['token'], message['message_id'])
예제 #6
0
def message_remove_wsgi():
    json = request.get_json()
    return jsonify(message_remove(json['token'], int(json['message_id'])))
예제 #7
0
def test_removing_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_remove('invalid token', message['message_id'])