def delete_shopcarts(shopcart_id): """ Delete a shopcart This endpoint will delete an shopcart based the id specified in the path """ app.logger.info("Request to delete shopcart with id: %s", shopcart_id) shopcart = ShopCart.find(shopcart_id) if shopcart: shopcart.delete() return make_response("", status.HTTP_204_NO_CONTENT)
def delete_all_shopcarts(): """ Returns IDs of the ShopCarts """ app.logger.info("Request for ShopCart list") shopcarts = [] id = request.args.get("id") if id: shopcarts = ShopCart.find(id) else: shopcarts = ShopCart.all() results = [shopcart.delete() for shopcart in shopcarts] return make_response("", status.HTTP_204_NO_CONTENT)
def list_shopcarts(): """ Returns IDs of the ShopCarts """ app.logger.info("Request for ShopCart list") shopcarts = [] id = request.args.get("id") if id: shopcarts = ShopCart.find(id) else: shopcarts = ShopCart.all() results = [shopcart.serialize() for shopcart in shopcarts] return make_response(jsonify(results), status.HTTP_200_OK)
def test_delete_shopcart_item(self): """ Delete a ShopCart item """ shopcarts = ShopCart.all() self.assertEqual(shopcarts, []) item = self._create_item() shopcart = self._create_shopcart(items=[item]) shopcart.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(shopcart.id, 1) shopcarts = ShopCart.all() self.assertEqual(len(shopcarts), 1) # Fetch it back shopcart = ShopCart.find(shopcart.id) item = shopcart.items[0] item.delete() shopcart.save() # Fetch it back again shopcart = ShopCart.find(shopcart.id) self.assertEqual(len(shopcart.items), 0)
def update_shopcarts(shopcart_id): """ Update an existing shopcart This endpoint will update an shopcart based the body that is posted """ app.logger.info("Request to update shopcart with id: %s", shopcart_id) check_content_type("application/json") shopcart = ShopCart.find(shopcart_id) if not shopcart: raise NotFound("ShopCart with id '{}' was not found.".format(shopcart_id)) shopcart.deserialize(request.get_json()) shopcart.id = shopcart_id shopcart.save() return make_response(jsonify(shopcart.serialize()), status.HTTP_200_OK)