def test_delete_note(session, user, note):
    before_delete = session.query(Note).filter(Note.owner_id == user.id).count()
    delete_note(session, note.id, user)
    after_delete = session.query(Note).filter(Note.owner_id == user.id).count()

    assert (
        before_delete > after_delete
    ), "Delete should reduce the number of notes in the database."
    assert (
        before_delete == after_delete + 1
    ), "There should be exactly one less note in the database"
Exemple #2
0
def standart_message(message: telebot.types.Message) -> None:
    """Добавление/изменение сообщения"""

    if message.reply_to_message is not None:
        database.update_note(message.text, message.reply_to_message.message_id)
    elif message.text[0].isdigit():
        database.delete_note(int(message.text[0]))
    else:
        database.insert_note(message.text, message.message_id)

    _send_message(message.chat.id, database.select_notes(),
                  keyboard.delete_key())
def delete_note():
    json = util.getJson(request)

    user = database.get_user_object_from_token(json["token"])

    if user:
        if database.delete_note(json["noteid"], user.ID):
            return JSON.dumps(util.makeResponseDict(200, "Note deleted"))
        else:
            return JSON.dumps(util.makeResponseDict(403, "Not your note!"))
    else:
        return JSON.dumps(util.makeResponseDict(403, "Bad credentials!"))
Exemple #4
0
def delete_note(uuid):
    """
    Api.update_note method
    returns: empty body
    204 -- note deleted
    403 -- wrong authorization
    404 -- note not found
    500 -- internal error
    """

    conn = conn_get()
    note = database.get_note(conn, uuid)
    if note is None:
        abort(404)

    if AUTH.username() != note["user"]:
        abort(403)

    database.delete_note(conn, note["uuid"])
    conn.commit()

    return "", 204
def test_cascades_work(session, user, note):
    """ make sure all things related to a note are deleted when a note is deleted """
    user2 = create_user(session, "dafdsfas", "dfadsfdsaf")
    add_permission(session, PermissionType.READ, user2, note, triggered_by=user)
    add_comment(session, "fdsa", note, user)
    create_rating(session, user, note, 5)
    delete_note(session, note.id, user)
    permissioncheck = (
        session.query(NotePermission)
        .filter_by(user_id=user2.id, note_id=note.id)
        .first()
    )
    ratingcheck = (
        session.query(Rating).filter_by(owner_id=user.id, note_id=note.id).first()
    )
    commentcheck = (
        session.query(Comment).filter_by(owner_id=user.id, note_id=note.id).first()
    )

    assert permissioncheck is None
    assert ratingcheck is None
    assert commentcheck is None
Exemple #6
0
def note_delete(note_id):
    """ Delete notes """
    delete_note(g.session, note_id, current_user)

    return redirect(url_for("list_notes"))