Example #1
0
def update_item(item_id):
    """Handle request to update an item."""

    # validate ownership
    item = item_dao.get_item(item_id)
    if "user_id" not in login_session:
        return redirect(url_for("showLogin"))

    elif item.user_id != login_session["user_id"]:
        flash("Unauthorized operation")
        return redirect(url_for("view_items_html"))

    # update item
    item = Item()

    item.id = item_id
    item.name = request.form["name"]
    item.category_id = request.form["category_id"]

    if request.form["description"] != "":
        item.description = request.form["description"]

    item = item_dao.edit_item(item)

    return jsonify(item.serialize)
Example #2
0
def test_delete_item(item_dao):

    item = Item()
    item.id = 1

    item_dao.delete_item(item)

    assert item_dao.get_item(1) is None
Example #3
0
def test_edit_item(item_dao):

    item = Item()
    item.id = 1
    item.name = "SNES Classic"

    item_dao.edit_item(item)

    assert item_dao.get_item(1).name == "SNES Classic"
Example #4
0
def delete_item(item_id):
    """Handle request to delete an item."""

    # validate ownership
    item = item_dao.get_item(item_id)
    if "user_id" not in login_session:
        return redirect(url_for("showLogin"))

    elif item.user_id != login_session["user_id"]:
        flash("Unauthorized operation")
        return redirect(url_for("view_items_html"))

    # delete item
    item = Item()
    item.id = item_id

    item = item_dao.delete_item(item)

    return jsonify(item.serialize)